Skip to content

Commit

Permalink
feat: add empty trash option
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonella Sgarlatta committed May 12, 2021
1 parent 075f1b9 commit 674f14b
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 23 deletions.
3 changes: 3 additions & 0 deletions app/assets/icons/ic-trash-sweep.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions app/assets/javascripts/components/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ChevronRightIcon from '../../icons/ic-chevron-right.svg';
import RestoreIcon from '../../icons/ic-restore.svg';
import CloseIcon from '../../icons/ic-close.svg';
import PasswordIcon from '../../icons/ic-textbox-password.svg';
import TrashSweepIcon from '../../icons/ic-trash-sweep.svg';
import { toDirective } from './utils';

const ICONS = {
Expand All @@ -25,6 +26,7 @@ const ICONS = {
'restore': RestoreIcon,
'close': CloseIcon,
'password': PasswordIcon,
'trash-sweep': TrashSweepIcon,
};

type Props = {
Expand Down
59 changes: 37 additions & 22 deletions app/assets/javascripts/components/NotesOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,29 +238,44 @@ export const NotesOptions = observer(
</button>
)}
{trashed && (
<button
onBlur={closeOnBlur}
className={`${buttonClass} py-1.5`}
onClick={async () => {
await appState.notes.setTrashSelectedNotes(false);
}}
>
<Icon type='restore' className={iconClass} />
Restore
</button>
<>
<button
onBlur={closeOnBlur}
className={`${buttonClass} py-1.5`}
onClick={async () => {
await appState.notes.setTrashSelectedNotes(false);
}}
>
<Icon type='restore' className={iconClass} />
Restore
</button>
<button
onBlur={closeOnBlur}
className={`${buttonClass} py-1.5`}
onClick={async () => {
await appState.notes.deleteNotesPermanently();
}}
>
<Icon type="close" className="fill-current color-danger mr-2" />
<span className="color-danger">Delete permanently</span>
</button>
<button
onBlur={closeOnBlur}
className={`${buttonClass} py-1.5`}
onClick={async () => {
await appState.notes.emptyTrash();
}}
>
<div className="flex items-start">
<Icon type="trash-sweep" className="fill-current color-danger mr-2" />
<div className="flex-row">
<div className="color-danger">Empty Trash</div>
<div className="text-xs">{appState.notes.trashedNotesCount} notes in Trash</div>
</div>
</div>
</button>
</>
)}
{appState.selectedTag?.isTrashTag && (
<button
onBlur={closeOnBlur}
className={`${buttonClass} py-1.5`}
onClick={async () => {
await appState.notes.deleteNotesPermanently();
}}
>
<Icon type="close" className="fill-current color-danger mr-2" />
<span className="color-danger">Delete permanently</span>
</button>
)}
</>
);
}
Expand Down
20 changes: 19 additions & 1 deletion app/assets/javascripts/ui_models/app_state/notes_state.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { confirmDialog } from '@/services/alertService';
import { KeyboardModifier } from '@/services/ioService';
import { Strings, StringUtils } from '@/strings';
import { StringEmptyTrash, Strings, StringUtils } from '@/strings';
import {
UuidString,
SNNote,
Expand Down Expand Up @@ -40,6 +40,7 @@ export class NotesState {
showProtectedWarning: observable,

selectedNotesCount: computed,
trashedNotesCount: computed,

deleteNotesPermanently: action,
selectNote: action,
Expand All @@ -55,6 +56,7 @@ export class NotesState {
removeTagFromSelectedNotes: action,
isTagInSelectedNotes: action,
setShowProtectedWarning: action,
emptyTrash: action,
});

appEventListeners.push(
Expand All @@ -78,6 +80,10 @@ export class NotesState {
return Object.keys(this.selectedNotes).length;
}

get trashedNotesCount(): number {
return this.application.getTrashedItems().length;
}

async runProtectedAction(action: (note: SNNote) => void, notes: SNNote[]): Promise<void> {
let protectedNotesAccessRequest: Promise<boolean>;
await Promise.all(
Expand Down Expand Up @@ -358,6 +364,18 @@ export class NotesState {
this.showProtectedWarning = show;
}

async emptyTrash() {
if (
await confirmDialog({
text: StringEmptyTrash(this.trashedNotesCount),
confirmButtonStyle: 'danger',
})
) {
this.application.emptyTrash();
this.application.sync();
}
}

private get io() {
return this.application.io;
}
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/_sn.scss
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@
overflow-y: scroll;
}

.items-start {
align-items: flex-start;
}

/**
* A button that is just an icon. Separated from .sn-button because there
* is almost no style overlap.
Expand Down

0 comments on commit 674f14b

Please sign in to comment.