From 348432bd5be81c006a8512ad01c8268fd272455f Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 23 Sep 2025 21:55:39 +0300 Subject: [PATCH] fix(client/search): not reacting to change --- .../client/src/widgets/collections/NoteList.tsx | 17 ++++++++++++----- apps/client/src/widgets/search_result.tsx | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/client/src/widgets/collections/NoteList.tsx b/apps/client/src/widgets/collections/NoteList.tsx index d458cb68b..7eac3f57a 100644 --- a/apps/client/src/widgets/collections/NoteList.tsx +++ b/apps/client/src/widgets/collections/NoteList.tsx @@ -20,22 +20,23 @@ interface NoteListProps { /** if set to `true` then only collection-type views are displayed such as geo-map and the calendar. The original book types grid and list will be ignored. */ displayOnlyCollections?: boolean; isEnabled: boolean; + ntxId: string | null | undefined; } export default function NoteList(props: Pick, "displayOnlyCollections">) { - const { note, noteContext, notePath } = useNoteContext(); + const { note, noteContext, notePath, ntxId } = useNoteContext(); const isEnabled = noteContext?.hasNoteList(); - return + return } export function SearchNoteList(props: Omit, "isEnabled">) { return } -function CustomNoteList({ note, isEnabled: shouldEnable, notePath, highlightedTokens, displayOnlyCollections }: NoteListProps) { +function CustomNoteList({ note, isEnabled: shouldEnable, notePath, highlightedTokens, displayOnlyCollections, ntxId }: NoteListProps) { const widgetRef = useRef(null); const viewType = useNoteViewType(note); - const noteIds = useNoteIds(note, viewType); + const noteIds = useNoteIds(note, viewType, ntxId); const isFullHeight = (viewType && viewType !== "list" && viewType !== "grid"); const [ isIntersecting, setIsIntersecting ] = useState(false); const shouldRender = (isFullHeight || isIntersecting || note?.type === "book"); @@ -119,7 +120,7 @@ function useNoteViewType(note?: FNote | null): ViewTypeOptions | undefined { } } -function useNoteIds(note: FNote | null | undefined, viewType: ViewTypeOptions | undefined) { +function useNoteIds(note: FNote | null | undefined, viewType: ViewTypeOptions | undefined, ntxId: string | null | undefined) { const [ noteIds, setNoteIds ] = useState([]); const [ includeArchived ] = useNoteLabelBoolean(note, "includeArchived"); @@ -153,6 +154,12 @@ function useNoteIds(note: FNote | null | undefined, viewType: ViewTypeOptions | } }) + // Refresh on search. + useTriliumEvent("searchRefreshed", ({ ntxId: eventNtxId }) => { + if (eventNtxId !== ntxId) return; + refreshNoteIds(); + }); + // Refresh on import. useEffect(() => { async function onImport(message: WebSocketMessage) { diff --git a/apps/client/src/widgets/search_result.tsx b/apps/client/src/widgets/search_result.tsx index c259e2cb7..6c1c07419 100644 --- a/apps/client/src/widgets/search_result.tsx +++ b/apps/client/src/widgets/search_result.tsx @@ -57,6 +57,7 @@ export default function SearchResult() { note={note} notePath={notePath} highlightedTokens={highlightedTokens} + ntxId={ntxId} /> )}