fix: permanent delete not working

This commit is contained in:
thecodrr
2022-02-15 07:30:33 +05:00
parent 2a7309238b
commit f449fb6c33
4 changed files with 15 additions and 16 deletions

View File

@@ -1,7 +1,6 @@
import { db } from "./db"; import { db } from "./db";
import { store as notestore } from "../stores/note-store"; import { store as notestore } from "../stores/note-store";
import { store as nbstore } from "../stores/notebook-store"; import { store as nbstore } from "../stores/notebook-store";
import { store as trashstore } from "../stores/trash-store";
import { showToast } from "../utils/toast"; import { showToast } from "../utils/toast";
function showNotesMovedToast(note, noteIds, notebook) { function showNotesMovedToast(note, noteIds, notebook) {
@@ -57,12 +56,13 @@ function showItemDeletedToast(item) {
var toast = showToast("success", messageText, actions); var toast = showToast("success", messageText, actions);
} }
async function showUndoableToast(message, onAction, onUndo) { async function showUndoableToast(message, onAction, onPermanentAction, onUndo) {
const timeoutId = setTimeout(onAction, 5000); await onAction();
const timeoutId = setTimeout(onPermanentAction, 5000);
const undoAction = async () => { const undoAction = async () => {
clearTimeout(timeoutId);
toast.hide(); toast.hide();
onUndo(); onUndo();
clearTimeout(timeoutId);
}; };
let actions = [{ text: "Undo", onClick: undoAction }]; let actions = [{ text: "Undo", onClick: undoAction }];
var toast = showToast("success", message, actions); var toast = showToast("success", message, actions);

View File

@@ -318,8 +318,8 @@ const menuItems = [
{ {
key: "movetotrash", key: "movetotrash",
title: "Move to trash", title: "Move to trash",
color: "red", color: "error",
iconColor: "red", iconColor: "error",
icon: Icon.Trash, icon: Icon.Trash,
disabled: ({ items }) => disabled: ({ items }) =>
items.length === 1 && db.monographs.isPublished(items[0].id), items.length === 1 && db.monographs.isPublished(items[0].id),
@@ -337,8 +337,8 @@ const topicNoteMenuItems = [
key: "removefromtopic", key: "removefromtopic",
title: "Remove from topic", title: "Remove from topic",
icon: Icon.TopicRemove, icon: Icon.TopicRemove,
color: "red", color: "error",
iconColor: "red", iconColor: "error",
onClick: async ({ items, context }) => { onClick: async ({ items, context }) => {
await db.notebooks await db.notebooks
.notebook(context.value.id) .notebook(context.value.id)

View File

@@ -124,8 +124,8 @@ const menuItems = [
}, },
{ {
title: "Move to trash", title: "Move to trash",
color: "red", color: "error",
iconColor: "red", iconColor: "error",
icon: Icon.Trash, icon: Icon.Trash,
onClick: async ({ items }) => { onClick: async ({ items }) => {
await Multiselect.moveNotebooksToTrash(items); await Multiselect.moveNotebooksToTrash(items);

View File

@@ -1,9 +1,6 @@
import React from "react"; import React from "react";
import ListItem from "../list-item"; import ListItem from "../list-item";
import { import { showMultiPermanentDeleteConfirmation } from "../../common/dialog-controller";
confirm,
showMultiPermanentDeleteConfirmation,
} from "../../common/dialog-controller";
import * as Icon from "../icons"; import * as Icon from "../icons";
import { store } from "../../stores/trash-store"; import { store } from "../../stores/trash-store";
import { Flex, Text } from "rebass"; import { Flex, Text } from "rebass";
@@ -48,14 +45,16 @@ const menuItems = [
{ {
title: "Delete", title: "Delete",
icon: Icon.DeleteForver, icon: Icon.DeleteForver,
color: "red", color: "error",
iconColor: "error",
onClick: async ({ items }) => { onClick: async ({ items }) => {
if (!(await showMultiPermanentDeleteConfirmation(items.length))) return; if (!(await showMultiPermanentDeleteConfirmation(items.length))) return;
const ids = items.map((i) => i.id); const ids = items.map((i) => i.id);
showUndoableToast( showUndoableToast(
`${items.length} items permanently deleted`, `${items.length} items permanently deleted`,
() => store.delete(ids), () => store.delete(ids),
() => store.delete(ids, true) () => store.delete(ids, true),
() => store.refresh()
); );
}, },
multiSelect: true, multiSelect: true,