Skip to content

Commit d7bec3d

Browse files
committed
Add remove all archived documents
1 parent 11656cc commit d7bec3d

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

src/components/organisms/ArchiveDetail.tsx

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import {
1515
selectStyle,
1616
} from '../../shared/lib/styled/styleFunctions'
1717
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'
1822

1923
interface TrashDetailProps {
2024
storage: NoteStorage
@@ -24,6 +28,9 @@ const ArchiveDetail = ({ storage }: TrashDetailProps) => {
2428
const { preferences, setPreferences } = usePreferences()
2529
const noteSorting = preferences['general.noteSorting']
2630
const { t } = useTranslation()
31+
const { purgeNote } = useDb()
32+
const { messageBox } = useDialog()
33+
const { pushMessage } = useToast()
2734

2835
const notes = useMemo(() => {
2936
return values(storage.noteMap)
@@ -68,6 +75,39 @@ const ArchiveDetail = ({ storage }: TrashDetailProps) => {
6875
[setPreferences]
6976
)
7077

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+
71111
if (notes.length === 0) {
72112
return (
73113
<NoArchivedItemsContainer>
@@ -85,7 +125,17 @@ const ArchiveDetail = ({ storage }: TrashDetailProps) => {
85125
{t('general.archive')}
86126
</Header>
87127
<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>
89139
<div className='right'>
90140
<select onChange={selectNoteSorting} value={noteSorting}>
91141
{<NoteSortingOptionsFragment />}

0 commit comments

Comments
 (0)