enhance: migrate api to projid PR645 (#650)

This commit is contained in:
Wendong-Fan 2025-11-14 00:01:14 +08:00 committed by GitHub
commit ea8a2eea69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 13 deletions

View file

@ -5,7 +5,6 @@ import { fetchGroupedHistoryTasks } from "@/service/historyApi";
import ProjectGroup from "./ProjectGroup";
import { useTranslation } from "react-i18next";
import { Loader2, FolderOpen } from "lucide-react";
import { update } from "electron/main/update";
interface GroupedHistoryViewProps {
searchValue?: string;
@ -43,9 +42,15 @@ export default function GroupedHistoryView({
try {
onTaskDelete(historyId, () => {
setProjects(prevProjects => {
// Create new project objects instead of mutating existing ones
return prevProjects.map(project => {
project.tasks = project.tasks.filter(task => String(task.id) !== historyId);
return project;
const filteredTasks = project.tasks.filter(task => String(task.id) !== historyId);
return {
...project,
tasks: filteredTasks,
task_count: filteredTasks.length,
total_tokens: filteredTasks.reduce((sum, task) => sum + (task.tokens || 0), 0)
};
}).filter(project => project.tasks.length > 0);
});
});

View file

@ -77,12 +77,16 @@ export const fetchHistoryTasks = async (setTasks: React.Dispatch<React.SetStateA
export const fetchGroupedHistoryTasks = async (setProjects: React.Dispatch<React.SetStateAction<ProjectGroup[]>>) => {
try {
const res = await proxyFetchGet(`/api/chat/histories/grouped?include_tasks=true`);
if(res.status !== 200) {
fetchGroupedHistoryTasksLegacy(setProjects);
} else setProjects(res.projects);
// If the response doesn't have projects field, fall back to legacy grouping
if(!res || !res.projects) {
await fetchGroupedHistoryTasksLegacy(setProjects);
} else {
setProjects(res.projects);
}
} catch (error) {
console.error("Failed to fetch grouped history summaries:", error);
setProjects([]);
console.error("Failed to fetch grouped history tasks, falling back to legacy:", error);
// Fall back to legacy grouping if the new endpoint fails
await fetchGroupedHistoryTasksLegacy(setProjects);
}
};
@ -90,12 +94,16 @@ export const fetchGroupedHistoryTasks = async (setProjects: React.Dispatch<React
export const fetchGroupedHistorySummaries = async (setProjects: React.Dispatch<React.SetStateAction<ProjectGroup[]>>) => {
try {
const res = await proxyFetchGet(`/api/chat/histories/grouped?include_tasks=false`);
if(res.status !== 200) {
fetchGroupedHistoryTasksLegacy(setProjects);
} else setProjects(res.projects);
// If the response doesn't have projects field, fall back to legacy grouping
if(!res || !res.projects) {
await fetchGroupedHistoryTasksLegacy(setProjects);
} else {
setProjects(res.projects);
}
} catch (error) {
console.error("Failed to fetch grouped history summaries:", error);
setProjects([]);
console.error("Failed to fetch grouped history summaries, falling back to legacy:", error);
// Fall back to legacy grouping if the new endpoint fails
await fetchGroupedHistoryTasksLegacy(setProjects);
}
};