Commits merged: - fix(FN-2991): align failed research status badge semantics - feat(FN-2991): add research dashboard view and navigation entry - fix(FN-2991): complete Step 8 — resolve lint and typecheck gates - test(FN-2991): address review feedback for Step 7 - test(FN-2991): complete Step 7 — add research store and route tests - feat(FN-2991): complete Step 6 — add research client API helpers - feat(FN-2991): complete Step 5 — add research REST routes - feat(FN-2991): complete Step 4 — wire research store into core exports - feat(FN-2991): complete Step 3 — implement research store - feat(FN-2991): complete Step 2 — add research schema and migration - feat(FN-2991): complete Step 1 — add research domain types Files changed: packages/core/src/__tests__/db.test.ts | 26 +- packages/core/src/__tests__/insight-store.test.ts | 8 +- packages/core/src/__tests__/mission-store.test.ts | 2 +- packages/core/src/__tests__/research-store.test.ts | 118 +++++++ packages/core/src/__tests__/roadmap-store.test.ts | 2 +- packages/core/src/__tests__/run-audit.test.ts | 2 +- packages/core/src/__tests__/task-documents.test.ts | 2 +- packages/core/src/db.ts | 82 ++++- packages/core/src/index.ts | 30 ++ packages/core/src/research-store.ts | 377 +++++++++++++++++++++ packages/core/src/research-types.ts | 162 +++++++++ packages/core/src/store.ts | 14 + packages/dashboard/app/App.tsx | 12 + .../app/api/__tests__/research-api.test.ts | 120 +++++++ packages/dashboard/app/api/legacy.ts | 132 +++++++- packages/dashboard/app/components/Header.tsx | 23 +- packages/dashboard/app/components/MobileNavBar.tsx | 16 +- packages/dashboard/app/components/ResearchView.css | 110 ++++++ packages/dashboard/app/components/ResearchView.tsx | 145 ++++++++ .../app/components/__tests__/Header.test.tsx | 4 +- .../app/components/__tests__/ResearchView.test.tsx | 170 ++++++++++ packages/dashboard/app/hooks/useViewState.ts | 3 +- packages/dashboard/src/research-routes.ts | 223 ++++++++++++ .../src/routes/register-integrated-routers.ts | 2 + 24 files changed, 1751 insertions(+), 34 deletions(-) Fusion-Task-Id: FN-2991
157 lines
4.3 KiB
TypeScript
157 lines
4.3 KiB
TypeScript
import { useCallback, useEffect, useRef, useState } from "react";
|
|
import type { ThemeMode } from "@fusion/core";
|
|
import type { ProjectInfo } from "../api";
|
|
import { getScopedItem, setScopedItem } from "../utils/projectStorage";
|
|
|
|
export type ViewMode = "overview" | "project";
|
|
export type TaskView = "board" | "list" | "agents" | "missions" | "chat" | "documents" | "research" | "roadmaps" | "skills" | "mailbox" | "insights" | "memory" | "devserver" | "dev-server" | "todos";
|
|
|
|
const TASK_VIEWS: readonly TaskView[] = [
|
|
"board",
|
|
"list",
|
|
"agents",
|
|
"missions",
|
|
"chat",
|
|
"documents",
|
|
"research",
|
|
"roadmaps",
|
|
"skills",
|
|
"mailbox",
|
|
"insights",
|
|
"memory",
|
|
"devserver",
|
|
"dev-server",
|
|
"todos",
|
|
];
|
|
|
|
function isTaskView(value: string | null): value is TaskView {
|
|
return value !== null && TASK_VIEWS.includes(value as TaskView);
|
|
}
|
|
|
|
function normalizeTaskView(value: TaskView): TaskView {
|
|
return value === "devserver" ? "dev-server" : value;
|
|
}
|
|
|
|
interface UseViewStateOptions {
|
|
projectsLoading: boolean;
|
|
projectsError: string | null;
|
|
currentProjectLoading: boolean;
|
|
currentProject: ProjectInfo | null;
|
|
projectsLength: number;
|
|
setupWizardOpen: boolean;
|
|
openSetupWizard: () => void;
|
|
themeMode: ThemeMode;
|
|
setThemeMode: (mode: ThemeMode) => void;
|
|
}
|
|
|
|
export interface UseViewStateResult {
|
|
viewMode: ViewMode;
|
|
setViewMode: (mode: ViewMode) => void;
|
|
taskView: TaskView;
|
|
setTaskView: (view: TaskView) => void;
|
|
handleChangeTaskView: (newView: TaskView) => void;
|
|
handleToggleTheme: () => void;
|
|
}
|
|
|
|
export function useViewState(options: UseViewStateOptions): UseViewStateResult {
|
|
const {
|
|
projectsLoading,
|
|
projectsError,
|
|
currentProjectLoading,
|
|
currentProject,
|
|
projectsLength,
|
|
setupWizardOpen,
|
|
openSetupWizard,
|
|
themeMode,
|
|
setThemeMode,
|
|
} = options;
|
|
|
|
const [viewMode, setViewMode] = useState<ViewMode>(() => {
|
|
if (typeof window !== "undefined") {
|
|
const saved = window.localStorage.getItem("kb-dashboard-view-mode");
|
|
if (saved === "overview" || saved === "project") return saved;
|
|
}
|
|
return "overview";
|
|
});
|
|
|
|
const [taskView, setTaskView] = useState<TaskView>(() => {
|
|
const saved = getScopedItem("kb-dashboard-task-view");
|
|
if (isTaskView(saved)) return saved;
|
|
return "board";
|
|
});
|
|
const hasHydratedScopedTaskViewRef = useRef(false);
|
|
|
|
useEffect(() => {
|
|
window.localStorage.setItem("kb-dashboard-view-mode", viewMode);
|
|
}, [viewMode]);
|
|
|
|
useEffect(() => {
|
|
const saved = getScopedItem("kb-dashboard-task-view", currentProject?.id);
|
|
if (isTaskView(saved)) {
|
|
const preserveLegacyOnFirstScopedHydration =
|
|
!hasHydratedScopedTaskViewRef.current && saved === "devserver";
|
|
|
|
setTaskView(preserveLegacyOnFirstScopedHydration ? "devserver" : normalizeTaskView(saved));
|
|
} else {
|
|
setTaskView("board");
|
|
}
|
|
|
|
if (currentProject?.id) {
|
|
hasHydratedScopedTaskViewRef.current = true;
|
|
}
|
|
}, [currentProject?.id]);
|
|
|
|
useEffect(() => {
|
|
setScopedItem("kb-dashboard-task-view", taskView, currentProject?.id);
|
|
}, [currentProject?.id, taskView]);
|
|
|
|
useEffect(() => {
|
|
if (projectsLoading || currentProjectLoading) return;
|
|
|
|
if (currentProject && viewMode === "overview") {
|
|
setViewMode("project");
|
|
}
|
|
}, [projectsLoading, currentProjectLoading, currentProject, viewMode]);
|
|
|
|
useEffect(() => {
|
|
if (projectsLoading || currentProjectLoading) return;
|
|
if (setupWizardOpen) return;
|
|
if (projectsError) return;
|
|
if (projectsLength > 0 || currentProject) return;
|
|
|
|
const timer = window.setTimeout(() => {
|
|
openSetupWizard();
|
|
}, 500);
|
|
|
|
return () => window.clearTimeout(timer);
|
|
}, [
|
|
projectsLoading,
|
|
projectsError,
|
|
projectsLength,
|
|
currentProjectLoading,
|
|
currentProject,
|
|
setupWizardOpen,
|
|
openSetupWizard,
|
|
]);
|
|
|
|
const handleChangeTaskView = useCallback((newView: TaskView) => {
|
|
setTaskView(newView);
|
|
}, []);
|
|
|
|
const handleToggleTheme = useCallback(() => {
|
|
const cycle: ThemeMode[] = ["dark", "light", "system"];
|
|
const currentIndex = cycle.indexOf(themeMode);
|
|
const nextMode = cycle[(currentIndex + 1) % cycle.length];
|
|
setThemeMode(nextMode);
|
|
}, [themeMode, setThemeMode]);
|
|
|
|
return {
|
|
viewMode,
|
|
setViewMode,
|
|
taskView,
|
|
setTaskView,
|
|
handleChangeTaskView,
|
|
handleToggleTheme,
|
|
};
|
|
}
|