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
feat: add toast for notebook unpinning
thecodrr87bce25c3fbf
diff --git a/apps/web/src/common/toasts.js b/apps/web/src/common/toasts.jsindex b890a1aff..9a69fa80e 100644--- a/apps/web/src/common/toasts.js+++ b/apps/web/src/common/toasts.js@@ -1,5 +1,6 @@import { db } from ".";import { store as notestore } from "../stores/note-store";+import { store as nbstore } from "../stores/notebook-store";import { showToast } from "../utils/toast";function showNotesMovedToast(note, noteIds, notebook) {@@ -46,11 +47,13 @@ function showNoteColored(colors, label) {}}-async function showNoteUnpinnedToast(noteId) {- const messageText = `Note unpinned successfully!`;+async function showUnpinnedToast(itemId, itemType) {+ const noun = itemType === "note" ? "Note" : "Notebook";+ const messageText = `${noun} unpinned successfully!`;const undoAction = async () => {toast.hide();- await notestore.pin(noteId);+ if (itemType === "note") await notestore.pin(itemId);+ else if (itemType === "notebook") await nbstore.pin(itemId);};let actions = [{ text: "Undo", onClick: undoAction }];var toast = showToast("success", messageText, actions);@@ -60,5 +63,5 @@ export {showNotesMovedToast,showNoteDeleted,showNoteColored,- showNoteUnpinnedToast,+ showUnpinnedToast,};diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.jsindex ebb38f45f..9926550fb 100644--- a/apps/web/src/components/note/index.js+++ b/apps/web/src/components/note/index.js@@ -14,8 +14,7 @@ import Colors from "../menu/colors";import { showExportDialog } from "../dialogs/exportdialog";import { setHashParam } from "../../utils/useHashParam";import { showNoteDeleted } from "../../common/toasts";-import { showToast } from "../../utils/toast";-import { showNoteUnpinnedToast } from "../../common/toasts";+import { showUnpinnedToast } from "../../common/toasts";function menuItems(note, context) {return [@@ -29,12 +28,8 @@ function menuItems(note, context) {{title: note.pinned ? "Unpin" : "Pin",onClick: async () => {- try {- await store.pin(note.id);- if (note.pinned) await showNoteUnpinnedToast(note.id);- } catch (e) {- showToast("error", e.message);- }+ await store.pin(note.id);+ if (note.pinned) await showUnpinnedToast(note.id, "note");},onlyPro: true,},diff --git a/apps/web/src/components/notebook/index.js b/apps/web/src/components/notebook/index.jsindex e99998491..498a88b9b 100644--- a/apps/web/src/components/notebook/index.js+++ b/apps/web/src/components/notebook/index.js@@ -5,12 +5,16 @@ import { store } from "../../stores/notebook-store";import * as Icon from "../icons";import { showEditNoteDialog } from "../dialogs/addnotebookdialog";import { confirm } from "../dialogs/confirm";+import { showUnpinnedToast } from "../../common/toasts";function menuItems(notebook, index) {return [{title: notebook.pinned ? "Unpin" : "Pin",- onClick: () => store.pin(notebook, index),+ onClick: async () => {+ await store.pin(notebook, index);+ if (notebook.pinned) showUnpinnedToast(notebook.id, "notebook");+ },},{title: "Edit",diff --git a/apps/web/src/stores/notebook-store.js b/apps/web/src/stores/notebook-store.jsindex 4e67baf20..3c886d409 100644--- a/apps/web/src/stores/notebook-store.js+++ b/apps/web/src/stores/notebook-store.js@@ -8,10 +8,10 @@ class NotebookStore extends BaseStore {selectedNotebookTopics = [];refresh = () => {- this.set(state => (state.notebooks = db.notebooks.all));+ this.set((state) => (state.notebooks = db.notebooks.all));};- add = async nb => {+ add = async (nb) => {let notebook = await db.notebooks.add(nb);if (notebook) {this.refresh();@@ -20,19 +20,19 @@ class NotebookStore extends BaseStore {delete = async (id, index) => {await db.notebooks.delete(id);- this.set(state => {+ this.set((state) => {state.notebooks.splice(index, 1);trashStore.refresh();});};- pin = async notebook => {- await db.notebooks.notebook(notebook).pin();+ pin = async (notebookId) => {+ await db.notebooks.notebook(notebookId).pin();this.refresh();};- setSelectedNotebookTopics = id => {- this.set(state => {+ setSelectedNotebookTopics = (id) => {+ this.set((state) => {state.selectedNotebookTopics = db.notebooks.notebook(id).topics.all;});};