mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-03 12:41:45 +02:00
feat: add toast for notebook unpinning
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user