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
feat: improve note opening performance
thecodrr02157422b53c
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.jsindex 32f440ded..065189a23 100644--- a/apps/web/src/components/editor/index.js+++ b/apps/web/src/components/editor/index.js@@ -13,17 +13,18 @@ import { useHashParam } from "../../utils/useHashParam";import SplitEditor from "../spliteditor";function Editor() {+ console.log("RERENDERING EDITOR");const delta = useStore((store) => store.session.content.delta);const sessionState = useStore((store) => store.session.state);const setSession = useStore((store) => store.setSession);const saveSession = useStore((store) => store.saveSession);- const openSession = useStore((store) => store.openSession);+ const init = useStore((store) => store.init);+ //const openSession = useStore((store) => store.openSession);const isFocusMode = useAppStore((store) => store.isFocusMode);const isTrial = useUserStore((store) => store.user.notesnook?.subscription?.isTrial);const quillRef = useRef();- const [noteId] = useHashParam("note");const [diff] = useHashParam("diff");useEffect(() => {@@ -36,9 +37,19 @@ function Editor() {}, []);useEffect(() => {- if (!noteId) return;- (async () => await openSession(noteId))();- }, [openSession, noteId]);+ init();+ }, [init]);++ useEffect(() => {+ if (sessionState === SESSION_STATES.new) {+ const { quill } = quillRef.current;+ quill.setContents(delta, "init");+ quill.history.clear();+ if (!delta.ops || !delta.ops.length) return;+ const text = quill.getText();+ quill.setSelection(text.length, 0, "init");+ }+ }, [sessionState, delta]);if (diff) return <SplitEditor diffId={diff} />;return (diff --git a/apps/web/src/components/editor/react-quill.js b/apps/web/src/components/editor/react-quill.jsindex 7dfcf4116..792eaf02f 100644--- a/apps/web/src/components/editor/react-quill.js+++ b/apps/web/src/components/editor/react-quill.js@@ -60,22 +60,10 @@ export default class ReactQuill extends Component {shouldComponentUpdate(nextProps) {return (this.props.readOnly !== nextProps.readOnly ||- nextProps.refresh ||this.props.isSimple !== nextProps.isSimple);}- componentDidUpdate() {- const { initialContent, refresh } = this.props;- if (refresh) {- this.quill.setContents(initialContent);- this.quill.history.clear();- if (!initialContent.ops || !initialContent.ops.length) return;- const text = this.quill.getText();- this.quill.setSelection(text.length, 0);- }- }-componentDidMount() {const {placeholder,@@ -121,10 +109,12 @@ export default class ReactQuill extends Component {}textChangeHandler = (delta, oldDelta, source) => {+ if (source === "init") return;this.props.onChange(this.quill);};render() {+ console.log("RERENDERING QUILL");return <pre id={this.props.id} />;}}diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.jsindex ba7cbc14a..a1ab18d1d 100644--- a/apps/web/src/stores/editor-store.js+++ b/apps/web/src/stores/editor-store.js@@ -5,7 +5,7 @@ import { store as tagStore } from "./tag-store";import { db } from "../common";import BaseStore from ".";import { isMobile } from "../utils/dimensions";-import { setHashParam } from "../utils/useHashParam";+import { getHashParam, setHashParam } from "../utils/useHashParam";const SESSION_STATES = { stale: "stale", new: "new" };const DEFAULT_SESSION = {@@ -33,6 +33,13 @@ class EditorStore extends BaseStore {session = DEFAULT_SESSION;arePropertiesVisible = false;+ init = () => {+ window.addEventListener("hashchange", async () => {+ const note = getHashParam("note");+ if (note) await this.openSession(note);+ });+ };+openLastSession = async () => {// Do not reopen last session on mobileif (isMobile()) return;diff --git a/apps/web/src/utils/useHashParam.js b/apps/web/src/utils/useHashParam.jsindex 1e80441a2..1ed5fc339 100644--- a/apps/web/src/utils/useHashParam.js+++ b/apps/web/src/utils/useHashParam.js@@ -44,4 +44,4 @@ const useHashParam = (key, defaultValue) => {return [innerValue || defaultValue];};-export { setHashParam, useHashParam };+export { setHashParam, useHashParam, getHashParam };