@@ -46,13 +46,15 @@ interface ExportData {
4646}
4747
4848type OperationStatus = 'idle' | 'loading' | 'success' | 'error' ;
49+ type ClearType = 'tasks' | 'settings' | 'all' | null ;
4950
5051export function DataSettings ( ) {
5152 const { t } = useLanguage ( ) ;
5253 const [ exportStatus , setExportStatus ] = useState < OperationStatus > ( 'idle' ) ;
5354 const [ importStatus , setImportStatus ] = useState < OperationStatus > ( 'idle' ) ;
5455 const [ clearStatus , setClearStatus ] = useState < OperationStatus > ( 'idle' ) ;
5556 const [ showClearDialog , setShowClearDialog ] = useState ( false ) ;
57+ const [ confirmClearType , setConfirmClearType ] = useState < ClearType > ( null ) ;
5658 const [ errorMessage , setErrorMessage ] = useState < string > ( '' ) ;
5759
5860 // Export all data
@@ -186,24 +188,40 @@ export function DataSettings() {
186188 } ;
187189
188190 // Clear data
189- const handleClear = async ( clearSettings : boolean ) => {
191+ const handleClear = async ( type : ClearType ) => {
192+ if ( ! type ) return ;
193+
190194 setClearStatus ( 'loading' ) ;
191195 setErrorMessage ( '' ) ;
192196 setShowClearDialog ( false ) ;
197+ setConfirmClearType ( null ) ;
193198
194199 try {
195- // Clear workspace files first
196- await clearWorkspaceFiles ( ) ;
197-
198- // Get all tasks and delete them with their messages
199- const tasks = await getAllTasks ( ) ;
200- for ( const task of tasks ) {
201- await deleteMessagesByTaskId ( task . id ) ;
202- await deleteTask ( task . id ) ;
203- }
204-
205- // Clear settings if requested
206- if ( clearSettings ) {
200+ if ( type === 'settings' ) {
201+ // Clear settings only
202+ await clearAllSettings ( ) ;
203+ } else if ( type === 'tasks' ) {
204+ // Clear workspace files first
205+ await clearWorkspaceFiles ( ) ;
206+
207+ // Get all tasks and delete them with their messages
208+ const tasks = await getAllTasks ( ) ;
209+ for ( const task of tasks ) {
210+ await deleteMessagesByTaskId ( task . id ) ;
211+ await deleteTask ( task . id ) ;
212+ }
213+ } else if ( type === 'all' ) {
214+ // Clear workspace files first
215+ await clearWorkspaceFiles ( ) ;
216+
217+ // Get all tasks and delete them with their messages
218+ const tasks = await getAllTasks ( ) ;
219+ for ( const task of tasks ) {
220+ await deleteMessagesByTaskId ( task . id ) ;
221+ await deleteTask ( task . id ) ;
222+ }
223+
224+ // Clear settings
207225 await clearAllSettings ( ) ;
208226 }
209227
@@ -221,6 +239,25 @@ export function DataSettings() {
221239 }
222240 } ;
223241
242+ // Handle clear option click - show confirmation
243+ const handleClearOptionClick = ( type : ClearType ) => {
244+ setConfirmClearType ( type ) ;
245+ } ;
246+
247+ // Get confirmation message based on clear type
248+ const getConfirmMessage = ( type : ClearType ) : string => {
249+ switch ( type ) {
250+ case 'tasks' :
251+ return t . settings . dataClearTasksConfirm || 'Are you sure you want to delete all tasks and messages? This action cannot be undone.' ;
252+ case 'settings' :
253+ return t . settings . dataClearSettingsConfirm || 'Are you sure you want to reset all settings to defaults? This action cannot be undone.' ;
254+ case 'all' :
255+ return t . settings . dataClearAllConfirm || 'Are you sure you want to delete ALL data including tasks, messages, and settings? This action cannot be undone.' ;
256+ default :
257+ return '' ;
258+ }
259+ } ;
260+
224261 const getButtonContent = (
225262 status : OperationStatus ,
226263 icon : React . ReactNode ,
@@ -380,7 +417,7 @@ export function DataSettings() {
380417
381418 < div className = "space-y-3" >
382419 < button
383- onClick = { ( ) => handleClear ( false ) }
420+ onClick = { ( ) => handleClearOptionClick ( 'tasks' ) }
384421 className = { cn (
385422 'flex w-full items-center justify-between rounded-lg px-4 py-3 text-left transition-colors' ,
386423 'border-border hover:bg-accent border'
@@ -398,7 +435,25 @@ export function DataSettings() {
398435 </ button >
399436
400437 < button
401- onClick = { ( ) => handleClear ( true ) }
438+ onClick = { ( ) => handleClearOptionClick ( 'settings' ) }
439+ className = { cn (
440+ 'flex w-full items-center justify-between rounded-lg px-4 py-3 text-left transition-colors' ,
441+ 'border-border hover:bg-accent border'
442+ ) }
443+ >
444+ < div >
445+ < div className = "text-foreground font-medium" >
446+ { t . settings . dataClearSettingsOnly || 'Clear Settings Only' }
447+ </ div >
448+ < div className = "text-muted-foreground text-sm" >
449+ { t . settings . dataClearSettingsOnlyDescription ||
450+ 'Reset all settings to defaults, keep tasks' }
451+ </ div >
452+ </ div >
453+ </ button >
454+
455+ < button
456+ onClick = { ( ) => handleClearOptionClick ( 'all' ) }
402457 className = { cn (
403458 'flex w-full items-center justify-between rounded-lg px-4 py-3 text-left transition-colors' ,
404459 'border border-red-500/30 bg-red-500/5 hover:bg-red-500/10'
@@ -425,6 +480,47 @@ export function DataSettings() {
425480 </ div >
426481 </ div >
427482 ) }
483+
484+ { /* Confirmation Dialog */ }
485+ { confirmClearType && (
486+ < div className = "bg-background/80 fixed inset-0 z-[60] flex items-center justify-center backdrop-blur-sm" >
487+ < div className = "border-border bg-background mx-4 w-full max-w-md rounded-xl border p-6 shadow-lg" >
488+ < div className = "mb-4 flex items-center gap-3" >
489+ < div className = "flex size-10 items-center justify-center rounded-full bg-red-500/10 text-red-500" >
490+ < AlertTriangle className = "size-5" />
491+ </ div >
492+ < h3 className = "text-foreground text-lg font-semibold" >
493+ { t . settings . dataConfirmTitle || 'Confirm' }
494+ </ h3 >
495+ </ div >
496+
497+ < p className = "text-muted-foreground mb-6 text-sm" >
498+ { getConfirmMessage ( confirmClearType ) }
499+ </ p >
500+
501+ < div className = "flex gap-3" >
502+ < button
503+ onClick = { ( ) => setConfirmClearType ( null ) }
504+ className = { cn (
505+ 'flex-1 rounded-lg px-4 py-2 text-sm font-medium transition-colors' ,
506+ 'border-border text-foreground hover:bg-accent border'
507+ ) }
508+ >
509+ { t . settings . dataCancel || 'Cancel' }
510+ </ button >
511+ < button
512+ onClick = { ( ) => handleClear ( confirmClearType ) }
513+ className = { cn (
514+ 'flex-1 rounded-lg px-4 py-2 text-sm font-medium transition-colors' ,
515+ 'bg-red-500 text-white hover:bg-red-600'
516+ ) }
517+ >
518+ { t . settings . dataConfirmClear || 'Yes, Clear' }
519+ </ button >
520+ </ div >
521+ </ div >
522+ </ div >
523+ ) }
428524 </ div >
429525 ) ;
430526}
0 commit comments