Skip to content

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

fix: clear session & new session conflict

thecodrra09033ec54d9
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.js
index cb42108a7..30b65109c 100644
--- a/apps/web/src/components/editor/index.js
+++ b/apps/web/src/components/editor/index.js
@@ -43,6 +43,7 @@ function Editor({ noteId, nonce }) {
const editorRef = useRef();
const [isEditorLoading, setIsEditorLoading] = useState(true);
const sessionId = useStore((store) => store.session.id);
+ const contentId = useStore((store) => store.session.contentId);
const contentType = useStore((store) => store.session.content?.type);
const saveSession = useStore((store) => store.saveSession);
const newSession = useStore((store) => store.newSession);
@@ -93,19 +94,30 @@ function Editor({ noteId, nonce }) {
editor.clearContent();
}, []);
- useEffect(() => {
- if (!sessionId || !editorstore.get().session.contentId) {
- clearContent();
- return;
- }
- setContent();
- }, [sessionId, setContent, clearContent]);
+ useEffect(
+ function clearSession() {
+ // clearSession makes sessionId && contentId both undefined
+ if (!sessionId && !contentId) clearContent();
+ },
+ [sessionId, contentId, clearContent]
+ );
- useEffect(() => {
- if (!nonce) return;
+ useEffect(
+ function openSesion() {
+ if (!contentId) return;
+ setContent();
+ },
+ [sessionId, contentId, setContent, clearContent]
+ );
+
+ useEffect(
+ function newSession() {
+ if (!nonce) return;
- clearContent();
- }, [nonce, clearContent]);
+ clearContent();
+ },
+ [nonce, clearContent]
+ );
useEffect(() => {
(async () => {
diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.js
index 5bcaa7fef..2dc8230b4 100644
--- a/apps/web/src/stores/editor-store.js
+++ b/apps/web/src/stores/editor-store.js
@@ -21,7 +21,7 @@ const getDefaultSession = () => {
state: undefined,
isSaving: false,
title: "",
- id: "",
+ id: undefined,
pinned: false,
favorite: false,
locked: false,