diff --git a/apps/obsidian/src/components/RelationshipSection.tsx b/apps/obsidian/src/components/RelationshipSection.tsx index 9414902b5..7c29408e1 100644 --- a/apps/obsidian/src/components/RelationshipSection.tsx +++ b/apps/obsidian/src/components/RelationshipSection.tsx @@ -148,12 +148,12 @@ const AddRelationship = ({ activeFile }: RelationshipSectionProps) => { const nodeTypeIdsToSearch = compatibleNodeTypes.map((type) => type.id); const results = - await queryEngineRef.current?.searchCompatibleNodeByTitle( + await queryEngineRef.current.searchCompatibleNodeByTitle({ query, - nodeTypeIdsToSearch, + compatibleNodeTypeIds: nodeTypeIdsToSearch, activeFile, selectedRelationType, - ); + }); if (results.length === 0 && query.length >= 2) { setSearchError( diff --git a/apps/obsidian/src/components/SearchBar.tsx b/apps/obsidian/src/components/SearchBar.tsx index 32532fd10..df1899043 100644 --- a/apps/obsidian/src/components/SearchBar.tsx +++ b/apps/obsidian/src/components/SearchBar.tsx @@ -74,6 +74,7 @@ const SearchBar = ({ renderItem, asyncSearch, disabled = false, + className, }: { onSelect: (item: T | null) => void; placeholder?: string; @@ -81,30 +82,42 @@ const SearchBar = ({ renderItem?: (item: T, el: HTMLElement) => void; asyncSearch: (query: string) => Promise; disabled?: boolean; + className?: string; }) => { const inputRef = useRef(null); const [selected, setSelected] = useState(null); const plugin = usePlugin(); const app = plugin.app; + const asyncSearchRef = useRef(asyncSearch); useEffect(() => { - if (inputRef.current && app) { - const suggest = new GenericSuggest( - app, - inputRef.current, - (item) => { - setSelected(item); - onSelect(item); - }, - { - getItemText, - renderItem, - asyncSearch, + asyncSearchRef.current = asyncSearch; + }, [asyncSearch]); + + useEffect(() => { + if (!inputRef.current || !app) return; + const suggest = new GenericSuggest( + app, + inputRef.current, + (item) => { + setSelected(item); + onSelect(item); + inputRef.current?.blur(); + }, + { + getItemText: (item: T) => getItemText(item), + renderItem: (item: T, el: HTMLElement) => { + if (renderItem) { + renderItem(item, el); + return; + } + el.setText(getItemText(item)); }, - ); - return () => suggest.close(); - } - }, [onSelect, app, getItemText, renderItem, asyncSearch]); + asyncSearch: (query: string) => asyncSearchRef.current(query), + }, + ); + return () => suggest.close(); + }, [app, getItemText, renderItem, onSelect, asyncSearch]); const clearSelection = useCallback(() => { if (inputRef.current) { @@ -115,23 +128,21 @@ const SearchBar = ({ }, [onSelect]); return ( -
+
{selected && !disabled && (