From 7d6fc664d1fa8aa803d5c855e55ea8929db0621b Mon Sep 17 00:00:00 2001 From: a7m-1st Date: Thu, 13 Nov 2025 03:22:46 +0300 Subject: [PATCH] fix: support multi task replay + delete backwards compat --- src/components/HistorySidebar/index.tsx | 19 +++++++++---------- src/lib/replay.ts | 12 +++++------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/components/HistorySidebar/index.tsx b/src/components/HistorySidebar/index.tsx index 6da613f03..2ec126ae9 100644 --- a/src/components/HistorySidebar/index.tsx +++ b/src/components/HistorySidebar/index.tsx @@ -39,7 +39,7 @@ import { replayProject } from "@/lib"; import { useTranslation } from "react-i18next"; import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; import {getAuthStore} from "@/store/authStore"; -import { fetchGroupedHistorySummaries } from "@/service/historyApi"; +import { fetchGroupedHistoryTasks } from "@/service/historyApi"; import { HistoryTask, ProjectGroup } from "@/types/history"; export default function HistorySidebar() { @@ -75,12 +75,15 @@ export default function HistorySidebar() { }; useEffect(() => { - fetchGroupedHistorySummaries(setHistoryTasks); + fetchGroupedHistoryTasks(setHistoryTasks); }, [chatStore.updateCount]); const handleReplay = async (projectId: string, question: string, historyId: string) => { close(); - await replayProject(projectStore, navigate, projectId, question, historyId); + // Get task IDs from the API response data in descending order (newest first) + const project = historyTasks.find(p => p.project_id === projectId); + const taskIdsList = project?.tasks.map((task: HistoryTask) => task.task_id) || [projectId]; + await replayProject(projectStore, navigate, projectId, question, historyId, taskIdsList); }; const handleDelete = (id: string) => { @@ -118,15 +121,11 @@ export default function HistorySidebar() { } }; - // Deletes whole project by getting all tasks and deleting them one by one + // Deletes whole project by using the tasks from historyTasks state const deleteWholeProject = async (projectId: string) => { try { - // First, get all tasks for this project using the grouped API - const res = await proxyFetchGet(`/api/chat/histories/grouped?include_tasks=true`); - const projects = res.projects || []; - - // Find the project that matches the projectId (currentProjectId) - const targetProject = projects.find((project: ProjectGroup) => project.project_id === projectId); + // Find the project in our existing data + const targetProject = historyTasks.find(project => project.project_id === projectId); if (targetProject && targetProject.tasks) { console.log(`Found project ${projectId} with ${targetProject.tasks.length} tasks to delete`); diff --git a/src/lib/replay.ts b/src/lib/replay.ts index fcb4ed261..819ee9db9 100644 --- a/src/lib/replay.ts +++ b/src/lib/replay.ts @@ -1,5 +1,7 @@ +import { fetchGroupedHistoryTasks } from "@/service/historyApi"; import { ChatStore } from "@/store/chatStore"; import { ProjectStore } from "@/store/projectStore"; +import { ProjectGroup } from "@/types/history"; import { NavigateFunction } from "react-router-dom"; /** @@ -17,14 +19,10 @@ export const replayProject = async ( navigate: NavigateFunction, projectId: string, question: string, - historyId: string + historyId: string, + taskIdsList?: string[] ) => { - /** - * TODO(history): For now all replaying is appending to the same instance - * of task_id (to be renamed projectId). Later we need to filter task_id from - * /api/chat/histories by project_id then feed it here. - */ - const taskIdsList = [projectId]; + if(!taskIdsList) taskIdsList = [projectId]; projectStore.replayProject(taskIdsList, question, projectId, historyId); navigate({ pathname: "/" }); };