Files
kandev/apps/web/lib/ws/handlers/task-plans.ts
T
2026-01-31 00:51:17 +00:00

32 lines
1018 B
TypeScript

import type { StoreApi } from 'zustand';
import type { AppState } from '@/lib/state/store';
import type { BackendMessageMap } from '@/lib/types/backend';
import type { WsHandlers } from '@/lib/ws/handlers/types';
type PlanMessage = BackendMessageMap['task.plan.created'] | BackendMessageMap['task.plan.updated'];
function handlePlanUpsert(store: StoreApi<AppState>, message: PlanMessage) {
const { task_id, id, title, content, created_by, created_at, updated_at } = message.payload;
store.getState().setTaskPlan(task_id, {
id,
task_id,
title,
content,
created_by,
created_at,
updated_at,
});
}
export function registerTaskPlansHandlers(store: StoreApi<AppState>): WsHandlers {
return {
'task.plan.created': (message) => handlePlanUpsert(store, message),
'task.plan.updated': (message) => handlePlanUpsert(store, message),
'task.plan.deleted': (message) => {
const { task_id } = message.payload;
store.getState().setTaskPlan(task_id, null);
},
};
}