Skip to content

Add remove all archived documents #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2022
Merged
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
52 changes: 51 additions & 1 deletion src/components/organisms/ArchiveDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import {
selectStyle,
} from '../../shared/lib/styled/styleFunctions'
import Icon from '../../shared/components/atoms/Icon'
import Button from '../../shared/components/atoms/Button'
import { useDb } from '../../lib/db'
import { DialogIconTypes, useDialog } from '../../shared/lib/stores/dialog'
import { useToast } from '../../shared/lib/stores/toast'

interface TrashDetailProps {
storage: NoteStorage
Expand All @@ -24,6 +28,9 @@ const ArchiveDetail = ({ storage }: TrashDetailProps) => {
const { preferences, setPreferences } = usePreferences()
const noteSorting = preferences['general.noteSorting']
const { t } = useTranslation()
const { purgeNote } = useDb()
const { messageBox } = useDialog()
const { pushMessage } = useToast()

const notes = useMemo(() => {
return values(storage.noteMap)
Expand Down Expand Up @@ -68,6 +75,39 @@ const ArchiveDetail = ({ storage }: TrashDetailProps) => {
[setPreferences]
)

const removeAllArchivedNotes = useCallback(() => {
messageBox({
title: t('note.delete'),
message:
'This operation is not reversible. Are you sure you want to permanently remove all archived notes?',
iconType: DialogIconTypes.Warning,
buttons: [
{
variant: 'warning',
label: t('note.delete'),
onClick: async () => {
try {
for (const note of notes) {
purgeNote(storage.id, note._id)
}
} catch {
pushMessage({
title: t('general.networkError'),
description: `An error occurred while removing notes.`,
})
}
},
},
{
label: t('general.cancel'),
cancelButton: true,
defaultButton: true,
variant: 'secondary',
},
],
})
}, [messageBox, notes, purgeNote, pushMessage, storage.id, t])

if (notes.length === 0) {
return (
<NoArchivedItemsContainer>
Expand All @@ -85,7 +125,17 @@ const ArchiveDetail = ({ storage }: TrashDetailProps) => {
{t('general.archive')}
</Header>
<Control>
<div className='left' />
<div className='left'>
<div>
<Button
size={'sm'}
variant={'danger'}
onClick={() => removeAllArchivedNotes()}
>
Remove All
</Button>
</div>
</div>
<div className='right'>
<select onChange={selectNoteSorting} value={noteSorting}>
{<NoteSortingOptionsFragment />}
Expand Down