Skip to content

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

web: don't close note after deleting its attachment Signed-off-by: 01zulfi <[email protected]>

01zulfi0ca1d8286115
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsx
index aa57a52ce..18d5a3feb 100644
--- a/apps/web/src/components/editor/index.tsx
+++ b/apps/web/src/components/editor/index.tsx
@@ -237,13 +237,24 @@ export default function TabsView() {
}
const MemoizedEditorView = React.memo(EditorView, (prev, next) => {
- return (
+ const baseConditions =
prev.session.id === next.session.id &&
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.activeSearchResultId === next.session.activeSearchResultId;
+
+ if (
+ "attachmentsLength" in prev.session &&
+ "attachmentsLength" in next.session
+ ) {
+ return (
+ baseConditions &&
+ prev.session.attachmentsLength === next.session.attachmentsLength
+ );
+ }
+
+ return baseConditions;
});
function EditorView({
session
diff --git a/apps/web/src/components/properties/index.tsx b/apps/web/src/components/properties/index.tsx
index aa4967a6d..4875e9a78 100644
--- a/apps/web/src/components/properties/index.tsx
+++ b/apps/web/src/components/properties/index.tsx
@@ -43,6 +43,7 @@ import {
import { db } from "../../common/db";
import { useStore as useAppStore } from "../../stores/app-store";
import { store as noteStore } from "../../stores/note-store";
+import { useStore as useAttachmentStore } from "../../stores/attachment-store";
import Toggle from "./toggle";
import ScrollContainer from "../scroll-container";
import {
@@ -728,12 +729,13 @@ function Reminders({ noteId }: { noteId: string }) {
);
}
function Attachments({ noteId }: { noteId: string }) {
+ const attachmentStoreNonce = useAttachmentStore((store) => store.nonce);
const result = usePromise(
() =>
db.attachments
.ofNote(noteId, "all")
.sorted({ sortBy: "dateCreated", sortDirection: "desc" }),
- [noteId]
+ [noteId, attachmentStoreNonce]
);
if (result.status !== "fulfilled" || result.value.length <= 0) return null;
diff --git a/apps/web/src/stores/attachment-store.ts b/apps/web/src/stores/attachment-store.ts
index e56053509..0b14710fb 100644
--- a/apps/web/src/stores/attachment-store.ts
+++ b/apps/web/src/stores/attachment-store.ts
@@ -135,7 +135,24 @@ class AttachmentStore extends BaseStore<AttachmentStore> {
if (await db.attachments.remove(attachment.hash, false)) {
await this.get().refresh();
await useNoteStore.getState().refresh();
- useEditorStore.getState().closeNotes(...linkedNotes);
+
+ 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 });
+ }
}
} catch (e) {
console.error(e);
diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.ts
index 71083ee43..6993877fb 100644
--- a/apps/web/src/stores/editor-store.ts
+++ b/apps/web/src/stores/editor-store.ts
@@ -102,6 +102,7 @@ export type ReadonlyEditorSession = BaseEditorSession & {
color?: string;
tags?: Tag[];
locked?: boolean;
+ attachmentsLength?: number;
};
export type DeletedEditorSession = BaseEditorSession & {
@@ -815,7 +816,8 @@ class EditorStore extends BaseStore<EditorStore> {
tags,
activeBlockId: options.activeBlockId,
activeSearchResultId: options.activeSearchResultId,
- tabId
+ tabId,
+ attachmentsLength
},
options.silent
);