@@ -15,6 +15,10 @@ import {
15
15
selectStyle ,
16
16
} from '../../shared/lib/styled/styleFunctions'
17
17
import Icon from '../../shared/components/atoms/Icon'
18
+ import Button from '../../shared/components/atoms/Button'
19
+ import { useDb } from '../../lib/db'
20
+ import { DialogIconTypes , useDialog } from '../../shared/lib/stores/dialog'
21
+ import { useToast } from '../../shared/lib/stores/toast'
18
22
19
23
interface TrashDetailProps {
20
24
storage : NoteStorage
@@ -24,6 +28,9 @@ const ArchiveDetail = ({ storage }: TrashDetailProps) => {
24
28
const { preferences, setPreferences } = usePreferences ( )
25
29
const noteSorting = preferences [ 'general.noteSorting' ]
26
30
const { t } = useTranslation ( )
31
+ const { purgeNote } = useDb ( )
32
+ const { messageBox } = useDialog ( )
33
+ const { pushMessage } = useToast ( )
27
34
28
35
const notes = useMemo ( ( ) => {
29
36
return values ( storage . noteMap )
@@ -68,6 +75,39 @@ const ArchiveDetail = ({ storage }: TrashDetailProps) => {
68
75
[ setPreferences ]
69
76
)
70
77
78
+ const removeAllArchivedNotes = useCallback ( ( ) => {
79
+ messageBox ( {
80
+ title : t ( 'note.delete' ) ,
81
+ message :
82
+ 'This operation is not reversible. Are you sure you want to permanently remove all archived notes?' ,
83
+ iconType : DialogIconTypes . Warning ,
84
+ buttons : [
85
+ {
86
+ variant : 'warning' ,
87
+ label : t ( 'note.delete' ) ,
88
+ onClick : async ( ) => {
89
+ try {
90
+ for ( const note of notes ) {
91
+ purgeNote ( storage . id , note . _id )
92
+ }
93
+ } catch {
94
+ pushMessage ( {
95
+ title : t ( 'general.networkError' ) ,
96
+ description : `An error occurred while removing notes.` ,
97
+ } )
98
+ }
99
+ } ,
100
+ } ,
101
+ {
102
+ label : t ( 'general.cancel' ) ,
103
+ cancelButton : true ,
104
+ defaultButton : true ,
105
+ variant : 'secondary' ,
106
+ } ,
107
+ ] ,
108
+ } )
109
+ } , [ messageBox , notes , purgeNote , pushMessage , storage . id , t ] )
110
+
71
111
if ( notes . length === 0 ) {
72
112
return (
73
113
< NoArchivedItemsContainer >
@@ -85,7 +125,17 @@ const ArchiveDetail = ({ storage }: TrashDetailProps) => {
85
125
{ t ( 'general.archive' ) }
86
126
</ Header >
87
127
< Control >
88
- < div className = 'left' />
128
+ < div className = 'left' >
129
+ < div >
130
+ < Button
131
+ size = { 'sm' }
132
+ variant = { 'danger' }
133
+ onClick = { ( ) => removeAllArchivedNotes ( ) }
134
+ >
135
+ Remove All
136
+ </ Button >
137
+ </ div >
138
+ </ div >
89
139
< div className = 'right' >
90
140
< select onChange = { selectNoteSorting } value = { noteSorting } >
91
141
{ < NoteSortingOptionsFragment /> }
0 commit comments