@@ -181,6 +181,7 @@ const Search: React.FC<SearchProps> = ({onOpenChange, query, setQuery}) => {
181181 const { data : topicsData } = topicsQuery ;
182182
183183 const [ displayResults , setDisplayResults ] = useState < AccountSearchResult [ ] > ( [ ] ) ;
184+ const [ lastResultState , setLastResultState ] = useState < 'results' | 'none' | null > ( null ) ;
184185
185186 // Filter topics client-side (no additional API call needed)
186187 const matchingTopics = useMemo ( ( ) => {
@@ -204,18 +205,29 @@ const Search: React.FC<SearchProps> = ({onOpenChange, query, setQuery}) => {
204205 } , [ query , shouldSearch , topicsData ?. topics ] ) ;
205206
206207 useEffect ( ( ) => {
208+ if ( ! shouldSearch ) {
209+ setDisplayResults ( [ ] ) ;
210+ setLastResultState ( null ) ;
211+ return ;
212+ }
213+
214+ if ( ! isFetched ) {
215+ return ;
216+ }
217+
207218 if ( data ?. accounts && data . accounts . length > 0 ) {
208219 setDisplayResults ( data . accounts ) ;
209- } else if ( ! isFetching && shouldSearch ) {
220+ setLastResultState ( 'results' ) ;
221+ } else {
210222 setDisplayResults ( [ ] ) ;
223+ setLastResultState ( 'none' ) ;
211224 }
212- } , [ data ?. accounts , isFetching , shouldSearch ] ) ;
225+ } , [ data ?. accounts , isFetched , shouldSearch ] ) ;
213226
214227 const showLoading = isFetching && shouldSearch ;
215- const hasAnyResults = matchingTopics . length > 0 || displayResults . length > 0 ;
216- const showNoResults = ! isFetching && isFetched && ! hasAnyResults && shouldSearch && debouncedQuery === query ;
217- const showSuggested = query . length < 2 || ( showLoading && ! hasAnyResults ) ;
218- const showSearchResults = shouldSearch && hasAnyResults ;
228+ const showSuggested = query . length < 2 || ( ! lastResultState && shouldSearch && matchingTopics . length === 0 ) ;
229+ const showNoResults = ! showSuggested && lastResultState === 'none' && matchingTopics . length === 0 ;
230+ const showSearchResults = ! showSuggested && ( displayResults . length > 0 || matchingTopics . length > 0 ) ;
219231
220232 // Focus the query input on initial render
221233 useEffect ( ( ) => {
0 commit comments