Skip to content

Build your personal knowledge base with Trilium Notes

fix(client/search): not reacting to change

Elian Doran348432bd5be8
diff --git a/apps/client/src/widgets/collections/NoteList.tsx b/apps/client/src/widgets/collections/NoteList.tsx
index d458cb68b9..7eac3f57af 100644
--- a/apps/client/src/widgets/collections/NoteList.tsx
+++ b/apps/client/src/widgets/collections/NoteList.tsx
@@ -20,22 +20,23 @@ interface NoteListProps<T extends object> {
/** 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<T extends object>(props: Pick<NoteListProps<T>, "displayOnlyCollections">) {
- const { note, noteContext, notePath } = useNoteContext();
+ const { note, noteContext, notePath, ntxId } = useNoteContext();
const isEnabled = noteContext?.hasNoteList();
- return <CustomNoteList note={note} isEnabled={!!isEnabled} notePath={notePath} {...props} />
+ return <CustomNoteList note={note} isEnabled={!!isEnabled} notePath={notePath} ntxId={ntxId} {...props} />
}
export function SearchNoteList<T extends object>(props: Omit<NoteListProps<T>, "isEnabled">) {
return <CustomNoteList {...props} isEnabled={true} />
}
-function CustomNoteList<T extends object>({ note, isEnabled: shouldEnable, notePath, highlightedTokens, displayOnlyCollections }: NoteListProps<T>) {
+function CustomNoteList<T extends object>({ note, isEnabled: shouldEnable, notePath, highlightedTokens, displayOnlyCollections, ntxId }: NoteListProps<T>) {
const widgetRef = useRef<HTMLDivElement>(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<string[]>([]);
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 c259e2cb7c..6c1c074196 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}
/>
)}
</div>