mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-24 04:00:59 +01:00
web: only load new media attachments on realtime sync
This commit is contained in:
committed by
Abdullah Atta
parent
b354a26f0a
commit
c0a2dd139a
@@ -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);
|
||||
|
||||
@@ -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.current
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user