diff --git a/src/components/ChatBox/index.tsx b/src/components/ChatBox/index.tsx index 4800b6662..8f2c03375 100644 --- a/src/components/ChatBox/index.tsx +++ b/src/components/ChatBox/index.tsx @@ -20,7 +20,7 @@ export default function ChatBox(): JSX.Element { const [message, setMessage] = useState(""); //Get Chatstore for the active project's task - const { chatStore } = useChatStoreAdapter(); + const { chatStore, projectStore } = useChatStoreAdapter(); if (!chatStore) { return
Loading...
; } @@ -110,7 +110,7 @@ export default function ChatBox(): JSX.Element { if (isTaskBusy && !task.activeAsk) { // Queue the message instead of sending immediately const currentAttaches = JSON.parse(JSON.stringify(task.attaches)) || []; - chatStore.addQueuedMessage(_taskId, tempMessageContent, currentAttaches); + projectStore.addQueuedMessage(projectStore.activeProjectId as string, tempMessageContent, currentAttaches); chatStore.setAttaches(_taskId, []); // Clear attaches after queuing setMessage(""); if (textareaRef.current) textareaRef.current.style.height = "60px"; @@ -400,9 +400,10 @@ export default function ChatBox(): JSX.Element { const getBottomBoxState = () => { if (!chatStore.activeTaskId) return "input"; const task = chatStore.tasks[chatStore.activeTaskId]; + const activeProject = projectStore.getProjectById(projectStore.activeProjectId || ''); - // Check for queued messages - if (task.queuedMessages && task.queuedMessages.length > 0) { + // Check for queued messages at project level + if (activeProject?.queuedMessages && activeProject.queuedMessages.length > 0) { return "queuing"; } @@ -720,12 +721,12 @@ export default function ChatBox(): JSX.Element { {chatStore.activeTaskId && ( ({ + queuedMessages={projectStore.getProjectById(projectStore.activeProjectId || '')?.queuedMessages?.map(m => ({ id: m.id, content: m.content, timestamp: m.timestamp })) || []} - onRemoveQueuedMessage={(id) => chatStore.removeQueuedMessage(chatStore.activeTaskId as string, id)} + onRemoveQueuedMessage={(id) => projectStore.removeQueuedMessage(projectStore.activeProjectId as string, id)} subTasks={chatStore.tasks[chatStore.activeTaskId]?.taskInfo?.map(t => ({ id: t.id || generateUniqueId(), content: t.content, diff --git a/src/store/chatStore.ts b/src/store/chatStore.ts index 74f6c8ac7..605992321 100644 --- a/src/store/chatStore.ts +++ b/src/store/chatStore.ts @@ -39,7 +39,6 @@ interface Task { snapshotsTemp: any[]; isTakeControl: boolean; isTaskEdit: boolean; - queuedMessages: Array<{ id: string; content: string; timestamp: number; attaches: File[] }>; } export interface ChatStore { @@ -95,9 +94,6 @@ export interface ChatStore { setSnapshotsTemp: (taskId: string, snapshot: any) => void, setIsTaskEdit: (taskId: string, isTaskEdit: boolean) => void, clearTasks: () => void, - addQueuedMessage: (taskId: string, content: string, attaches: File[]) => void; - removeQueuedMessage: (taskId: string, messageId: string) => void; - clearQueuedMessages: (taskId: string) => void; } @@ -146,7 +142,6 @@ const chatStore = (initial?: Partial) => createStore()( snapshotsTemp: [], isTakeControl: false, isTaskEdit: false, - queuedMessages: [] }, } })) @@ -1705,50 +1700,6 @@ const chatStore = (initial?: Partial) => createStore()( }, })) }, - addQueuedMessage(taskId: string, content: string, attaches: File[]) { - set((state) => ({ - ...state, - tasks: { - ...state.tasks, - [taskId]: { - ...state.tasks[taskId], - queuedMessages: [ - ...state.tasks[taskId].queuedMessages, - { - id: generateUniqueId(), - content, - timestamp: Date.now(), - attaches: [...attaches] - } - ] - }, - }, - })) - }, - removeQueuedMessage(taskId: string, messageId: string) { - set((state) => ({ - ...state, - tasks: { - ...state.tasks, - [taskId]: { - ...state.tasks[taskId], - queuedMessages: state.tasks[taskId].queuedMessages.filter(m => m.id !== messageId) - }, - }, - })) - }, - clearQueuedMessages(taskId: string) { - set((state) => ({ - ...state, - tasks: { - ...state.tasks, - [taskId]: { - ...state.tasks[taskId], - queuedMessages: [] - }, - }, - })) - }, }) ); diff --git a/src/store/projectStore.ts b/src/store/projectStore.ts index 8b75ad13e..448163b1f 100644 --- a/src/store/projectStore.ts +++ b/src/store/projectStore.ts @@ -16,6 +16,7 @@ interface Project { updatedAt: number; chatStores: { [chatId: string]: VanillaChatStore }; // Multiple chat stores for this project activeChatId: string | null; // ID of the currently active chat store + queuedMessages: Array<{ id: string; content: string; timestamp: number; attaches: File[] }>; // Project-level queued messages metadata?: { tags?: string[]; priority?: 'low' | 'medium' | 'high'; @@ -34,6 +35,11 @@ interface ProjectStore { updateProject: (projectId: string, updates: Partial>) => void; replayProject: (taskIds: string[], question?: string, projectId?: string) => string; + // Project-level queued messages management + addQueuedMessage: (projectId: string, content: string, attaches: File[]) => void; + removeQueuedMessage: (projectId: string, messageId: string) => void; + clearQueuedMessages: (projectId: string) => void; + // Chat store state management createChatStore: (projectId: string, chatName?: string) => string | null; setActiveChatStore: (projectId: string, chatId: string) => void; @@ -76,6 +82,11 @@ const isEmptyProject = (project: Project): boolean => { return false; } + // Check if project has any queued messages + if (project.queuedMessages && project.queuedMessages.length > 0) { + return false; + } + // Check if task is in initial/empty state const isEmpty = ( Array.isArray(task.messages) && task.messages.length === 0 && @@ -153,6 +164,7 @@ const projectStore = create()((set, get) => ({ [initialChatId]: initialChatStore }, activeChatId: initialChatId, + queuedMessages: [], // Initialize empty queued messages array metadata: { status: 'active' } @@ -498,6 +510,75 @@ const projectStore = create()((set, get) => ({ return null; }, + // Project-level queued messages management + addQueuedMessage: (projectId: string, content: string, attaches: File[]) => { + const { projects } = get(); + + if (!projects[projectId]) { + console.warn(`Project ${projectId} not found`); + return; + } + + set((state) => ({ + projects: { + ...state.projects, + [projectId]: { + ...state.projects[projectId], + queuedMessages: [ + ...state.projects[projectId].queuedMessages, + { + id: generateUniqueId(), + content, + timestamp: Date.now(), + attaches: [...attaches] + } + ], + updatedAt: Date.now() + } + } + })); + }, + + removeQueuedMessage: (projectId: string, messageId: string) => { + const { projects } = get(); + + if (!projects[projectId]) { + console.warn(`Project ${projectId} not found`); + return; + } + + set((state) => ({ + projects: { + ...state.projects, + [projectId]: { + ...state.projects[projectId], + queuedMessages: state.projects[projectId].queuedMessages.filter(m => m.id !== messageId), + updatedAt: Date.now() + } + } + })); + }, + + clearQueuedMessages: (projectId: string) => { + const { projects } = get(); + + if (!projects[projectId]) { + console.warn(`Project ${projectId} not found`); + return; + } + + set((state) => ({ + projects: { + ...state.projects, + [projectId]: { + ...state.projects[projectId], + queuedMessages: [], + updatedAt: Date.now() + } + } + })); + }, + getAllChatStores: (projectId: string) => { const { projects } = get(); @@ -515,7 +596,14 @@ const projectStore = create()((set, get) => ({ getProjectById: (projectId: string) => { const { projects } = get(); - return projects[projectId] || null; + const project = projects[projectId] || null; + + // Ensure backwards compatibility - add queuedMessages if it doesn't exist + if (project && !project.queuedMessages) { + project.queuedMessages = []; + } + + return project; } }));