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 permanent delete
thecodrr61d382aabfc5
diff --git a/apps/web/src/common/toasts.js b/apps/web/src/common/toasts.jsindex 5b6d19518..1e395fe3a 100644--- a/apps/web/src/common/toasts.js+++ b/apps/web/src/common/toasts.js@@ -1,6 +1,7 @@import { db } from ".";import { store as notestore } from "../stores/note-store";import { store as nbstore } from "../stores/notebook-store";+import { store as trashstore } from "../stores/trash-store";import { showToast } from "../utils/toast";function showNotesMovedToast(note, noteIds, notebook) {@@ -85,8 +86,21 @@ function showTrashItemRestored() {showToast("success", "Item restored");}-function showTrashItemPermanentDelete() {- showToast("success", "Item permanently deleted");+async function showPermanentDeleteToast(item, index) {+ const noun = item.type === "note" ? "Note" : "Notebook";+ const messageText = `${noun} permanently deleted!`;+ const timeoutId = setTimeout(() => {+ trashstore.delete(item.id, index, true);+ }, 5000);+ const undoAction = async () => {+ toast.hide();+ trashstore.set((state) => {+ state.trash.splice(index, 0, item);+ });+ clearTimeout(timeoutId);+ };+ let actions = [{ text: "Undo", onClick: undoAction }];+ var toast = showToast("success", messageText, actions);}export {@@ -96,5 +110,5 @@ export {showUnpinnedToast,showNoteBookDeleted,showTrashItemRestored,- showTrashItemPermanentDelete,+ showPermanentDeleteToast,};diff --git a/apps/web/src/stores/trash-store.js b/apps/web/src/stores/trash-store.jsindex 325ecb4ec..a640aae3e 100644--- a/apps/web/src/stores/trash-store.js+++ b/apps/web/src/stores/trash-store.js@@ -9,12 +9,13 @@ class TrashStore extends BaseStore {this.set((state) => (state.trash = db.trash.all));};- delete = (id, index) => {- return db.trash.delete(id).then(() => {- this.set((state) => {+ delete = (id, index, commit = false) => {+ if (!commit) {+ return this.set((state) => {state.trash.splice(index, 1);});- });+ }+ return db.trash.delete(id);};restore = (id, index) => {diff --git a/apps/web/src/views/trash.js b/apps/web/src/views/trash.jsindex 86ccf0c25..ef8edb698 100644--- a/apps/web/src/views/trash.js+++ b/apps/web/src/views/trash.js@@ -10,8 +10,8 @@ import { toTitleCase } from "../utils/string";import TrashPlaceholder from "../components/placeholders/trash-placeholder";import { showToast } from "../utils/toast";import {- showTrashItemPermanentDelete,showTrashItemRestored,+ showPermanentDeleteToast,} from "../common/toasts";function menuItems(item, index) {@@ -33,9 +33,8 @@ function menuItems(item, index) {`Are you sure you want to permanently delete this item?`).then(async (res) => {if (res) {- await store- .delete(item.id, index)- .then(showTrashItemPermanentDelete());+ await store.delete(item.id, index);+ showPermanentDeleteToast(item, index);}});},diff --git a/apps/web/yarn.lock b/apps/web/yarn.lockindex 251d83c69..78bd7498d 100644--- a/apps/web/yarn.lock+++ b/apps/web/yarn.lock@@ -7645,7 +7645,7 @@ normalize-url@^3.0.0, normalize-url@^3.0.1:"notes-core@git+ssh://[email protected]:streetwriters/notesnook-core.git":version "1.5.0"- resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#95ada5b4a905a6facc9168f8c6b5f517f227f55e"+ resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#244b587d695363d5ef90603b2bc2595fd15c164f"dependencies:crypto-random-string "^3.2.0"event-source-polyfill "^1.0.16"