mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 07:38:53 +02:00
fix(client/search): not reacting to change
This commit is contained in:
parent
d2962b060e
commit
348432bd5b
@ -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. */
|
/** 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;
|
displayOnlyCollections?: boolean;
|
||||||
isEnabled: boolean;
|
isEnabled: boolean;
|
||||||
|
ntxId: string | null | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function NoteList<T extends object>(props: Pick<NoteListProps<T>, "displayOnlyCollections">) {
|
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();
|
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">) {
|
export function SearchNoteList<T extends object>(props: Omit<NoteListProps<T>, "isEnabled">) {
|
||||||
return <CustomNoteList {...props} isEnabled={true} />
|
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 widgetRef = useRef<HTMLDivElement>(null);
|
||||||
const viewType = useNoteViewType(note);
|
const viewType = useNoteViewType(note);
|
||||||
const noteIds = useNoteIds(note, viewType);
|
const noteIds = useNoteIds(note, viewType, ntxId);
|
||||||
const isFullHeight = (viewType && viewType !== "list" && viewType !== "grid");
|
const isFullHeight = (viewType && viewType !== "list" && viewType !== "grid");
|
||||||
const [ isIntersecting, setIsIntersecting ] = useState(false);
|
const [ isIntersecting, setIsIntersecting ] = useState(false);
|
||||||
const shouldRender = (isFullHeight || isIntersecting || note?.type === "book");
|
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 [ noteIds, setNoteIds ] = useState<string[]>([]);
|
||||||
const [ includeArchived ] = useNoteLabelBoolean(note, "includeArchived");
|
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.
|
// Refresh on import.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function onImport(message: WebSocketMessage) {
|
async function onImport(message: WebSocketMessage) {
|
||||||
|
@ -57,6 +57,7 @@ export default function SearchResult() {
|
|||||||
note={note}
|
note={note}
|
||||||
notePath={notePath}
|
notePath={notePath}
|
||||||
highlightedTokens={highlightedTokens}
|
highlightedTokens={highlightedTokens}
|
||||||
|
ntxId={ntxId}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user