mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-03 12:41:45 +02:00
feat: add toast notification for add/move note to notebook
This commit is contained in:
29
apps/web/src/common/toasts.js
Normal file
29
apps/web/src/common/toasts.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { db } from ".";
|
||||
import { showToast } from "../utils/toast";
|
||||
|
||||
function showNotesMovedToast(note, noteIds, notebook) {
|
||||
let actions;
|
||||
|
||||
const newNotebook = db.notebooks.notebook(notebook.id);
|
||||
let verb =
|
||||
noteIds.length > 1 ? "added" : note.notebook?.id ? "moved" : "added";
|
||||
let messageText = noteIds.length > 1 ? `${noteIds.length} notes` : "Note";
|
||||
messageText += ` ${verb} to "${newNotebook.title}"`;
|
||||
|
||||
if (noteIds.length === 1) {
|
||||
const undoAction = async () => {
|
||||
if (note.notebook?.id) {
|
||||
db.notes.move(note.notebook, note.id);
|
||||
const notebook = db.notebooks.notebook(note.notebook.id);
|
||||
showToast("success", `Note moved back to "${notebook.title}"`);
|
||||
} else {
|
||||
await newNotebook.topics.topic(notebook.topic).delete(note.id);
|
||||
showToast("success", `Note removed from "${newNotebook.title}"`);
|
||||
}
|
||||
};
|
||||
actions = [{ text: "Undo", onClick: undoAction }];
|
||||
}
|
||||
showToast("success", messageText, actions);
|
||||
}
|
||||
|
||||
export { showNotesMovedToast };
|
||||
@@ -5,6 +5,8 @@ import * as Icon from "../icons";
|
||||
import { db } from "../../common";
|
||||
import Dialog, { showDialog } from "./dialog";
|
||||
import { toTitleCase } from "../../utils/string";
|
||||
import { showNotesMovedToast } from "../../common/toasts";
|
||||
import { showToast } from "../../utils/toast";
|
||||
|
||||
class MoveDialog extends React.Component {
|
||||
history = [];
|
||||
@@ -40,12 +42,16 @@ class MoveDialog extends React.Component {
|
||||
text: "Move",
|
||||
onClick: async () => {
|
||||
try {
|
||||
await db.notes.move(
|
||||
{ id: this.selectedNotebook.id, topic: this.selectedTopic },
|
||||
...props.noteIds
|
||||
);
|
||||
const notebook = {
|
||||
id: this.selectedNotebook.id,
|
||||
topic: this.selectedTopic,
|
||||
};
|
||||
const note = db.notes.note(props.noteIds[0]).data;
|
||||
await db.notes.move(notebook, ...props.noteIds);
|
||||
showNotesMovedToast(note, props.noteIds, notebook);
|
||||
props.onMove();
|
||||
} catch (e) {
|
||||
showToast("error", e.message);
|
||||
console.error(e);
|
||||
} finally {
|
||||
props.onClose();
|
||||
|
||||
@@ -20,9 +20,7 @@ function menuItems(note, context) {
|
||||
{
|
||||
title: note.notebook?.id ? "Move" : "Add to",
|
||||
onClick: async () => {
|
||||
if (await showMoveNoteDialog([note.id])) {
|
||||
console.log("Note moved successfully!");
|
||||
}
|
||||
await showMoveNoteDialog([note.id]);
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user