Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

Merge pull request #8562 from streetwriters/fix/refresh-note-on-attachment-delete

Abdullah Atta3a3434b021af
diff --cc apps/web/src/components/editor/index.tsx
index 5ece61a97,72b9b0ae8..385a43308
--- a/apps/web/src/components/editor/index.tsx
+++ b/apps/web/src/components/editor/index.tsx
@@@ -242,19 -242,10 +242,20 @@@ const MemoizedEditorView = React.memo(E
prev.session.type === next.session.type &&
prev.session.needsHydration === next.session.needsHydration &&
prev.session.activeBlockId === next.session.activeBlockId &&
- prev.session.activeSearchResultId === next.session.activeSearchResultId;
- prev.session.activeSearchResultIndex ===
- next.session.activeSearchResultIndex &&
- prev.session.nonce === next.session.nonce
- );
++ prev.session.activeSearchResultId === next.session.activeSearchResultId &&
++ prev.session.nonce === next.session.nonce;
+
+ if (
+ "attachmentsLength" in prev.session &&
+ "attachmentsLength" in next.session
+ ) {
+ return (
+ baseConditions &&
+ prev.session.attachmentsLength === next.session.attachmentsLength
+ );
+ }
+
+ return baseConditions;
});
function EditorView({
session
diff --cc apps/web/src/stores/attachment-store.ts
index 0b14710fb,0da34a3cd..91fbdad54
--- a/apps/web/src/stores/attachment-store.ts
+++ b/apps/web/src/stores/attachment-store.ts
@@@ -135,23 -135,11 +135,24 @@@ class AttachmentStore extends BaseStore
if (await db.attachments.remove(attachment.hash, false)) {
await this.get().refresh();
await useNoteStore.getState().refresh();
- for (const noteId of linkedNotes) {
- await useEditorStore.getState().openSession(noteId, {
+
+ const sessions = useEditorStore.getState().sessions;
+ for (const session of sessions) {
+ if (
+ !("note" in session) ||
+ !session.note.id ||
+ !session.note.contentId
+ ) {
+ continue;
+ }
+ if (!linkedNotes.includes(session.note.id)) {
+ continue;
+ }
+
- useEditorStore
- .getState()
- .openSession(session.note.id, { force: true });
++ useEditorStore.getState().openSession(session.note.id, {
+ force: true,
- silent: useEditorStore.getState().getActiveNote()?.id !== noteId
++ silent: true
+ });
}
}
} catch (e) {
diff --cc apps/web/src/stores/editor-store.ts
index 6993877fb,bd49050b5..5331a268c
--- a/apps/web/src/stores/editor-store.ts
+++ b/apps/web/src/stores/editor-store.ts
@@@ -85,9 -85,13 +85,13 @@@ export type BaseEditorSession =
*/
activeBlockId?: string;
/**
- * The index of search result to scroll to after opening the session successfully.
+ * The id of search result to scroll to after opening the session successfully.
*/
- activeSearchResultIndex?: number;
+ activeSearchResultId?: string;
+ /**
+ * Used for force refreshing a session.
+ */
+ nonce?: number;
};
export type LockedEditorSession = BaseEditorSession & {
@@@ -791,10 -794,10 +795,10 @@@ class EditorStore extends BaseStore<Edi
id: sessionId,
content,
activeBlockId: options.activeBlockId,
- activeSearchResultIndex: options.activeSearchResultIndex,
+ activeSearchResultId: options.activeSearchResultId,
tabId
},
- options.silent
+ options
);
} else {
const attachmentsLength = await db.attachments
@@@ -815,11 -818,10 +819,11 @@@
color: colors[0]?.fromId,
tags,
activeBlockId: options.activeBlockId,
- activeSearchResultIndex: options.activeSearchResultIndex,
- tabId
+ activeSearchResultId: options.activeSearchResultId,
+ tabId,
+ attachmentsLength
},
- options.silent
+ options
);
} else {
this.addSession(
@@@ -837,10 -839,10 +841,10 @@@
? { ...content, data: options.rawContent }
: content,
activeBlockId: options.activeBlockId,
- activeSearchResultIndex: options.activeSearchResultIndex,
+ activeSearchResultId: options.activeSearchResultId,
tabId
},
- options.silent
+ options
);
}
}