feat: no need to show confirm dialogs before moving to trash

This commit is contained in:
thecodrr
2021-01-12 23:33:05 +05:00
parent 3c2d429831
commit 7dd430f6be
5 changed files with 16 additions and 98 deletions

View File

@@ -6,7 +6,7 @@ import { store as editorStore } from "../stores/editor-store";
import { store as trashStore } from "../stores/trash-store";
import { db } from "./index";
import { showMoveNoteDialog } from "../components/dialogs/movenotedialog";
import { showDeleteConfirmation } from "../components/dialogs/confirm";
import { showMultiDeleteConfirmation } from "../components/dialogs/confirm";
import { showExportDialog } from "../components/dialogs/exportdialog";
import { showToast } from "../utils/toast";
@@ -31,7 +31,7 @@ const DeleteOption = createOption(
async function (state) {
const item = state.selectedItems[0];
if (!(await showDeleteConfirmation(item.type, true))) return;
if (!(await showMultiDeleteConfirmation(item.type))) return;
var isAnyNoteOpened = false;
const items = state.selectedItems.map((item) => {

View File

@@ -49,33 +49,6 @@ export function confirm(
));
}
/**
*
* @param {"note"|"notebook"} type
*/
export function showDeleteConfirmation(type, multi = false) {
let noun = type === "note" ? "Note" : "Notebook";
if (multi) noun += "s";
let lowerCaseNoun = noun.toLowerCase();
let secondPronoun = multi ? "they" : "it";
return confirm(Icon.Trash, {
title: `Delete ${noun}?`,
message: (
<Text as="span" fontSize="body">
The {lowerCaseNoun} will be{" "}
<Text as="span" color="primary">
kept in your Trash for 7 days
</Text>{" "}
after which {secondPronoun} will be permanently removed.
</Text>
),
yesText: `Delete ${lowerCaseNoun}`,
noText: "Cancel",
});
}
export function showMultiDeleteConfirmation(type) {
let noun = type === "note" ? "Notes" : "Notebooks";

View File

@@ -3,7 +3,6 @@ import { Flex, Text } from "rebass";
import * as Icon from "../icons";
import TimeAgo from "timeago-react";
import ListItem from "../list-item";
import { confirm, showDeleteConfirmation } from "../dialogs/confirm";
import { showMoveNoteDialog } from "../dialogs/movenotedialog";
import { store, useStore } from "../../stores/note-store";
import { showPasswordDialog } from "../dialogs/passworddialog";
@@ -68,33 +67,12 @@ function menuItems(note, context) {
visible: context?.type === "topic",
title: "Remove from topic",
onClick: async () => {
confirm(Icon.Topic, {
title: "Remove Note from Topic",
subtitle: "Are you sure you want to remove the note from this topic?",
yesText: "Remove note",
noText: "Cancel",
message: (
<Text as="span">
<Text as="span" color="primary">
This action does not delete the note.
</Text>{" "}
The note will only be removed from this notebook. You will still
be able to{" "}
<Text as="span" color="primary">
access it from Home and other places.
</Text>
</Text>
),
}).then(async (res) => {
if (res) {
console.log(context);
await db.notebooks
.notebook(context.value.id)
.topics.topic(context.value.topic)
.delete(note.id);
store.setContext(context);
}
});
await db.notebooks
.notebook(context.value.id)
.topics.topic(context.value.topic)
.delete(note.id);
store.setContext(context);
await showToast("success", "Note removed from topic!");
},
},
{
@@ -110,11 +88,7 @@ function menuItems(note, context) {
});
if (!res) return;
}
showDeleteConfirmation("note").then(async (res) => {
if (res) {
await store.delete(note.id).then(() => showItemDeletedToast(note));
}
});
await store.delete(note.id).then(() => showItemDeletedToast(note));
},
},
];

View File

@@ -3,7 +3,6 @@ import { Flex, Text } from "rebass";
import ListItem from "../list-item";
import { store } from "../../stores/notebook-store";
import { store as appStore } from "../../stores/app-store";
import { showDeleteConfirmation } from "../dialogs/confirm";
import { showItemDeletedToast, showUnpinnedToast } from "../../common/toasts";
import { db } from "../../common";
import * as Icon from "../icons";
@@ -33,14 +32,10 @@ function menuItems(notebook, index) {
{
title: "Move to trash",
color: "red",
onClick: () => {
showDeleteConfirmation("notebook").then(async (res) => {
if (res) {
await store
.delete(notebook.id, index)
.then(() => showItemDeletedToast(notebook));
}
});
onClick: async () => {
await store
.delete(notebook.id, index)
.then(() => showItemDeletedToast(notebook));
},
},
];

View File

@@ -1,11 +1,8 @@
import React from "react";
import ListItem from "../list-item";
import { confirm } from "../dialogs/confirm";
import * as Icon from "../icons";
import { db } from "../../common";
import { store } from "../../stores/notebook-store";
import { store as appStore } from "../../stores/app-store";
import { Text } from "rebass";
import { hashNavigate } from "../../navigation";
const menuItems = (item) => [
@@ -25,30 +22,9 @@ const menuItems = (item) => [
title: "Delete",
visible: item.title !== "General",
color: "red",
onClick: () => {
confirm(Icon.Trash, {
title: "Delete topic",
subtitle: "Are you sure you want to delete this topic?",
yesText: "Delete topic",
noText: "Cancel",
message: (
<>
This action is{" "}
<Text as="span" color="error">
IRREVERSIBLE
</Text>
. Deleting this topic{" "}
<Text as="span" color="primary">
will not delete the notes contained in it.
</Text>
</>
),
}).then(async (res) => {
if (res) {
await db.notebooks.notebook(item.notebookId).topics.delete(item.id);
store.setSelectedNotebookTopics(item.notebookId);
}
});
onClick: async () => {
await db.notebooks.notebook(item.notebookId).topics.delete(item.id);
store.setSelectedNotebookTopics(item.notebookId);
},
},
];