Skip to content

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

fix: editor is not clearing on pressing new note btn

thecodrr6d9b817af81b
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.js
index c989f11ea..dd7492a58 100644
--- a/apps/web/src/components/editor/index.js
+++ b/apps/web/src/components/editor/index.js
@@ -23,6 +23,7 @@ const ReactQuill = React.lazy(() => import("./react-quill"));
function Editor(props) {
const sessionState = useStore((store) => store.session.state);
+ const sessionId = useStore((store) => store.session.id);
const contentType = useStore((store) => store.session.content?.type);
const setSession = useStore((store) => store.setSession);
const saveSession = useStore((store) => store.saveSession);
@@ -60,7 +61,7 @@ function Editor(props) {
useEffect(() => {
if (contentType !== "delta" || !quillRef || !quillRef.current) return;
-
+ console.log("session", sessionState);
if (sessionState === SESSION_STATES.new) {
editorstore.set((state) => (state.session.state = SESSION_STATES.stale));
const {
@@ -85,7 +86,7 @@ function Editor(props) {
const text = quill.getText();
quill.setSelection(text.length, 0, "init");
}
- }, [sessionState, quillRef, contentType]);
+ }, [sessionState, quillRef, contentType, sessionId]);
return (
<Flex
diff --git a/apps/web/src/components/editor/toolbar.js b/apps/web/src/components/editor/toolbar.js
index 5a06caecd..b027fe8ce 100644
--- a/apps/web/src/components/editor/toolbar.js
+++ b/apps/web/src/components/editor/toolbar.js
@@ -2,7 +2,7 @@ import React, { useEffect, useMemo, useState } from "react";
import { Button, Flex, Text } from "rebass";
import * as Icon from "../icons";
import { useStore as useAppStore } from "../../stores/app-store";
-import { useStore } from "../../stores/editor-store";
+import { useStore, store } from "../../stores/editor-store";
import { showToast } from "../../utils/toast";
import { EventManagers } from "../../utils/observablearray";
import Animated from "../animated";
@@ -11,7 +11,6 @@ function Toolbar(props) {
console.log("TOOLBACR");
const { quill } = props;
const sessionState = useStore((store) => store.session.state);
- const sessionId = useStore((store) => store.session.sessionId);
const [undoable, setUndoable] = useState(false);
const [redoable, setRedoable] = useState(false);
const isFocusMode = useAppStore((store) => store.isFocusMode);
@@ -93,7 +92,7 @@ function Toolbar(props) {
}}
size={18}
onClick={() => {
- if (sessionId) showToast("success", "Note saved!");
+ if (store.get().session.id) showToast("success", "Note saved!");
clearSession();
}}
/>
diff --git a/apps/web/src/navigation/hash-routes.js b/apps/web/src/navigation/hash-routes.js
index a908fa04d..d18320604 100644
--- a/apps/web/src/navigation/hash-routes.js
+++ b/apps/web/src/navigation/hash-routes.js
@@ -29,6 +29,10 @@ const hashroutes = {
"/notebooks/:notebookId/edit": ({ notebookId }) => {
showEditNotebookDialog(notebookId);
},
+ "/notes/create": () => {
+ console.log("session");
+ editorStore.get().newSession(noteStore.get().context);
+ },
"/notes/:noteId/edit": ({ noteId }) => {
editorStore.openSession(noteId);
},
@@ -43,9 +47,6 @@ const hashroutes = {
"/notes/:noteId/conflict": ({ noteId }) => {
return <SplitEditor noteId={noteId} />;
},
- "/notes/create": () => {
- editorStore.newSession(noteStore.get().context);
- },
"/signup": () => {
showSignUpDialog();
},
diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.js
index 6e4346484..dca2d22ec 100644
--- a/apps/web/src/stores/editor-store.js
+++ b/apps/web/src/stores/editor-store.js
@@ -124,12 +124,16 @@ class EditorStore extends BaseStore {
});
noteStore.refresh();
+ if (!oldSession?.id) {
+ hashNavigate(`/notes/${id}/edit`, true, true);
+ }
});
};
newSession = (context = {}) => {
+ console.log("Session");
appStore.setIsEditorOpen(true);
- this.set(function (state) {
+ this.set((state) => {
state.session = {
...DEFAULT_SESSION,
context,
diff --git a/apps/web/src/utils/use-hash-routes.js b/apps/web/src/utils/use-hash-routes.js
index 718d1357f..e0f6ae696 100644
--- a/apps/web/src/utils/use-hash-routes.js
+++ b/apps/web/src/utils/use-hash-routes.js
@@ -4,7 +4,7 @@ import useHashLocation from "./use-hash-location";
export default function useHashRoutes(routes) {
const [location] = useHashLocation();
const matcher = makeMatcher();
-
+ console.log("Location", location);
for (var key in routes) {
const [match, params] = matcher(key, location);
console.log("isMatch:", match, key, location);