Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: allow deleting contained notes during notebook/topic deletion

alihamuh4dbd49d61200
diff --git a/apps/web/src/components/notebook/index.js b/apps/web/src/components/notebook/index.js
index def799489..99f02f414 100644
--- a/apps/web/src/components/notebook/index.js
+++ b/apps/web/src/components/notebook/index.js
@@ -30,6 +30,7 @@ import IconTag from "../icon-tag";
import { showToast } from "../../utils/toast";
import { Multiselect } from "../../common/multi-select";
import { pluralize } from "../../utils/string";
+import { confirm } from "../../common/dialog-controller";
function Notebook(props) {
const { item, index, totalNotes, date, simplified } = props;
@@ -150,6 +151,25 @@ const menuItems = [
iconColor: "error",
icon: Icon.Trash,
onClick: async ({ items }) => {
+ const shouldDeleteNotes = await confirm({
+ title: `Delete Contained Notes?`,
+ message: `Do you also want to delete notes within ${items.length > 1 ? "this notebook" : "these notebooks"}?`,
+ yesText: `Yes`,
+ noText: "No"
+ });
+
+ let notes = [];
+ if (shouldDeleteNotes) {
+ for (const item of items) {
+ const topics = db.notebooks.notebook(item.id).topics;
+ for (const topic of topics.all) {
+ for (const note of topics.topic(topic.id).all) {
+ notes.push(note);
+ }
+ }
+ }
+ await Multiselect.moveNotesToTrash(notes, false);
+ }
await Multiselect.moveNotebooksToTrash(items);
},
multiSelect: true
diff --git a/apps/web/src/components/topic/index.js b/apps/web/src/components/topic/index.js
index 31bddfd9f..6b7e5b65a 100644
--- a/apps/web/src/components/topic/index.js
+++ b/apps/web/src/components/topic/index.js
@@ -26,6 +26,7 @@ import { Flex, Text } from "@theme-ui/components";
import * as Icon from "../icons";
import { Multiselect } from "../../common/multi-select";
import { pluralize } from "../../utils/string";
+import { confirm } from "../../common/dialog-controller";
function Topic({ item, index, onClick }) {
const { id, notebookId } = item;
@@ -88,6 +89,24 @@ const menuItems = [
color: "error",
iconColor: "error",
onClick: async ({ items, notebookId }) => {
+ let showDeleteNotesDialog = confirm({
+ title: `Delete Contained Notes?`,
+ message: `Do you also want to delete notes within ${items.length > 1 ? "this topic" : "these topics"}?`,
+ yesText: `Yes`,
+ noText: "No"
+ });
+
+ let notes = [];
+ if (await showDeleteNotesDialog) {
+ for (const item of items) {
+ for (const note of db.notebooks
+ .notebook(notebookId)
+ .topics.topic(item.id).all) {
+ notes.push(note);
+ }
+ }
+ await Multiselect.moveNotesToTrash(notes, false);
+ }
await Multiselect.deleteTopics(notebookId, items);
},
multiSelect: true