A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
mobile: improve wording of delete notebook dialog
ammarahm-edfdeb34ff0a52
diff --git a/apps/mobile/app/components/dialog/index.js b/apps/mobile/app/components/dialog/index.jsindex da92a300b..6dd9719d1 100644--- a/apps/mobile/app/components/dialog/index.js+++ b/apps/mobile/app/components/dialog/index.js@@ -35,6 +35,7 @@ import BaseDialog from "./base-dialog";import DialogButtons from "./dialog-buttons";import DialogHeader from "./dialog-header";import { useCallback } from "react";+import { Button } from "../ui/button";export const Dialog = ({ context = "global" }) => {const colors = useThemeStore((state) => state.colors);@@ -54,7 +55,11 @@ export const Dialog = ({ context = "global" }) => {input: false,inputPlaceholder: "Enter some text",defaultValue: "",- disableBackdropClosing: false+ disableBackdropClosing: false,+ check: {+ info: "Check",+ type: "transparent"+ }});useEffect(() => {@@ -87,6 +92,7 @@ export const Dialog = ({ context = "global" }) => {if (data.context !== context) return;setDialogInfo(data);setVisible(true);+ setInputValue(data.defaultValue);},[context]);@@ -137,6 +143,9 @@ export const Dialog = ({ context = "global" }) => {paragraph={dialogInfo.paragraph}paragraphColor={dialogInfo.paragraphColor}padding={12}+ style={{+ minHeight: 0+ }}/><Seperator half />@@ -163,6 +172,28 @@ export const Dialog = ({ context = "global" }) => {</View>) : null}+ {dialogInfo.check ? (+ <>+ <Button+ onPress={() => {+ setInputValue(!inputValue);+ }}+ icon={+ inputValue+ ? "check-circle-outline"+ : "checkbox-blank-circle-outline"+ }+ style={{+ justifyContent: "flex-start"+ }}+ height={35}+ width="100%"+ title={dialogInfo.check.info}+ type={inputValue ? dialogInfo.check.type : "gray"}+ />+ </>+ ) : null}+<DialogButtonsonPressNegative={onNegativePress}onPressPositive={dialogInfo.positivePress && onPressPositive}diff --git a/apps/mobile/app/utils/functions.js b/apps/mobile/app/utils/functions.jsindex e4943039e..335470570 100644--- a/apps/mobile/app/utils/functions.js+++ b/apps/mobile/app/utils/functions.js@@ -29,22 +29,28 @@ import { eClearEditor } from "./events";import { useRelationStore } from "../stores/use-relation-store";import { presentDialog } from "../components/dialog/functions";-function deleteNotesConfirmDialog(items, type, context) {+function deleteConfirmDialog(items, type, context) {return new Promise((resolve) => {presentDialog({- title: "Delete Contained Notes?",- paragraph: `Do you want to delete notes within ${- items.length > 1 ? `these ${type}s` : `this ${type}`+ title: `Delete ${+ items.length > 1 ? `${items.length} ${type}s` : `${type}`}?`,- positiveText: "Yes",- negativeText: "No",- positivePress: () => {- resolve(true);+ positiveText: "Delete",+ negativeText: "Cancel",+ positivePress: (value) => {+ console.log(value);+ resolve({ delete: true, deleteNotes: value });},onClose: () => {- resolve(false);+ resolve({ delete: false });},- context: context+ context: context,+ check: {+ info: `Move all notes in ${+ items.length > 1 ? `these ${type}s` : `this ${type}`+ } to trash`,+ type: "transparent"+ }});});}@@ -107,50 +113,49 @@ export const deleteItems = async (item, context) => {}if (topics?.length > 0) {- const deleteNotes = await deleteNotesConfirmDialog(- topics,- "topic",- context- );- for (const topic of topics) {- if (deleteNotes) {- const notes = db.notebooks- .notebook(topic.notebookId)- .topics.topic(topic.id).all;- await db.notes.delete(...notes.map((note) => note.id));+ const result = await deleteConfirmDialog(topics, "topic", context);+ if (result.delete) {+ for (const topic of topics) {+ if (result.deleteNotes) {+ const notes = db.notebooks+ .notebook(topic.notebookId)+ .topics.topic(topic.id).all;+ await db.notes.delete(...notes.map((note) => note.id));+ }+ await db.notebooks.notebook(topic.notebookId).topics.delete(topic.id);}- await db.notebooks.notebook(topic.notebookId).topics.delete(topic.id);+ routesForUpdate.push("Notebook", "Notebooks");+ useMenuStore.getState().setMenuPins();+ ToastEvent.show({+ heading: `${topics.length > 1 ? "Topics" : "Topic"} deleted`,+ type: "success"+ });}- routesForUpdate.push("Notebook", "Notebooks");- useMenuStore.getState().setMenuPins();- ToastEvent.show({- heading: `${topics.length > 1 ? "Topics" : "Topic"} deleted`,- type: "success"- });}if (notebooks?.length > 0) {- const deleteNotes = await deleteNotesConfirmDialog(- notebooks,- "notebook",- context- );-- let ids = notebooks.map((i) => i.id);- if (deleteNotes) {- for (let id of ids) {- const topics = db.notebooks.notebook(id).topics.all;- for (let topic of topics) {- const notes = db.notebooks- .notebook(topic.notebookId)- .topics.topic(topic.id).all;+ const result = await deleteConfirmDialog(notebooks, "notebook", context);++ if (result.delete) {+ let ids = notebooks.map((i) => i.id);+ if (result.deleteNotes) {+ for (let id of ids) {+ const notebook = db.notebooks.notebook(id);+ const topics = notebook.topics.all;+ for (let topic of topics) {+ const notes = db.notebooks+ .notebook(topic.notebookId)+ .topics.topic(topic.id).all;+ await db.notes.delete(...notes.map((note) => note.id));+ }+ const notes = db.relations.from(notebook.data, "note");await db.notes.delete(...notes.map((note) => note.id));}}+ await db.notebooks.delete(...ids);+ routesForUpdate.push("Notebook", "Notebooks");+ useMenuStore.getState().setMenuPins();}- await db.notebooks.delete(...ids);- routesForUpdate.push("Notebook", "Notebooks");- useMenuStore.getState().setMenuPins();}Navigation.queueRoutesForUpdate(...routesForUpdate);