web: add support for moving locked notes to trash (#4134)

* web: added support for single/multi trash notes

* web: show error when trying to preview a locked note in trash

---------

Co-authored-by: Abdullah Atta <abdullahatta@streetwriters.co>
This commit is contained in:
Muhammad Ali
2024-01-26 16:37:54 +05:00
committed by GitHub
parent 76a4d5c2a5
commit af792e394c
3 changed files with 6 additions and 13 deletions

View File

@@ -35,20 +35,11 @@ type Item = {
};
async function moveNotesToTrash(notes: Item[], confirm = true) {
const item = notes[0];
if (confirm && !(await showMultiDeleteConfirmation(notes.length))) return;
if (notes.length === 1) {
if (
item.locked &&
!(await Vault.unlockNote(item.id, "unlock_and_delete_note"))
)
return;
item.locked = false;
}
if (notes.some((n) => n.locked) && !(await Vault.unlockVault())) return;
const items = notes.map((item) => {
if (item.locked || db.monographs?.isPublished(item.id)) return 0;
if (db.monographs?.isPublished(item.id)) return 0;
return item.id;
});

View File

@@ -539,7 +539,7 @@ const menuItems: (note: any, items?: any[]) => MenuItem[] = (
icon: Trash.path,
isDisabled:
items.length === 1
? db.monographs?.isPublished(note.id) || note.locked
? db.monographs?.isPublished(note.id)
: items.some((item) => !db.notes?.note(item.id).synced()),
onClick: () => Multiselect.moveNotesToTrash(items, items.length > 1),
multiSelect: true

View File

@@ -59,7 +59,9 @@ function TrashItem(props: TrashItemProps) {
menuItems={menuItems}
onClick={() => {
if (item.itemType === "note")
hashNavigate(`/notes/${item.id}/edit`, { replace: true });
!item.locked
? hashNavigate(`/notes/${item.id}/edit`, { replace: true })
: showToast("error", "Locked notes cannot be previewed in trash.");
}}
/>
);