mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-24 04:00:59 +01:00
mobile: improve wording of delete notebook dialog
This commit is contained in:
committed by
Abdullah Atta
parent
ec76be776c
commit
fdeb34ff0a
@@ -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}
|
||||
|
||||
<DialogButtons
|
||||
onPressNegative={onNegativePress}
|
||||
onPressPositive={dialogInfo.positivePress && onPressPositive}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
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"
|
||||
});
|
||||
}
|
||||
|
||||
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 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);
|
||||
}
|
||||
routesForUpdate.push("Notebook", "Notebooks");
|
||||
useMenuStore.getState().setMenuPins();
|
||||
ToastEvent.show({
|
||||
heading: `${topics.length > 1 ? "Topics" : "Topic"} deleted`,
|
||||
type: "success"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (notebooks?.length > 0) {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user