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 unpinned toast notification
thecodrr4375dc637ef6
diff --git a/apps/web/src/common/toasts.js b/apps/web/src/common/toasts.jsindex 53a2731d5..36d4bab58 100644--- a/apps/web/src/common/toasts.js+++ b/apps/web/src/common/toasts.js@@ -1,4 +1,5 @@import { db } from ".";+import { store as notestore } from "../stores/note-store";import { showToast } from "../utils/toast";function showNotesMovedToast(note, noteIds, notebook) {@@ -12,6 +13,7 @@ function showNotesMovedToast(note, noteIds, notebook) {if (noteIds.length === 1) {const undoAction = async () => {+ toast.hide();if (note.notebook?.id) {db.notes.move(note.notebook, note.id);const notebook = db.notebooks.notebook(note.notebook.id);@@ -23,7 +25,17 @@ function showNotesMovedToast(note, noteIds, notebook) {};actions = [{ text: "Undo", onClick: undoAction }];}- showToast("success", messageText, actions);+ var toast = showToast("success", messageText, actions);}-export { showNotesMovedToast };+async function showNoteUnpinnedToast(noteId) {+ const messageText = `Note unpinned successfully!`;+ const undoAction = async () => {+ toast.hide();+ await notestore.pin(noteId);+ };+ let actions = [{ text: "Undo", onClick: undoAction }];+ var toast = showToast("success", messageText, actions);+}++export { showNotesMovedToast, showNoteUnpinnedToast };diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.jsindex 1aaa18ce1..91c0185d4 100644--- a/apps/web/src/components/note/index.js+++ b/apps/web/src/components/note/index.js@@ -13,6 +13,8 @@ import { useTheme } from "emotion-theming";import Colors from "../menu/colors";import { showExportDialog } from "../dialogs/exportdialog";import { setHashParam } from "../../utils/useHashParam";+import { showToast } from "../../utils/toast";+import { showNoteUnpinnedToast } from "../../common/toasts";function menuItems(note, context) {return [@@ -25,7 +27,14 @@ function menuItems(note, context) {},{title: note.pinned ? "Unpin" : "Pin",- onClick: () => store.pin(note),+ onClick: async () => {+ try {+ await store.pin(note.id);+ if (note.pinned) await showNoteUnpinnedToast(note.id);+ } catch (e) {+ showToast("error", e.message);+ }+ },onlyPro: true,},{diff --git a/apps/web/src/stores/note-store.js b/apps/web/src/stores/note-store.jsindex adcce76a4..ce9e5039f 100644--- a/apps/web/src/stores/note-store.js+++ b/apps/web/src/stores/note-store.js@@ -84,16 +84,20 @@ class NoteStore extends BaseStore {}};- pin = async (note) => {- await db.notes.note(note).pin();- this.refresh();- this._syncEditor(note.id, "pinned", !note.pinned);+ pin = async (id) => {+ const note = db.notes.note(id);+ if (!this._syncEditor(note.id, "pinned", !note.data.pinned)) {+ await note.pin();+ this.refresh();+ }};- favorite = async (note) => {- await db.notes.note(note).favorite();- setTimeout(() => this.refreshContext(), 0);- this._setValue(note.id, "favorite", !note.favorite);+ favorite = async (id) => {+ const note = db.notes.note(id);+ if (!this._syncEditor(note.id, "favorite", !note.data.favorite)) {+ await note.favorite();+ this.refresh();+ }};unlock = async (id) => {@@ -127,7 +131,7 @@ class NoteStore extends BaseStore {if (index < 0) return;arr[index][prop] = value;- this._syncEditor(noteId, prop, value);+ // this._syncEditor(noteId, prop, value);});};@@ -136,9 +140,8 @@ class NoteStore extends BaseStore {*/_syncEditor = (noteId, action, value) => {const { session, setSession } = editorStore.get();- if (session.id === noteId) {- setSession((state) => (state.session[action] = value));- }+ if (session.id !== noteId) return false;+ setSession((state) => (state.session[action] = value), true);};}