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
fix: monographs are not updating on changes
thecodrr315fd444e5d5
diff --git a/apps/web/src/common/index.js b/apps/web/src/common/index.jsindex c5872fa5d..b7a822b79 100644--- a/apps/web/src/common/index.js+++ b/apps/web/src/common/index.js@@ -67,6 +67,9 @@ export function notesFromContext(context) {case "favorite":notes = db.notes.favorites;break;+ case "monographs":+ notes = db.monographs.all;+ break;default:return [];}diff --git a/apps/web/src/components/editor/toolbar.js b/apps/web/src/components/editor/toolbar.jsindex a7c45015e..f66309dd6 100644--- a/apps/web/src/components/editor/toolbar.js+++ b/apps/web/src/components/editor/toolbar.js@@ -4,6 +4,7 @@ import { Button, Flex, Text } from "rebass";import * as Icon from "../icons";import { useStore as useAppStore } from "../../stores/app-store";import { useStore as useThemeStore } from "../../stores/theme-store";+import { useStore as useMonographStore } from "../../stores/monograph-store";import { useStore, store } from "../../stores/editor-store";import { showToast } from "../../utils/toast";import { AnimatedInput } from "../animated";@@ -27,10 +28,11 @@ function Toolbar(props) {const theme = useThemeStore((store) => store.theme);const toggleNightMode = useThemeStore((store) => store.toggleNightMode);const [isTitleVisible, setIsTitleVisible] = useState(false);+ const monographs = useMonographStore((store) => store.monographs);const isNotePublished = useMemo(() => sessionId && db.monographs.isPublished(sessionId),- [sessionId]+ [sessionId, monographs]);useEffect(() => {diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.jsindex 2d406703d..9f36c1174 100644--- a/apps/web/src/components/note/index.js+++ b/apps/web/src/components/note/index.js@@ -292,7 +292,9 @@ const menuItems = [title: ({ note }) =>db.monographs.isPublished(note.id) ? "Unpublish" : "Publish",onClick: async ({ note }) => {- await showPublishView(note.id, "bottom");+ const isPublished = db.monographs.isPublished(note.id);+ if (isPublished) await db.monographs.unpublish(note.id);+ else await showPublishView(note.id, "bottom");},},{diff --git a/apps/web/src/components/publish-view/index.js b/apps/web/src/components/publish-view/index.jsindex c1e006303..1458341c9 100644--- a/apps/web/src/components/publish-view/index.js+++ b/apps/web/src/components/publish-view/index.js@@ -9,6 +9,7 @@ import * as clipboard from "clipboard-polyfill/text";import ThemeProvider from "../theme-provider";import { showToast } from "../../utils/toast";import { EV, EVENTS } from "notes-core/common";+import { useStore } from "../../stores/monograph-store";import { closeOpenedDialog } from "../../common/dialog-controller";function PublishView(props) {@@ -18,6 +19,8 @@ function PublishView(props) {const [selfDestruct, setSelfDestruct] = useState(false);const [isPublishing, setIsPublishing] = useState(false);const [processingStatus, setProcessingStatus] = useState();+ const publishNote = useStore((store) => store.publish);+ const unpublishNote = useStore((store) => store.unpublish);const noteTitle = useMemo(() => db.notes.note(noteId)?.title, [noteId]);@@ -190,7 +193,7 @@ function PublishView(props) {const password =document.getElementById("publishPassword")?.value;- const publishId = await db.monographs.publish(noteId, {+ const publishId = await publishNote(noteId, {selfDestruct,password,});@@ -226,7 +229,7 @@ function PublishView(props) {onClick={async () => {try {setIsPublishing(true);- await db.monographs.unpublish(noteId);+ await unpublishNote(noteId);setPublishId();onClose(true);showToast("success", "Note unpublished.");diff --git a/apps/web/src/navigation/routes.js b/apps/web/src/navigation/routes.jsindex ea2e41d47..dfb791c1b 100644--- a/apps/web/src/navigation/routes.js+++ b/apps/web/src/navigation/routes.js@@ -11,7 +11,6 @@ import { navigate } from "../navigation";import Trash from "../views/trash";import { store as notestore } from "../stores/note-store";import { store as nbstore } from "../stores/notebook-store";-import Monographs from "../views/monographs";import { showToast } from "../utils/toast";const routes = {@@ -167,12 +166,20 @@ const routes = {title: "Settings",component: <Settings />,}),- "/monographs": () => ({- key: "monographs",- type: "monographs",- title: "Monographs",- component: <Monographs />,- }),+ "/monographs": () => {+ notestore.setContext({ type: "monographs" });+ return {+ key: "notes",+ title: "Monographs",+ type: "notes",+ component: <Notes />,+ buttons: {+ search: {+ title: "Search monograph notes",+ },+ },+ };+ },"/search/:type": ({ type }) => ({type: "search",title: "Search",diff --git a/apps/web/src/stores/monograph-store.js b/apps/web/src/stores/monograph-store.jsnew file mode 100644index 000000000..266b28f56--- /dev/null+++ b/apps/web/src/stores/monograph-store.js@@ -0,0 +1,31 @@+import createStore from "../common/store";+import { db } from "../common/db";+import BaseStore from "./index";+import { store as notestore } from "./note-store";++class TagStore extends BaseStore {+ monographs = [];++ refresh = () => {+ this.set((state) => (state.monographs = db.monographs.all));+ };++ publish = async (noteId, opts) => {+ const publishId = await db.monographs.publish(noteId, opts);+ this.get().refresh();+ notestore.refreshContext();+ return publishId;+ };++ unpublish = async (noteId) => {+ await db.monographs.unpublish(noteId);+ this.get().refresh();+ notestore.refreshContext();+ };+}++/**+ * @type {[import("zustand").UseStore<TagStore>, TagStore]}+ */+const [useStore, store] = createStore(TagStore);+export { useStore, store };diff --git a/apps/web/src/views/monographs.js b/apps/web/src/views/monographs.jsdeleted file mode 100644index 656916439..000000000--- a/apps/web/src/views/monographs.js+++ /dev/null@@ -1,21 +0,0 @@-import React, { useState } from "react";-import { db } from "../common/db";-import ListContainer from "../components/list-container";-import MonographsPlaceholder from "../components/placeholders/monographsplaceholder";-import useNavigate from "../utils/use-navigate";--function Monographs() {- const [monographs, setMonographs] = useState([]);- useNavigate("monographs", () => {- setMonographs(db.monographs.all);- });- return (- <ListContainer- type="notes"- groupType="notes"- items={monographs}- placeholder={MonographsPlaceholder}- />- );-}-export default Monographs;