1414
1515'use client' ;
1616
17- import { ScanFace , Search } from 'lucide-react' ;
17+ import { ScanFace , Search , Trash2 } from 'lucide-react' ;
1818import { useEffect , useState } from 'react' ;
1919
20+ import { proxyFetchDelete } from '@/api/http' ;
2021import GroupedHistoryView from '@/components/GroupedHistoryView' ;
2122import {
2223 CommandDialog ,
@@ -30,6 +31,7 @@ import {
3031import useChatStoreAdapter from '@/hooks/useChatStoreAdapter' ;
3132import { replayProject } from '@/lib' ;
3233import { fetchHistoryTasks } from '@/service/historyApi' ;
34+ import { getAuthStore } from '@/store/authStore' ;
3335import { useGlobalStore } from '@/store/globalStore' ;
3436import { VisuallyHidden } from '@radix-ui/react-visually-hidden' ;
3537import { useTranslation } from 'react-i18next' ;
@@ -74,9 +76,35 @@ export function SearchHistoryDialog() {
7476 await replayProject ( projectStore , navigate , projectId , question , historyId ) ;
7577 } ;
7678
77- const handleDelete = ( taskId : string ) => {
78- // TODO: Implement delete functionality similar to HistorySidebar
79- console . log ( 'Delete task:' , taskId ) ;
79+ const handleDelete = async ( historyId : string , callback ?: ( ) => void ) => {
80+ try {
81+ await proxyFetchDelete ( `/api/chat/history/${ historyId } ` ) ;
82+
83+ // Also delete local files for this task if available (via Electron IPC)
84+ const history = historyTasks . find (
85+ ( item ) => String ( item . id ) === String ( historyId )
86+ ) ;
87+ const { email } = getAuthStore ( ) ;
88+ if ( history ?. task_id && ( window as any ) . ipcRenderer ) {
89+ try {
90+ await ( window as any ) . ipcRenderer . invoke (
91+ 'delete-task-files' ,
92+ email ,
93+ history . task_id ,
94+ history . project_id ?? undefined
95+ ) ;
96+ } catch ( error ) {
97+ console . warn ( 'Local file cleanup failed:' , error ) ;
98+ }
99+ }
100+
101+ setHistoryTasks ( ( list ) =>
102+ list . filter ( ( item ) => String ( item . id ) !== String ( historyId ) )
103+ ) ;
104+ callback ?.( ) ;
105+ } catch ( error ) {
106+ console . error ( 'Failed to delete history task:' , error ) ;
107+ }
80108 } ;
81109
82110 const handleShare = ( taskId : string ) => {
@@ -137,6 +165,20 @@ export function SearchHistoryDialog() {
137165 < div className = "overflow-hidden text-ellipsis whitespace-nowrap" >
138166 { task . question }
139167 </ div >
168+ < Button
169+ type = "button"
170+ variant = "ghost"
171+ size = "icon"
172+ className = "text-muted-foreground hover:text-foreground ml-auto"
173+ aria-label = "Delete history"
174+ onClick = { ( e ) => {
175+ e . preventDefault ( ) ;
176+ e . stopPropagation ( ) ;
177+ void handleDelete ( String ( task . id ) ) ;
178+ } }
179+ >
180+ < Trash2 size = { 16 } />
181+ </ Button >
140182 </ CommandItem >
141183 ) ) }
142184 </ CommandGroup >
0 commit comments