Skip to content

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

fix: auto delete empty note (#148)

thecodrrf517dfdf1d1d
diff --git a/apps/web/package.json b/apps/web/package.json
index 4cba31503..99ea34974 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -66,4 +66,4 @@
"last 4 edge version"
]
}
-}
\ No newline at end of file
+}
diff --git a/apps/web/src/app.js b/apps/web/src/app.js
index 5fc82e5dd..5e58cc8a9 100644
--- a/apps/web/src/app.js
+++ b/apps/web/src/app.js
@@ -4,27 +4,30 @@ import { Flex, Box } from "rebass";
import ThemeProvider from "./components/theme-provider";
import { usePersistentState } from "./utils/hooks";
import { useStore } from "./stores/app-store";
-import { useStore as useAppStore } from "./stores/app-store";
import { useStore as useEditorStore } from "./stores/editor-store";
import { useStore as useUserStore } from "./stores/user-store";
+import { useStore as useNotesStore } from "./stores/note-store";
import Animated from "./components/animated";
import NavigationMenu from "./components/navigationmenu";
import NavigationContainer from "./navigation/container";
import RootNavigator from "./navigation/navigators/rootnavigator";
import EditorNavigator from "./navigation/navigators/editornavigator";
import { isMobile } from "./utils/dimensions";
+import { db } from "./common";
function App() {
const [show, setShow] = usePersistentState("isContainerVisible", true);
const refreshColors = useStore((store) => store.refreshColors);
- const isFocusMode = useAppStore((store) => store.isFocusMode);
+ const isFocusMode = useStore((store) => store.isFocusMode);
const initUser = useUserStore((store) => store.init);
+ const initNotes = useNotesStore((store) => store.init);
const openLastSession = useEditorStore((store) => store.openLastSession);
useEffect(() => {
refreshColors();
initUser();
- }, [refreshColors, initUser]);
+ initNotes();
+ }, [refreshColors, initUser, initNotes]);
useEffect(() => {
if (isFocusMode) {
@@ -47,6 +50,12 @@ function App() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
+ useEffect(() => {
+ return () => {
+ db.ev.unsubscribeAll();
+ };
+ }, []);
+
return (
<ThemeProvider>
<Flex id="app" bg="background" height="100%">
diff --git a/apps/web/src/components/editor/header.js b/apps/web/src/components/editor/header.js
index 46d7fd7b9..ed5ef9943 100644
--- a/apps/web/src/components/editor/header.js
+++ b/apps/web/src/components/editor/header.js
@@ -64,9 +64,8 @@ function Header() {
sx={{
display: "flex",
alignItems: "center",
- marginTop: dateEdited || text.length || id.length ? 0 : [0, 2, 2],
- marginBottom:
- dateEdited || text.length || id.length ? [1, 2, 2] : 0,
+ marginTop: dateEdited || text?.length || id ? 0 : [0, 2, 2],
+ marginBottom: dateEdited || text?.length || id ? [1, 2, 2] : 0,
}}
>
{dateEdited > 0 ? (
@@ -81,7 +80,7 @@ function Header() {
<TextSeperator />
</>
) : null}
- {id && id.length > 0 ? <>{isSaving ? "Saving" : "Saved"}</> : null}
+ {id ? <>{isSaving ? "Saving" : "Saved"}</> : null}
</Text>
</Flex>
<Flex
diff --git a/apps/web/src/components/editor/modules/markdown/index.js b/apps/web/src/components/editor/modules/markdown/index.js
index 5711664bc..be2cd5eaa 100644
--- a/apps/web/src/components/editor/modules/markdown/index.js
+++ b/apps/web/src/components/editor/modules/markdown/index.js
@@ -286,7 +286,7 @@ class MarkdownShortcuts {
if (!selection) return;
const [line, offset] = this.quill.getLine(selection.index);
const lineStart = selection.index - offset;
- const rawText = this.quill.getText(lineStart, selection.index - lineStart);
+ //const rawText = this.quill.getText(lineStart, selection.index - lineStart);
// formulas count as a single character for insertion/deletion
// purposes, yet they don't show up the output of getText.
diff --git a/apps/web/src/stores/note-store.js b/apps/web/src/stores/note-store.js
index a78cff915..f64651c0e 100644
--- a/apps/web/src/stores/note-store.js
+++ b/apps/web/src/stores/note-store.js
@@ -13,6 +13,15 @@ class NoteStore extends BaseStore {
context = undefined;
selectedNote = 0;
+ init = () => {
+ db.ev.subscribe("notes:removeEmptyNote", (id) => {
+ const { session, newSession } = editorStore.get();
+ if (session.id === id) {
+ newSession();
+ }
+ });
+ };
+
setSelectedNote = (id) => {
this.set((state) => (state.selectedNote = id));
};
diff --git a/apps/web/yarn.lock b/apps/web/yarn.lock
index 6817fcf4c..53d67d078 100644
--- a/apps/web/yarn.lock
+++ b/apps/web/yarn.lock
@@ -7319,7 +7319,7 @@ normalize-url@^3.0.0, normalize-url@^3.0.1:
"notes-core@git+ssh://[email protected]:streetwriters/notesnook-core.git":
version "1.5.0"
- resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#9e4abf6e98d98183bada040f9279989959f1bd14"
+ resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#85b016c0756aaeeab9487de9068027edd40a075d"
dependencies:
crypto-random-string "^3.2.0"
event-source-polyfill "^1.0.16"