fix: unable to delete multiple items with del key

(fixes streetwriters/notesnook#429)
This commit is contained in:
thecodrr
2022-03-23 09:49:24 +05:00
parent 5a0a729ca5
commit d509defe55
2 changed files with 9 additions and 17 deletions

View File

@@ -10,10 +10,9 @@ import { TaskManager } from "./task-manager";
async function moveNotesToTrash(notes: any[]) {
const item = notes[0];
const isMultiselect = notes.length > 1;
if (isMultiselect) {
if (!(await showMultiDeleteConfirmation(notes.length))) return;
} else {
if (!(await showMultiDeleteConfirmation(notes.length))) return;
if (notes.length === 1) {
if (
item.locked &&
!(await Vault.unlockNote(item.id, "unlock_and_delete_note"))
@@ -38,11 +37,7 @@ async function moveNotesToTrash(notes: any[]) {
},
});
if (isMultiselect) {
showToast("success", `${items.length} notes moved to trash`);
} else {
showItemDeletedToast(item);
}
showToast("success", `${items.length} notes moved to trash`);
}
async function moveNotebooksToTrash(notebooks: any[]) {

View File

@@ -15,6 +15,7 @@ import IconTag from "../icon-tag";
import { COLORS } from "../../common/constants";
import { exportNotes } from "../../common/export";
import { Multiselect } from "../../common/multi-select";
import { store as selectionStore } from "../../stores/selection-store";
function Note(props) {
const { tags, notebook, item, index, context, date } = props;
@@ -46,14 +47,10 @@ function Note(props) {
index={index}
onKeyPress={async (e) => {
if (e.key === "Delete") {
await confirm({
title: "Delete note?",
message:
"This item will be kept in your Trash for 7 days after which it will be permanently removed",
noText: "No",
yesText: "Yes",
yesAction: () => Multiselect.moveNotesToTrash([item]),
});
let selectedItems = selectionStore
.get()
.selectedItems.filter((i) => i.type === item.type && i !== item);
await Multiselect.moveNotesToTrash([item, ...selectedItems]);
}
}}
colors={{