@@ -5,12 +5,23 @@ import { SearchIcon } from 'lucide-react'
55
66import { useDebouncedCallback } from 'use-debounce'
77
8+ import {
9+ useGetModelSources ,
10+ useModelSourcesMutation ,
11+ } from '@/hooks/useModelSource'
12+
13+ import Spinner from '../Loader/Spinner'
14+
815type Props = {
16+ supportModelImport ?: boolean
917 onSearchLocal ?: ( searchText : string ) => void
1018}
1119
12- const ModelSearch = ( { onSearchLocal } : Props ) => {
20+ const ModelSearch = ( { supportModelImport , onSearchLocal } : Props ) => {
1321 const [ searchText , setSearchText ] = useState ( '' )
22+ const [ isSearching , setSearching ] = useState ( false )
23+ const { mutate } = useGetModelSources ( )
24+ const { addModelSource } = useModelSourcesMutation ( )
1425 const inputRef = useRef < HTMLInputElement | null > ( null )
1526 const debounced = useDebouncedCallback ( async ( ) => {
1627 if ( searchText . indexOf ( '/' ) === - 1 ) {
@@ -20,6 +31,15 @@ const ModelSearch = ({ onSearchLocal }: Props) => {
2031 }
2132 // Attempt to search local
2233 onSearchLocal ?.( searchText )
34+
35+ setSearching ( true )
36+ // Attempt to search model source
37+ if ( supportModelImport )
38+ addModelSource ( searchText )
39+ . then ( ( ) => mutate ( ) )
40+ . then ( ( ) => onSearchLocal ?.( searchText ) )
41+ . catch ( console . debug )
42+ . finally ( ( ) => setSearching ( false ) )
2343 } , 300 )
2444
2545 const onSearchChanged = useCallback (
@@ -50,8 +70,18 @@ const ModelSearch = ({ onSearchLocal }: Props) => {
5070 return (
5171 < Input
5272 ref = { inputRef }
53- prefixIcon = { < SearchIcon size = { 16 } /> }
54- placeholder = "Search models..."
73+ prefixIcon = {
74+ isSearching ? (
75+ < Spinner size = { 16 } strokeWidth = { 2 } />
76+ ) : (
77+ < SearchIcon size = { 16 } />
78+ )
79+ }
80+ placeholder = {
81+ supportModelImport
82+ ? 'Search or enter Hugging Face URL'
83+ : 'Search models'
84+ }
5585 onChange = { onSearchChanged }
5686 onKeyDown = { onKeyDown }
5787 value = { searchText }
0 commit comments