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 note on attachment permanent delete
Abdullah Attaa7fa42e94480
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsxindex 4e23d6a28..72b9b0ae8 100644--- a/apps/web/src/components/editor/index.tsx+++ b/apps/web/src/components/editor/index.tsx@@ -243,7 +243,8 @@ const MemoizedEditorView = React.memo(EditorView, (prev, next) => {prev.session.needsHydration === next.session.needsHydration &&prev.session.activeBlockId === next.session.activeBlockId &&prev.session.activeSearchResultIndex ===- next.session.activeSearchResultIndex+ next.session.activeSearchResultIndex &&+ prev.session.nonce === next.session.nonce);});function EditorView({diff --git a/apps/web/src/components/properties/index.tsx b/apps/web/src/components/properties/index.tsxindex 902dddd03..c8f89efeb 100644--- a/apps/web/src/components/properties/index.tsx+++ b/apps/web/src/components/properties/index.tsx@@ -42,6 +42,7 @@ import {} from "../../stores/editor-store";import { db } from "../../common/db";import { useStore as useAppStore } from "../../stores/app-store";+import { useStore as useAttachmentStore } from "../../stores/attachment-store";import { store as noteStore } from "../../stores/note-store";import Toggle from "./toggle";import ScrollContainer from "../scroll-container";@@ -727,26 +728,27 @@ function Reminders({ noteId }: { noteId: string }) {);}function Attachments({ noteId }: { noteId: string }) {+ const nonce = useAttachmentStore((store) => store.nonce);const result = usePromise(() =>db.attachments.ofNote(noteId, "all").sorted({ sortBy: "dateCreated", sortDirection: "desc" }),- [noteId]+ [noteId, nonce]);+if (result.status !== "fulfilled" || result.value.length <= 0) return null;return (<Sectiontitle={strings.dataTypesPluralCamelCase.attachment()}- sx={{ borderTop: "1px solid var(--border)" }}+ sx={{ borderTop: "1px solid var(--border)", mt: 1 }}><VirtualizedTableestimatedSize={25}getItemKey={(index) => result.value.key(index)}items={result.value.placeholders}style={{- marginTop: 5,tableLayout: "fixed",width: "100%"}}diff --git a/apps/web/src/components/virtualized-table/index.tsx b/apps/web/src/components/virtualized-table/index.tsxindex 95628703c..13b26ce2b 100644--- a/apps/web/src/components/virtualized-table/index.tsx+++ b/apps/web/src/components/virtualized-table/index.tsx@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import { Virtualizer } from "@tanstack/react-virtual";import { Flex } from "@theme-ui/components";-import React, { useRef } from "react";+import React, { useLayoutEffect, useRef, useState } from "react";import { TableVirtuoso } from "react-virtuoso";export type VirtualizedTableRowProps<T, C> = {@@ -57,6 +57,14 @@ export function VirtualizedTable<T, C>(props: VirtualizedTableProps<T, C>) {style} = props;const containerRef = useRef<HTMLDivElement>(null);+ const [scrollParent, setScrollParent] = useState(scrollElement);++ useLayoutEffect(() => {+ setScrollParent(+ scrollElement ||+ containerRef.current?.closest<HTMLDivElement>(".ms-container")+ );+ }, [scrollElement]);return (<Flex@@ -67,11 +75,7 @@ export function VirtualizedTable<T, C>(props: VirtualizedTableProps<T, C>) {<TableVirtuosodata={items}context={context}- customScrollParent={- scrollElement ||- containerRef.current?.closest(".ms-container") ||- undefined- }+ customScrollParent={scrollParent || undefined}increaseViewportBy={300}computeItemKey={(index) => getItemKey(index)}defaultItemHeight={estimatedSize}diff --git a/apps/web/src/stores/attachment-store.ts b/apps/web/src/stores/attachment-store.tsindex e56053509..0da34a3cd 100644--- a/apps/web/src/stores/attachment-store.ts+++ b/apps/web/src/stores/attachment-store.ts@@ -135,13 +135,19 @@ 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);+ for (const noteId of linkedNotes) {+ await useEditorStore.getState().openSession(noteId, {+ force: true,+ silent: useEditorStore.getState().getActiveNote()?.id !== noteId+ });+ }}} catch (e) {console.error(e);- this._changeWorkingStatus(attachment.hash);if (e instanceof Error)showToast("error", `${strings.failedToDelete()}: ${e.message}`);+ } finally {+ this._changeWorkingStatus(attachment.hash);}};diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.tsindex 5117c1966..bd49050b5 100644--- a/apps/web/src/stores/editor-store.ts+++ b/apps/web/src/stores/editor-store.ts@@ -88,6 +88,10 @@ export type BaseEditorSession = {* The index of search result to scroll to after opening the session successfully.*/activeSearchResultIndex?: number;+ /**+ * Used for force refreshing a session.+ */+ nonce?: number;};export type LockedEditorSession = BaseEditorSession & {@@ -759,7 +763,7 @@ class EditorStore extends BaseStore<EditorStore> {activeBlockId: options.activeBlockId,tabId},- options.silent+ options);} else if (isLocked && note.type !== "trash") {this.addSession(@@ -770,7 +774,7 @@ class EditorStore extends BaseStore<EditorStore> {activeBlockId: options.activeBlockId,tabId},- options.silent+ options);} else {const content = note.contentId@@ -793,7 +797,7 @@ class EditorStore extends BaseStore<EditorStore> {activeSearchResultIndex: options.activeSearchResultIndex,tabId},- options.silent+ options);} else {const attachmentsLength = await db.attachments@@ -817,7 +821,7 @@ class EditorStore extends BaseStore<EditorStore> {activeSearchResultIndex: options.activeSearchResultIndex,tabId},- options.silent+ options);} else {this.addSession(@@ -838,7 +842,7 @@ class EditorStore extends BaseStore<EditorStore> {activeSearchResultIndex: options.activeSearchResultIndex,tabId},- options.silent+ options);}}@@ -934,15 +938,20 @@ class EditorStore extends BaseStore<EditorStore> {}};- addSession = (session: EditorSession, silent = false) => {+ addSession = (+ session: EditorSession,+ options?: { force?: boolean; silent?: boolean }+ ) => {this.set((state) => {const index = state.sessions.findIndex((s) => s.id === session.id);if (index > -1) {+ if (options?.force)+ session.nonce = (state.sessions[index]?.nonce || 0) + 1;state.sessions[index] = session;} else state.sessions.push(session);});- this.activateSession(session.id, undefined, silent);+ this.activateSession(session.id, undefined, options?.silent);};saveSession = async (