Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/components/GroupedHistoryView/ProjectDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '@/components/ui/dialog';
import { Input } from '@/components/ui/input';
import { useProjectStore } from '@/store/projectStore';
import { ProjectGroup } from '@/types/history';
import { HistoryTask, ProjectGroup } from '@/types/history';
import {
CheckCircle,
Clock,
Expand All @@ -46,7 +46,7 @@ interface ProjectDialogProps {
historyId: string,
project?: ProjectGroup
) => void;
onTaskDelete: (taskId: string) => void;
onTaskDelete: (historyId: string, task?: HistoryTask) => void;
onTaskShare: (taskId: string) => void;
activeTaskId?: string;
}
Expand Down Expand Up @@ -256,8 +256,12 @@ export default function ProjectDialog({
project
)
}
onDelete={() => onTaskDelete(task.id.toString())}
onShare={() => onTaskShare(task.id.toString())}
onDelete={() =>
onTaskDelete(task.id.toString(), task)
}
onShare={() =>
onTaskShare(task.task_id || task.id.toString())
}
isLast={index === project.tasks.length - 1}
showActions={false}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/components/GroupedHistoryView/ProjectGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import useChatStoreAdapter from '@/hooks/useChatStoreAdapter';
import { loadProjectFromHistory } from '@/lib/replay';
import { useProjectStore } from '@/store/projectStore';
import { ChatTaskStatus } from '@/types/constants';
import { ProjectGroup as ProjectGroupType } from '@/types/history';
import { HistoryTask, ProjectGroup as ProjectGroupType } from '@/types/history';
import { motion } from 'framer-motion';
import {
Edit,
Expand All @@ -51,7 +51,7 @@ interface ProjectGroupProps {
historyId: string,
project?: ProjectGroupType
) => void;
onTaskDelete: (taskId: string) => void;
onTaskDelete: (historyId: string, task?: HistoryTask) => void;
onTaskShare: (taskId: string) => void;
activeTaskId?: string;
searchValue?: string;
Expand Down
15 changes: 11 additions & 4 deletions src/components/GroupedHistoryView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { fetchGroupedHistoryTasks } from '@/service/historyApi';
import { getAuthStore } from '@/store/authStore';
import { useGlobalStore } from '@/store/globalStore';
import { useProjectStore } from '@/store/projectStore';
import { ProjectGroup as ProjectGroupType } from '@/types/history';
import { HistoryTask, ProjectGroup as ProjectGroupType } from '@/types/history';
import { AnimatePresence, motion } from 'framer-motion';
import { FolderOpen, LayoutGrid, List, Pin, Sparkle } from 'lucide-react';
import { useEffect, useState } from 'react';
Expand All @@ -34,7 +34,11 @@ interface GroupedHistoryViewProps {
historyId: string,
project?: ProjectGroupType
) => void;
onTaskDelete: (historyId: string, callback: () => void) => void;
onTaskDelete: (
historyId: string,
task: HistoryTask | undefined,
callback: () => void
) => void;
onTaskShare: (taskId: string) => void;
activeTaskId?: string;
refreshTrigger?: number; // For triggering refresh from parent
Expand Down Expand Up @@ -82,9 +86,12 @@ export default function GroupedHistoryView({
}
};

const onDelete = (historyId: string) => {
const onDelete = (historyId: string, task?: HistoryTask) => {
try {
onTaskDelete(historyId, () => {
const targetTask = task ?? projects.flatMap((p) => p.tasks).find(
(t) => String(t.id) === historyId
);
onTaskDelete(historyId, targetTask, () => {
setProjects((prevProjects) => {
// Create new project objects instead of mutating existing ones
return prevProjects
Expand Down
179 changes: 158 additions & 21 deletions src/components/SearchHistoryDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

'use client';

import { ScanFace, Search } from 'lucide-react';
import { useEffect, useState } from 'react';

import { proxyFetchDelete } from '@/api/http';
import GroupedHistoryView from '@/components/GroupedHistoryView';
import {
CommandDialog,
Expand All @@ -29,18 +27,57 @@ import {
} from '@/components/ui/command';
import useChatStoreAdapter from '@/hooks/useChatStoreAdapter';
import { loadProjectFromHistory } from '@/lib';
import { share } from '@/lib/share';
import { fetchHistoryTasks } from '@/service/historyApi';
import { getAuthStore } from '@/store/authStore';
import { useGlobalStore } from '@/store/globalStore';
import { HistoryTask } from '@/types/history';
import { VisuallyHidden } from '@radix-ui/react-visually-hidden';
import { Ellipsis, ScanFace, Search, Share2, Trash2 } from 'lucide-react';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { toast } from 'sonner';
import AlertDialog from '@/components/ui/alertDialog';
import { Button } from './ui/button';
import { DialogTitle } from './ui/dialog';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from './ui/dropdown-menu';

type IpcRendererLike = {
invoke: (
channel: string,
email: string,
taskId: string,
projectId?: string
) => Promise<void>;
};

function getIpcRenderer(): IpcRendererLike | undefined {
const w = window as unknown as { ipcRenderer?: IpcRendererLike };
return w.ipcRenderer;
}

type HistoryListItem = HistoryTask & {
tasks?: { task_id: string }[];
project_name?: string;
project_id?: string;
};

export function SearchHistoryDialog() {
const { t } = useTranslation();
const [open, setOpen] = useState(false);
const [historyTasks, setHistoryTasks] = useState<any[]>([]);
const [historyTasks, setHistoryTasks] = useState<HistoryListItem[]>([]);
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
const [pendingDelete, setPendingDelete] = useState<{
historyId: string;
task: HistoryTask | undefined;
callback: () => void;
} | null>(null);
const { history_type } = useGlobalStore();
//Get Chatstore for the active project's task
const { chatStore, projectStore } = useChatStoreAdapter();
Expand Down Expand Up @@ -75,14 +112,60 @@ export function SearchHistoryDialog() {
}
};

const handleDelete = (taskId: string) => {
// TODO: Implement delete functionality similar to HistorySidebar
console.log('Delete task:', taskId);
const handleDelete = async (
historyId: string,
task: HistoryTask | undefined,
callback: () => void
) => {
try {
await proxyFetchDelete(`/api/chat/history/${historyId}`);

const ipcRenderer = getIpcRenderer();
if (task?.task_id && ipcRenderer) {
const { email } = getAuthStore();
const safeEmail = email ?? '';
try {
await ipcRenderer.invoke(
'delete-task-files',
safeEmail,
task.task_id,
task.project_id
);
} catch (error) {
console.warn('Local file cleanup failed:', error);
}
}

callback();
toast.success(t('layout.delete-success') || 'Task deleted successfully');
} catch (error) {
console.error('Failed to delete history task:', error);
toast.error(t('layout.delete-failed') || 'Failed to delete task');
}
};

const handleShare = async (taskId: string) => {
setOpen(false);
await share(taskId);
};

const openDeleteConfirm = (
historyId: string,
task: HistoryTask | undefined,
callback: () => void
) => {
setPendingDelete({ historyId, task, callback });
setDeleteDialogOpen(true);
};

const handleShare = (taskId: string) => {
// TODO: Implement share functionality similar to HistorySidebar
console.log('Share task:', taskId);
const confirmDelete = () => {
if (!pendingDelete) return;
void handleDelete(
pendingDelete.historyId,
pendingDelete.task,
pendingDelete.callback
);
setPendingDelete(null);
};

useEffect(() => {
Expand Down Expand Up @@ -122,33 +205,87 @@ export function SearchHistoryDialog() {
</div>
) : (
<CommandGroup heading="Today">
{historyTasks.map((task) => (
{historyTasks.map((task: HistoryListItem) => (
<CommandItem
key={task.id}
className="cursor-pointer"
/**
* TODO(history): Update to use project_id field
* after update instead.
*/
className="flex cursor-pointer items-center justify-between gap-2"
onSelect={() =>
handleSetActive(
task.task_id,
task.project_id || task.task_id,
task.question,
String(task.id)
String(task.id),
{
tasks: task.tasks || [{ task_id: task.task_id }],
project_name: task.project_name,
}
)
}
>
<ScanFace />
<div className="overflow-hidden text-ellipsis whitespace-nowrap">
{task.question}
<div className="flex min-w-0 flex-1 items-center gap-2">
<ScanFace className="h-4 w-4 flex-shrink-0" />
<span className="overflow-hidden text-ellipsis whitespace-nowrap">
{task.question}
</span>
</div>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="icon"
className="h-7 w-7 flex-shrink-0"
onClick={(e: any) => e.stopPropagation()}
>
<Ellipsis className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem
onClick={(e: any) => {
e.stopPropagation();
handleShare(task.task_id || String(task.id));
}}
>
<Share2 className="mr-2 h-4 w-4" />
{t('layout.share')}
</DropdownMenuItem>
<DropdownMenuItem
className="text-text-cuation"
onClick={async (e: any) => {
e.stopPropagation();
openDeleteConfirm(String(task.id), task, () => {
setHistoryTasks((prev: HistoryListItem[]) =>
prev.filter(
(t: HistoryListItem) => t.id !== task.id
)
);
});
}}
>
<Trash2 className="mr-2 h-4 w-4" />
{t('layout.delete')}
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</CommandItem>
))}
</CommandGroup>
)}
<CommandSeparator />
</CommandList>
</CommandDialog>
<AlertDialog
isOpen={deleteDialogOpen}
onClose={() => {
setDeleteDialogOpen(false);
setPendingDelete(null);
}}
onConfirm={confirmDelete}
title={t('layout.delete-task')}
message={t('layout.delete-task-confirmation')}
confirmText={t('layout.delete')}
cancelText={t('layout.cancel')}
confirmVariant="cuation"
/>
</>
);
}
2 changes: 2 additions & 0 deletions src/i18n/locales/ar/layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"welcome": "أهلاً وسهلاً",
"delete-task": "حذف المهمة",
"delete-task-confirmation": "هل أنت متأكد من أنك تريد حذف هذه المهمة؟ لا يمكن التراجع عن هذا الإجراء.",
"delete-success": "تم حذف المهمة بنجاح",
"delete-failed": "فشل حذف المهمة",
"delete": "حذف",
"cancel": "إلغاء",
"continue": "متابعة",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/de/layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"welcome": "Willkommen",
"delete-task": "Aufgabe löschen",
"delete-task-confirmation": "Sind Sie sicher, dass Sie diese Aufgabe löschen möchten? Diese Aktion kann nicht rückgängig gemacht werden.",
"delete-success": "Aufgabe erfolgreich gelöscht",
"delete-failed": "Aufgabe konnte nicht gelöscht werden",
"delete": "Löschen",
"cancel": "Abbrechen",
"continue": "Fortfahren",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/en-us/layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
"welcome": "Welcome",
"delete-task": "Delete Task",
"delete-task-confirmation": "Are you sure you want to delete this task? This action cannot be undone.",
"delete-success": "Task deleted successfully",
"delete-failed": "Failed to delete task",
"delete": "Delete",
"cancel": "Cancel",
"continue": "Continue",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/es/layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"welcome": "Bienvenido",
"delete-task": "Eliminar Tarea",
"delete-task-confirmation": "¿Estás seguro de que quieres eliminar esta tarea? Esta acción no se puede deshacer.",
"delete-success": "Tarea eliminada correctamente",
"delete-failed": "No se pudo eliminar la tarea",
"delete": "Eliminar",
"cancel": "Cancelar",
"continue": "Continuar",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/fr/layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"welcome": "Bienvenue",
"delete-task": "Supprimer la Tâche",
"delete-task-confirmation": "Êtes-vous sûr de vouloir supprimer cette tâche ? Cette action ne peut pas être annulée.",
"delete-success": "Tâche supprimée avec succès",
"delete-failed": "Échec de la suppression de la tâche",
"delete": "Supprimer",
"cancel": "Annuler",
"continue": "Continuer",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/it/layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"welcome": "Benvenuto",
"delete-task": "Elimina Attività",
"delete-task-confirmation": "Sei sicuro di voler eliminare questa attività? Questa azione non può essere annullata.",
"delete-success": "Attività eliminata con successo",
"delete-failed": "Impossibile eliminare l'attività",
"delete": "Elimina",
"cancel": "Annulla",
"continue": "Continua",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/ja/layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"welcome": "ようこそ",
"delete-task": "タスクを削除",
"delete-task-confirmation": "このタスクを削除してもよろしいですか?この操作は元に戻せません。",
"delete-success": "タスクを削除しました",
"delete-failed": "タスクの削除に失敗しました",
"delete": "削除",
"cancel": "キャンセル",
"continue": "続行",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/ko/layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"welcome": "환영",
"delete-task": "작업 삭제",
"delete-task-confirmation": "이 작업을 삭제하시겠습니까? 이 작업은 되돌릴 수 없습니다.",
"delete-success": "작업이 삭제되었습니다",
"delete-failed": "작업 삭제에 실패했습니다",
"delete": "삭제",
"cancel": "취소",
"continue": "계속",
Expand Down
Loading
Loading