Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix: notebooks is removed from note on editing

thecodrr04c14018f4ff
diff --git a/apps/web/src/common/dialogcontroller.js b/apps/web/src/common/dialogcontroller.js
index 059a93201..01c392b41 100644
--- a/apps/web/src/common/dialogcontroller.js
+++ b/apps/web/src/common/dialogcontroller.js
@@ -21,7 +21,7 @@ function showDialog(dialog) {
return new Promise((resolve) => {
const perform = (result) => {
ReactDOM.unmountComponentAtNode(root);
- hashNavigate("/", true);
+ hashNavigate("/", { replace: true });
resolve(result);
};
const PropDialog = dialog(Dialogs, perform);
diff --git a/apps/web/src/common/index.js b/apps/web/src/common/index.js
index aa350533f..12992f165 100644
--- a/apps/web/src/common/index.js
+++ b/apps/web/src/common/index.js
@@ -39,7 +39,8 @@ export const SELECTION_OPTIONS_MAP = {
export const CREATE_BUTTON_MAP = {
notes: {
title: "Make a note",
- onClick: () => hashNavigate("/notes/create", true),
+ onClick: () =>
+ hashNavigate("/notes/create", { addNonce: true, replace: true }),
},
notebooks: {
title: "Create a notebook",
diff --git a/apps/web/src/components/editor/-placeholder.js b/apps/web/src/components/editor/-placeholder.js
index 2046293e8..d9068df56 100644
--- a/apps/web/src/components/editor/-placeholder.js
+++ b/apps/web/src/components/editor/-placeholder.js
@@ -27,7 +27,7 @@ function EditorPlaceholder() {
justifyContent: "center",
}}
variant="tool"
- onClick={() => hashNavigate("/notes/create")}
+ onClick={() => hashNavigate("")}
>
<Icon.Plus size={18} color="primary" />
<Text ml={1}>Make a new note</Text>
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.js
index df9e06b3c..1a16686e9 100644
--- a/apps/web/src/components/editor/index.js
+++ b/apps/web/src/components/editor/index.js
@@ -23,10 +23,10 @@ import EditorLoading from "./loading";
const ReactMCE = React.lazy(() => import("./tinymce"));
-function Editor({ noteId }) {
+function Editor({ noteId, nonce }) {
const editorRef = useRef();
const sessionState = useStore((store) => store.session.state);
- const sessionId = useStore((store) => store.session.id);
+ const sessionNonce = useStore((store) => store.session.nonce);
const contentType = useStore((store) => store.session.content?.type);
const setSession = useStore((store) => store.setSession);
const saveSession = useStore((store) => store.saveSession);
@@ -49,12 +49,12 @@ function Editor({ noteId }) {
const startSession = useCallback(
async function startSession(noteId) {
- if (noteId === 0) newSession();
+ if (noteId === 0) newSession(nonce);
else if (noteId) {
await openSession(noteId);
}
},
- [newSession, openSession]
+ [newSession, openSession, nonce]
);
useEffect(() => {
@@ -89,7 +89,7 @@ function Editor({ noteId }) {
editor.off("init", setContents);
};
}
- }, [editorRef, contentType, sessionState]);
+ }, [editorRef, contentType, sessionState, sessionNonce]);
return (
<Flex
diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.js
index 5c9f5c312..0db2a3a91 100644
--- a/apps/web/src/components/note/index.js
+++ b/apps/web/src/components/note/index.js
@@ -55,11 +55,11 @@ function Note(props) {
}}
onClick={() => {
if (note.conflicted) {
- hashNavigate(`/notes/${note.id}/conflict`, true);
+ hashNavigate(`/notes/${note.id}/conflict`, { replace: true });
} else if (note.locked) {
- hashNavigate(`/notes/${note.id}/unlock`, true);
+ hashNavigate(`/notes/${note.id}/unlock`, { replace: true });
} else {
- hashNavigate(`/notes/${note.id}/edit`, true);
+ hashNavigate(`/notes/${note.id}/edit`, { replace: true });
}
}}
header={
diff --git a/apps/web/src/components/placeholders/notesplacholder.js b/apps/web/src/components/placeholders/notesplacholder.js
index 407d53302..f543a0d8a 100644
--- a/apps/web/src/components/placeholders/notesplacholder.js
+++ b/apps/web/src/components/placeholders/notesplacholder.js
@@ -13,7 +13,8 @@ function NotesPlaceholder() {
callToAction={{
text: "Make your first note",
icon: Icon.Plus,
- onClick: () => hashNavigate("/notes/create"),
+ onClick: () =>
+ hashNavigate("/notes/create", { replace: true, addNonce: true }),
}}
/>
);
diff --git a/apps/web/src/components/spliteditor/index.js b/apps/web/src/components/spliteditor/index.js
index dc23ba96c..774ec465b 100644
--- a/apps/web/src/components/spliteditor/index.js
+++ b/apps/web/src/components/spliteditor/index.js
@@ -52,7 +52,7 @@ function SplitEditor(props) {
});
}
notesStore.refresh();
- hashNavigate(`/notes/${note.id}/edit`, true);
+ hashNavigate(`/notes/${note.id}/edit`, { replace: true });
const conflictsCount = db.notes.conflicted?.length;
if (conflictsCount) {
@@ -73,7 +73,7 @@ function SplitEditor(props) {
await db.notes.init();
let note = db.notes.note(noteId);
if (!note) {
- hashNavigate(`/notes/create`, true);
+ hashNavigate(`/notes/create`, { replace: true });
return;
}
notesStore.setSelectedNote(noteId);
diff --git a/apps/web/src/navigation/hash-routes.js b/apps/web/src/navigation/hash-routes.js
index aef69321b..8b0c59565 100644
--- a/apps/web/src/navigation/hash-routes.js
+++ b/apps/web/src/navigation/hash-routes.js
@@ -47,15 +47,16 @@ const hashroutes = {
showEditTopicDialog(notebookId, topicId);
},
"/notes/create": () => {
- //editorStore.get().newSession(noteStore.get().context);
+ hashNavigate("/notes/create", { addNonce: true, replace: true });
+ },
+ "/notes/create/:nonce": ({ nonce }) => {
return (
<Suspense fallback={<EditorLoading />}>
- <Editor noteId={0} />
+ <Editor noteId={0} nonce={nonce} />
</Suspense>
);
},
"/notes/:noteId/edit": ({ noteId }) => {
- // editorStore.openSession(noteId);
return (
<Suspense fallback={<EditorLoading text="Opening note..." />}>
<Editor noteId={noteId} />
@@ -69,7 +70,11 @@ const hashroutes = {
back: isMobile()
? {
title: "Go back",
- action: () => hashNavigate("/notes/create"),
+ action: () =>
+ hashNavigate("/notes/create", {
+ addNonce: true,
+ replace: true,
+ }),
}
: undefined,
}}
diff --git a/apps/web/src/navigation/index.js b/apps/web/src/navigation/index.js
index 01ea78f43..2d72ce1bc 100644
--- a/apps/web/src/navigation/index.js
+++ b/apps/web/src/navigation/index.js
@@ -23,8 +23,13 @@ export function navigate(url, replaceOrQuery, replace) {
window.history[`${replace ? "replace" : "push"}State`](null, null, url);
dispatchEvent(new PopStateEvent("popstate", null));
}
+let last = 0;
+export function hashNavigate(
+ url,
+ { replace = false, notify = true, addNonce = false } = {}
+) {
+ if (addNonce) url += `/${++last}`;
-export function hashNavigate(url, replace, notify = true) {
window.history[`${replace ? "replace" : "push"}State`](null, null, `#${url}`);
if (notify) dispatchEvent(new HashChangeEvent("hashchange"));
// if (typeof url !== "string") {
diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.js
index 85bb200d5..5cd27558e 100644
--- a/apps/web/src/stores/editor-store.js
+++ b/apps/web/src/stores/editor-store.js
@@ -53,7 +53,7 @@ class EditorStore extends BaseStore {
};
});
appStore.setIsEditorOpen(true);
- hashNavigate(`/notes/${note.id}/edit`, true);
+ hashNavigate(`/notes/${note.id}/edit`, { replace: true });
};
openSession = async (noteId) => {
@@ -77,8 +77,10 @@ class EditorStore extends BaseStore {
noteStore.setSelectedNote(note.id);
- if (note.locked) return hashNavigate(`/notes/${noteId}/unlock`, true);
- if (note.conflicted) return hashNavigate(`/notes/${noteId}/conflict`, true);
+ if (note.locked)
+ return hashNavigate(`/notes/${noteId}/unlock`, { replace: true });
+ if (note.conflicted)
+ return hashNavigate(`/notes/${noteId}/conflict`, { replace: true });
let content = await db.content.raw(note.contentId);
@@ -98,16 +100,14 @@ class EditorStore extends BaseStore {
const session = this.get().session;
if (session.isSaving) return; // avoid multiple in-queue saves; only save one time.
this.set((state) => (state.session.isSaving = true));
-
this._saveFn()(session).then(async (id) => {
- const note = db.notes.note(id)?.data;
+ let note = db.notes.note(id)?.data;
if (!note) {
noteStore.refresh();
return;
}
/* eslint-disable */
storeSync: {
- const session = this.get().session;
if (oldSession?.tags?.length !== session.tags.length)
tagStore.refresh();
@@ -119,6 +119,9 @@ class EditorStore extends BaseStore {
if (type === "topic") await db.notes.move(value, id);
else if (type === "color") await db.notes.note(id).color(value);
else if (type === "tag") await db.notes.note(id).tag(value);
+
+ // update the note.
+ note = db.notes.note(id)?.data;
}
/* eslint-enable */
@@ -127,28 +130,28 @@ class EditorStore extends BaseStore {
}
this.set((state) => {
- state.session.id = id;
+ state.session.id = note.id;
state.session.title = note.title;
state.session.isSaving = false;
state.session.color = note.color;
state.session.tags = note.tags;
+ state.session.notebooks = note.notebooks;
});
noteStore.refresh();
if (!oldSession?.id) {
- hashNavigate(`/notes/${id}/edit`, true, true);
+ hashNavigate(`/notes/${id}/edit`, { replace: true });
}
});
};
- newSession = (context) => {
- if (!context) {
- context = noteStore.get().context;
- }
+ newSession = (nonce) => {
+ let context = noteStore.get().context;
this.set((state) => {
state.session = {
...DEFAULT_SESSION,
context,
+ nonce,
state: SESSION_STATES.new,
};
});
@@ -166,7 +169,7 @@ class EditorStore extends BaseStore {
});
noteStore.setSelectedNote(0);
this.toggleProperties(false);
- if (shouldNavigate) hashNavigate(`/`, true);
+ if (shouldNavigate) hashNavigate(`/`, { replace: true });
};
setSession = (set) => {
diff --git a/apps/web/src/views/home.js b/apps/web/src/views/home.js
index 5ab858db7..83d4c3bd7 100644
--- a/apps/web/src/views/home.js
+++ b/apps/web/src/views/home.js
@@ -44,7 +44,8 @@ function Home() {
placeholder={NotesPlaceholder}
button={{
content: "Make a new note",
- onClick: () => hashNavigate("/notes/create", true),
+ onClick: () =>
+ hashNavigate("/notes/create", { replace: true, addNonce: true }),
}}
/>
);
diff --git a/apps/web/src/views/notes.js b/apps/web/src/views/notes.js
index 1f4bd2c60..a15646291 100644
--- a/apps/web/src/views/notes.js
+++ b/apps/web/src/views/notes.js
@@ -18,7 +18,8 @@ function Notes() {
}
button={{
content: "Make a new note",
- onClick: () => hashNavigate("/notes/create", true),
+ onClick: () =>
+ hashNavigate("/notes/create", { addNonce: true, replace: true }),
}}
/>
);