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: migrate from delta -> content
thecodrrc39812ae31e4
diff --git a/apps/web/src/common/height-calculator.js b/apps/web/src/common/height-calculator.jsindex 1249ebdce..7a86367e6 100644--- a/apps/web/src/common/height-calculator.js+++ b/apps/web/src/common/height-calculator.js@@ -11,8 +11,8 @@ function getNoteHeight(item) {const { title, headline } = item;let height = SINGLE_LINE_HEIGHT * 3;if (title.length > 30) height += SINGLE_LINE_HEIGHT;- if (headline.length > 0) height += SINGLE_LINE_HEIGHT;- if (headline.length > 40) height += SINGLE_LINE_HEIGHT;+ if (headline?.length > 0) height += SINGLE_LINE_HEIGHT;+ if (headline?.length > 40) height += SINGLE_LINE_HEIGHT;return height * DEFAULT_FONT_SIZE;}diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.jsindex cb626cd86..caa9984cb 100644--- a/apps/web/src/components/editor/index.js+++ b/apps/web/src/components/editor/index.js@@ -22,6 +22,7 @@ import { SUBSCRIPTION_STATUS } from "../../common";function Editor() {const sessionState = useStore((store) => store.session.state);+ const contentType = useStore((store) => store.session.content?.type);const setSession = useStore((store) => store.setSession);const saveSession = useStore((store) => store.saveSession);const toggleProperties = useStore((store) => store.toggleProperties);@@ -39,35 +40,36 @@ function Editor() {const [unlock] = useHashParam("unlock");useEffect(() => {+ if (contentType !== "delta") return;// move the toolbar outside (easiest way)const toolbar = document.querySelector(".ql-toolbar.ql-snow");const toolbarContainer = document.querySelector("#toolbar");if (toolbar && toolbarContainer) {toolbarContainer.appendChild(toolbar);}- }, []);+ }, [contentType]);useEffect(() => {init();}, [init]);useEffect(() => {- if (!quillRef || !quillRef.current) return;+ if (contentType !== "delta" || !quillRef || !quillRef.current) return;if (sessionState === SESSION_STATES.new) {editorstore.set((state) => (state.session.state = SESSION_STATES.stale));const {- content: { delta },+ content: { data },} = editorstore.get().session;const { quill } = quillRef.current;- quill.setContents(delta, "init");+ quill.setContents(data, "init");quill.history.clear();- if (!delta.ops || !delta.ops.length) return;+ if (!data || !data.length) return;const text = quill.getText();quill.setSelection(text.length, 0, "init");}- }, [sessionState, quillRef]);+ }, [sessionState, quillRef, contentType]);if (unlock)return (@@ -95,34 +97,35 @@ function Editor() {<Flex variant="columnFill" className="editor"><Header /><Flex id="toolbar" />- <EditorMenu quill={quillRef.current && quillRef.current.quill} />- <ReactQuill- id="quill"- ref={quillRef}- refresh={sessionState === SESSION_STATES.new}- isSimple={!isLoggedin || (isLoggedin && !isTrial)}- onFocus={() => {- toggleProperties(false);- }}- placeholder="Type anything here"- container=".editor"- onSave={() => {- saveSession();- }}- changeInterval={500}- onWordCountChanged={updateWordCount}- onChange={() => {- const { quill } = quillRef.current;- const delta = quill.getContents().ops;- const text = quill.getText();- setSession((state) => {- state.session.content = {- delta: { ops: delta },- text: text,- };- });- }}- />+ <EditorMenu quill={quillRef.current?.quill} />+ {contentType === "delta" && (+ <ReactQuill+ id="quill"+ ref={quillRef}+ refresh={sessionState === SESSION_STATES.new}+ isSimple={!isLoggedin || (isLoggedin && !isTrial)}+ onFocus={() => {+ toggleProperties(false);+ }}+ placeholder="Type anything here"+ container=".editor"+ onSave={() => {+ saveSession();+ }}+ changeInterval={500}+ onWordCountChanged={updateWordCount}+ onChange={() => {+ const { quill } = quillRef.current;+ const delta = quill.getContents().ops;+ setSession((state) => {+ state.session.content = {+ type: "delta",+ data: delta,+ };+ });+ }}+ />+ )}</Flex><Properties /></Animated.Flex>diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.jsindex 4be36059b..71ed131a8 100644--- a/apps/web/src/stores/editor-store.js+++ b/apps/web/src/stores/editor-store.js@@ -23,10 +23,8 @@ const DEFAULT_SESSION = {dateEdited: 0,totalWords: 0,content: {- text: "",- delta: {- ops: [],- },+ type: "delta",+ data: [],},};class EditorStore extends BaseStore {@@ -82,17 +80,13 @@ class EditorStore extends BaseStore {saveLastOpenedNote(note.id);- let content = {};- content = {- text: await db.notes.note(note).text(),- delta: await db.notes.note(note).delta(),- };+ let content = await db.content.raw(note.contentId);this.set((state) => {state.session = {...DEFAULT_SESSION,...note,- content,+ content: content || DEFAULT_SESSION.content,state: SESSION_STATES.new,};});