import { MagnifyingGlassIcon } from '@heroicons/react/24/outline' import Input from 'components/Input' import useSearch from 'hooks/useSearch' import { useMemo, useState } from 'react' import { useDebounce } from 'utils/debounce' import { CollectionsTable } from './CollectionsTable' export function SelectCollection({ selectCollection }: { selectCollection: (collectionAddress: string) => void }) { const [search, setSearch] = useState('') const [isInputFocused, setInputFocus] = useState(false) const debouncedQuery = useDebounce(search, 200) const debouncedIsInputFocused = useDebounce(isInputFocused, 200) const collectionsQuery = useSearch(debouncedQuery, ['collections'], 5) const collectionsResults = useMemo(() => { return collectionsQuery.data?.find((searchResult) => searchResult.indexUid === 'collections') }, [collectionsQuery.data]) const clickableCollections = useMemo(() => { return ( collectionsResults?.hits.map((hit) => ({ contractAddress: hit.id, name: hit.name, media: hit.thumbnail_url || hit.image_url, onClick: () => { selectCollection(hit.id) setSearch(hit.name) }, })) ?? [] ) }, [collectionsResults, selectCollection, setSearch]) const handleInputFocus = () => { setInputFocus(true) } const handleInputBlur = () => { setInputFocus(false) } return (

Select the NFT collection to take a snapshot for

} id="collection-search" onBlur={handleInputBlur} onChange={(e) => setSearch(e.target.value)} onFocus={handleInputFocus} placeholder="Search Collections..." value={search} /> {debouncedIsInputFocused && (
)}
) }