Fix: Persist plan notification state across page refreshes (#150)
This commit is contained in:
@@ -25,6 +25,7 @@ import { SessionTabs, type SessionTab } from '@/components/session-tabs';
|
||||
import { approveSessionAction } from '@/app/actions/workspaces';
|
||||
import { getWebSocketClient } from '@/lib/ws/connection';
|
||||
import { requestFileContent, updateFileContent } from '@/lib/ws/workspace-files';
|
||||
import { getPlanLastSeen, setPlanLastSeen } from '@/lib/local-storage';
|
||||
import { generateUnifiedDiff, calculateHash } from '@/lib/utils/file-diff';
|
||||
import { useToast } from '@/components/toast-provider';
|
||||
|
||||
@@ -123,26 +124,20 @@ export const TaskCenterPanel = memo(function TaskCenterPanel({
|
||||
const plan = useAppStore((state) =>
|
||||
activeTaskId ? state.taskPlans.byTaskId[activeTaskId] : null
|
||||
);
|
||||
// Track the last plan update timestamp the user has seen (when they viewed the Plan tab)
|
||||
// Key is taskId to handle task switching
|
||||
const [lastSeenPlanUpdateByTask, setLastSeenPlanUpdateByTask] = useState<Record<string, string | null>>({});
|
||||
|
||||
// Derive notification state: show dot if plan was updated by agent and we haven't seen it
|
||||
const hasUnseenPlanUpdate = useMemo(() => {
|
||||
if (!activeTaskId || !plan || leftTab === 'plan') return false;
|
||||
if (plan.created_by !== 'agent') return false;
|
||||
const lastSeen = lastSeenPlanUpdateByTask[activeTaskId];
|
||||
const lastSeen = getPlanLastSeen(activeTaskId);
|
||||
return plan.updated_at !== lastSeen;
|
||||
}, [activeTaskId, plan, leftTab, lastSeenPlanUpdateByTask]);
|
||||
}, [activeTaskId, plan, leftTab]);
|
||||
|
||||
// Handle tab change - mark plan as seen when switching to plan tab
|
||||
const handleTabChange = useCallback((tab: string) => {
|
||||
// If switching to plan tab, mark current plan as seen
|
||||
// If switching to plan tab, mark current plan as seen in localStorage
|
||||
if (tab === 'plan' && activeTaskId && plan?.updated_at) {
|
||||
setLastSeenPlanUpdateByTask(prev => ({
|
||||
...prev,
|
||||
[activeTaskId]: plan.updated_at
|
||||
}));
|
||||
setPlanLastSeen(activeTaskId, plan.updated_at);
|
||||
}
|
||||
setLeftTab(tab);
|
||||
}, [activeTaskId, plan]);
|
||||
|
||||
@@ -75,3 +75,45 @@ export function setKanbanPreviewState(state: Partial<KanbanPreviewState>): void
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Internal storage key for plan notifications (not exported - encapsulated)
|
||||
const PLAN_NOTIFICATION_KEY = 'kandev.plan.lastSeenByTask';
|
||||
|
||||
/**
|
||||
* Plan notification state - tracks when user last viewed each task's plan
|
||||
* Key is taskId, value is the plan's updated_at timestamp when last viewed
|
||||
*/
|
||||
export type PlanNotificationState = Record<string, string | null>;
|
||||
|
||||
/**
|
||||
* Get the plan notification state from localStorage
|
||||
* @returns Record of taskId -> last seen plan update timestamp
|
||||
*/
|
||||
export function getPlanNotificationState(): PlanNotificationState {
|
||||
return getLocalStorage(PLAN_NOTIFICATION_KEY, {} as PlanNotificationState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the last seen timestamp for a specific task's plan
|
||||
* @param taskId - The task ID
|
||||
* @param timestamp - The plan's updated_at timestamp when viewed (or null to clear)
|
||||
*/
|
||||
export function setPlanLastSeen(taskId: string, timestamp: string | null): void {
|
||||
const state = getPlanNotificationState();
|
||||
if (timestamp === null) {
|
||||
delete state[taskId];
|
||||
} else {
|
||||
state[taskId] = timestamp;
|
||||
}
|
||||
setLocalStorage(PLAN_NOTIFICATION_KEY, state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last seen timestamp for a specific task's plan
|
||||
* @param taskId - The task ID
|
||||
* @returns The last seen timestamp, or null if never viewed
|
||||
*/
|
||||
export function getPlanLastSeen(taskId: string): string | null {
|
||||
const state = getPlanNotificationState();
|
||||
return state[taskId] ?? null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user