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: only load new media attachments on realtime sync
Abdullah Attac0a2dd139aa6
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsxindex 1d4ae33cb..15691897e 100644--- a/apps/web/src/components/editor/index.tsx+++ b/apps/web/src/components/editor/index.tsx@@ -110,25 +110,31 @@ export default function EditorManager({const isContent = item.type === "tiptap" && item.id === contentId;const isNote = item.type === "note" && item.id === id;- if (isContent) {+ if (isContent && editorInstance.current) {if (locked) {const result = await db.vault?.decryptContent(item).catch(() => {});if (result) item.data = result.data;else EV.publish(EVENTS.vaultLocked);}+ const oldHashes = editorInstance.current.getMediaHashes();- editorInstance.current?.updateContent(item.data as string);+ editorInstance.current.updateContent(item.data as string);++ const newHashes = editorInstance.current.getMediaHashes();+ const hashesToLoad = newHashes.filter(+ (hash, index) => hash !== oldHashes[index]+ );if (appstore.get().isSyncing()) {db.eventManager.subscribe(EVENTS.syncCompleted,async () => {- await db.attachments?.downloadMedia(id);+ await db.attachments?.downloadMedia(id, hashesToLoad);},true);} else {- await db.attachments?.downloadMedia(id);+ await db.attachments?.downloadMedia(id, hashesToLoad);}} else if (isNote) {if (!locked && item.locked) return EV.publish(EVENTS.vaultLocked);diff --git a/apps/web/src/components/editor/tiptap.tsx b/apps/web/src/components/editor/tiptap.tsxindex f9b64f42b..26dfd443c 100644--- a/apps/web/src/components/editor/tiptap.tsx+++ b/apps/web/src/components/editor/tiptap.tsx@@ -373,6 +373,14 @@ function toIEditor(editor: Editor): IEditor {focus: () => editor.current?.commands.focus("start"),undo: () => editor.current?.commands.undo(),redo: () => editor.current?.commands.redo(),+ getMediaHashes: () => {+ if (!editor.current) return [];+ const hashes: string[] = [];+ editor.current.state.doc.descendants((n) => {+ if (typeof n.attrs.hash === "string") hashes.push(n.attrs.hash);+ });+ return hashes;+ },updateContent: (content) => {const { from, to } = editor.state.selection;editor.currentdiff --git a/apps/web/src/components/editor/types.ts b/apps/web/src/components/editor/types.tsindex f284c478d..f87c8f815 100644--- a/apps/web/src/components/editor/types.ts+++ b/apps/web/src/components/editor/types.ts@@ -30,6 +30,7 @@ export interface IEditor {focus: () => void;undo: () => void;redo: () => void;+ getMediaHashes: () => string[];updateContent: (content: string) => void;attachFile: (file: Attachment) => void;loadWebClip: (hash: string, html: string) => void;