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
web: refresh sessions instead of raising event on spellcheck toggle Signed-off-by: 01zulfi <[email protected]>
01zulfi257ac8962c60
diff --git a/apps/web/src/common/app-events.ts b/apps/web/src/common/app-events.tsindex ce157d9bc..ff04b29c8 100644--- a/apps/web/src/common/app-events.ts+++ b/apps/web/src/common/app-events.ts@@ -45,5 +45,6 @@ export const AppEvents = {onOpenLink: "onOpenLink",onCreateItem: "onCreateItem",- spellcheckUpdated: "spellcheck:updated"+ spellcheckUpdated: "spellcheck:updated",+ toggleEditor: "app:toggleEditor"};diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsxindex 2b2a78478..0763f6f6a 100644--- a/apps/web/src/components/editor/index.tsx+++ b/apps/web/src/components/editor/index.tsx@@ -360,7 +360,7 @@ function EditorView({<div className="dialogContainer" /><Editorid={session.id}- nonce={1}+ nonce={session.nonce}content={getContent}session={session}onPreviewDocument={(preview) =>diff --git a/apps/web/src/components/editor/tiptap.tsx b/apps/web/src/components/editor/tiptap.tsxindex 5db4814b0..e2eabc34e 100644--- a/apps/web/src/components/editor/tiptap.tsx+++ b/apps/web/src/components/editor/tiptap.tsx@@ -666,24 +666,10 @@ function TiptapWrapper(}, [editorConfig.zoom]);useEffect(() => {- const { unsubscribe } = AppEventManager.subscribe(- AppEvents.spellcheckUpdated,- ({ noteIds, spellcheck }) => {- const session = useEditorStore.getState().getSession(props.id);- if (- session &&- "note" in session &&- noteIds.includes(session.note.id) &&- editorContainerRef.current- ) {- editorContainerRef.current.spellcheck = spellcheck;- }- }- );- return () => {- unsubscribe();- };- }, []);+ if (editorContainerRef.current) {+ editorContainerRef.current.spellcheck = props.spellcheck === true;+ }+ }, [props.spellcheck]);return (<Flexdiff --git a/apps/web/src/components/editor/title-box.tsx b/apps/web/src/components/editor/title-box.tsxindex f8f376e75..004460f77 100644--- a/apps/web/src/components/editor/title-box.tsx+++ b/apps/web/src/components/editor/title-box.tsx@@ -95,30 +95,8 @@ function TitleBox(props: TitleBoxProps) {});- const { unsubscribe: unsubscribeSpellcheckUpdatedEvent } =- AppEventManager.subscribe(- AppEvents.spellcheckUpdated,- ({ noteIds, spellcheck }) => {- const sessions = useEditorStore.getState().sessions;- const sessionsToUpdate: string[] = [];- for (const session of sessions) {- if ("note" in session && noteIds.includes(session.note.id)) {- sessionsToUpdate.push(session.id);- }- }- for (const sessionId of sessionsToUpdate) {- const sessionTitleBox = document.querySelector(- `#editor-title[data-session-id="${sessionId}"]`- ) as HTMLTextAreaElement;- if (!sessionTitleBox) continue;- sessionTitleBox.spellcheck = spellcheck;- }- }- );-return () => {unsubscribe();- unsubscribeSpellcheckUpdatedEvent();};}, [id]);diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.tsindex f6f64f3ab..8fc89cf5a 100644--- a/apps/web/src/stores/editor-store.ts+++ b/apps/web/src/stores/editor-store.ts@@ -1335,6 +1335,20 @@ class EditorStore extends BaseStore<EditorStore> {sessionId = sessionId || tab?.sessionId;if (sessionId) this.rehydrateSession(sessionId);};++ refreshSessionWithNoteIds = (noteIds: string[]) => {+ this.set((state) => {+ state.sessions = state.sessions.map((session) => {+ if ("note" in session && noteIds.includes(session.note.id)) {+ return {+ ...session,+ nonce: (session.nonce || 0) + 1+ };+ }+ return session;+ });+ });+ };}const useEditorStore = createPersistedStore(EditorStore, {diff --git a/apps/web/src/stores/note-store.ts b/apps/web/src/stores/note-store.tsindex 7e44114d8..63d1caf22 100644--- a/apps/web/src/stores/note-store.ts+++ b/apps/web/src/stores/note-store.ts@@ -26,7 +26,7 @@ import BaseStore from ".";import Config from "../utils/config";import { Note, VirtualizedGrouping } from "@notesnook/core";import { Context } from "../components/list-container/types";-import { AppEventManager, AppEvents } from "../common/app-events";+import { useEditorStore } from "./editor-store";type ViewMode = "detailed" | "compact";class NoteStore extends BaseStore<NoteStore> {@@ -98,11 +98,7 @@ class NoteStore extends BaseStore<NoteStore> {spellcheck = async (state: boolean, ...ids: string[]) => {await db.notes.spellcheck(state, ...ids);await this.refresh();-- AppEventManager.publish(AppEvents.spellcheckUpdated, {- noteIds: ids,- spellcheck: state- });+ useEditorStore.getState().refreshSessionWithNoteIds(ids);};unlock = async (id: string) => {