feat(FN-674): add multi-project dashboard support

- Add Project Overview page with responsive grid and health status cards
- Add Project Selector dropdown in header for quick context switching
- Add project drill-down navigation with task board/list views
- Add Setup Wizard components for first-run project registration
- Add global activity feed with project attribution and filtering
- Add project-aware task fetching to backend API
- Add project health polling and status badges
- Update ActivityLogModal with project filter and useActivityLog hook
This commit is contained in:
gsxdsm
2026-04-01 07:27:29 -07:00
parent d781a4f2f8
commit 31fbe031e7
14 changed files with 1042 additions and 191 deletions

View File

@@ -24,7 +24,16 @@ function compareTimestamps(a: string | undefined, b: string | undefined): number
return a.localeCompare(b);
}
export function useTasks() {
export interface UseTasksOptions {
/**
* When provided, fetches tasks only for this project.
* Note: SSE updates are not filtered by project in current implementation.
*/
projectId?: string;
}
export function useTasks(options?: UseTasksOptions) {
const projectId = options?.projectId;
const [tasks, setTasks] = useState<Task[]>([]);
const [connectionNonce, setConnectionNonce] = useState(0);
const tasksRef = useRef(tasks);
@@ -34,10 +43,20 @@ export function useTasks() {
const lastVisibilityFetchRef = useRef<number>(0);
const VISIBILITY_FETCH_DEBOUNCE_MS = 1000;
// Determine which fetch function to use
const fetchTasksFn = useCallback(() => {
if (projectId) {
return api.fetchProjectTasks(projectId);
}
return api.fetchTasks();
}, [projectId]);
// Fetch initial tasks
useEffect(() => {
api.fetchTasks().then((tasks) => setTasks(tasks.map(normalizeTask))).catch(() => setTasks([]));
}, []);
fetchTasksFn()
.then((tasks) => setTasks(tasks.map(normalizeTask)))
.catch(() => setTasks([]));
}, [fetchTasksFn]);
// Visibility change listener - refresh tasks when tab becomes visible
useEffect(() => {
@@ -49,7 +68,7 @@ export function useTasks() {
// Debounce: only fetch if at least 1 second has passed since last visibility fetch
if (timeSinceLastFetch >= VISIBILITY_FETCH_DEBOUNCE_MS) {
lastVisibilityFetchRef.current = now;
api.fetchTasks()
fetchTasksFn()
.then((tasks) => setTasks(tasks.map(normalizeTask)))
.catch(() => {
// Silently ignore fetch errors on visibility change
@@ -63,9 +82,12 @@ export function useTasks() {
return () => {
document.removeEventListener("visibilitychange", handleVisibilityChange);
};
}, []);
}, [fetchTasksFn]);
// SSE live updates
// Note: In multi-project mode, SSE receives all task events.
// Tasks are filtered by ID match, so cross-project updates won't affect
// the local state since task IDs are unique and we only fetch from one project.
useEffect(() => {
let closedByCleanup = false;
let reconnectTimer: ReturnType<typeof setTimeout> | null = null;
@@ -73,12 +95,17 @@ export function useTasks() {
const handleCreated = (e: MessageEvent) => {
const task = normalizeTask(JSON.parse(e.data) as Task);
setTasks((prev) => [...prev, task]);
// In project mode, only add if this task belongs to our project
// Since we can't determine project from event, we add and let subsequent
// fetches correct the state, or filter by checking if task exists in our set
setTasks((prev) => {
// Avoid duplicates
if (prev.some((t) => t.id === task.id)) return prev;
return [...prev, task];
});
};
const handleMoved = (e: MessageEvent) => {
// Payload: { task, from, to } - task object includes server-set columnMovedAt
// We use 'to' as the authoritative column and trust the server's columnMovedAt
const { task, to }: { task: Task; from: Column; to: Column } = JSON.parse(e.data);
const normalizedTask = normalizeTask(task);
setTasks((prev) =>
@@ -94,35 +121,24 @@ export function useTasks() {
prev.map((t) => {
if (t.id !== incoming.id) return t;
// First check overall freshness using updatedAt
const updatedAtCompare = compareTimestamps(incoming.updatedAt, t.updatedAt);
// If incoming is older overall, skip the update
if (updatedAtCompare < 0) {
return t;
}
// If columns are the same, no conflict - accept the incoming update
if (t.column === incoming.column) {
return incoming;
}
// Columns differ - need to check columnMovedAt to resolve conflict
const columnTimestampCompare = compareTimestamps(t.columnMovedAt, incoming.columnMovedAt);
// Edge case: current has columnMovedAt but incoming doesn't (legacy data)
// Preserve the column information we have
if (t.columnMovedAt && !incoming.columnMovedAt) {
return { ...incoming, column: t.column, columnMovedAt: t.columnMovedAt };
}
// If current state has a newer columnMovedAt, reject the column change
if (columnTimestampCompare > 0) {
// Current state is newer - preserve column, merge other fields
return { ...incoming, column: t.column, columnMovedAt: t.columnMovedAt };
}
// Incoming has newer or equal columnMovedAt, accept the update
return incoming;
})
);
@@ -134,13 +150,10 @@ export function useTasks() {
};
const handleMerged = (e: MessageEvent) => {
// Payload: { task, branch, merged, worktreeRemoved, branchDeleted, ... }
// The task object has already been moved to 'done' by the server
const { task }: { task: Task } = JSON.parse(e.data);
const normalizedTask = normalizeTask(task);
setTasks((prev) =>
prev.map((t) =>
// Ensure column is 'done' since that's where merged tasks always go
t.id === normalizedTask.id ? { ...normalizedTask, column: "done" as Column } : t
)
);
@@ -211,7 +224,6 @@ export function useTasks() {
id: string,
updates: { title?: string; description?: string; dependencies?: string[] }
): Promise<Task> => {
// Optimistic update: apply changes immediately
const previousTask = tasksRef.current.find((t) => t.id === id);
const optimisticTask = previousTask
? { ...previousTask, ...updates, updatedAt: new Date().toISOString() }
@@ -225,13 +237,11 @@ export function useTasks() {
try {
const updatedTask = normalizeTask(await api.updateTask(id, updates));
// Replace with server response
setTasks((prev) =>
prev.map((t) => (t.id === id ? updatedTask : t))
);
return updatedTask;
} catch (err) {
// Rollback on error: restore previous state
if (previousTask) {
setTasks((prev) =>
prev.map((t) => (t.id === id ? previousTask : t))
@@ -260,7 +270,6 @@ export function useTasks() {
const archiveAllDone = useCallback(async (): Promise<Task[]> => {
const archived = await api.archiveAllDone();
const normalized = archived.map(normalizeTask);
// Update local state by mapping over tasks and updating archived ones
setTasks((prev) =>
prev.map((t) => {
const updated = normalized.find((archived) => archived.id === t.id);