@@ -4,13 +4,49 @@ import { useSearch } from '../hooks/useSearch';
44import { useProfile } from '../hooks/useProfile' ;
55import { LuSearch } from "react-icons/lu" ;
66import { useDebounce } from 'use-debounce' ;
7- import { shouldAttemptDirectLookup } from '../utils/validation' ;
7+ import { shouldAttemptDirectLookup , isValidENSNameFormat } from '../utils/validation' ;
88import { SearchResult } from '../components/SearchResult' ;
99
1010export const Route = createLazyFileRoute ( '/' ) ( {
1111 component : Home ,
1212} ) ;
1313
14+ // SuggestedSearch component that shows .eth auto-complete when user forgets to add .eth
15+ function SuggestedSearch ( { searchTerm } : { searchTerm : string } ) {
16+ const suggestedEns = `${ searchTerm } .eth` ;
17+ const { data : profile , isLoading } = useProfile ( suggestedEns ) ;
18+
19+ // Only show if we found a profile
20+ if ( isLoading || ! profile ) {
21+ return null ;
22+ }
23+
24+ return (
25+ < div className = "mb-4 p-3 bg-blue-50 rounded-md shadow-sm border border-blue-200" >
26+ < div className = "flex items-center" >
27+ { profile . avatar && (
28+ < img
29+ src = { profile . avatar }
30+ alt = { suggestedEns }
31+ className = "w-8 h-8 rounded-full mr-3"
32+ />
33+ ) }
34+ < div >
35+ < p className = "text-gray-700" >
36+ Did you mean < a href = { `/${ suggestedEns } ` } className = "font-semibold text-blue-600 hover:text-blue-800" > { suggestedEns } </ a > ?
37+ </ p >
38+ < a
39+ href = { `/${ suggestedEns } ` }
40+ className = "text-sm text-blue-600 hover:text-blue-800 underline"
41+ >
42+ Go to { suggestedEns } profile
43+ </ a >
44+ </ div >
45+ </ div >
46+ </ div >
47+ ) ;
48+ }
49+
1450// ProfileFallback component that attempts direct profile lookup
1551function ProfileFallback ( { searchTerm } : { searchTerm : string } ) {
1652 const { data : profile , isLoading, error } = useProfile ( searchTerm ) ;
@@ -91,6 +127,17 @@ function Home() {
91127 // The URL will be updated by the effect above
92128 } ;
93129
130+ // Check if we should show the .eth auto-complete
131+ const shouldShowEthAutoComplete = ( ) => {
132+ // Only show auto-complete if there's a search term, no dots in it (not already ENS), and it's not an Ethereum address
133+ return (
134+ debouncedSearchTerm &&
135+ debouncedSearchTerm . length > 1 &&
136+ ! debouncedSearchTerm . includes ( '.' ) &&
137+ ! debouncedSearchTerm . startsWith ( '0x' )
138+ ) ;
139+ } ;
140+
94141 // Render search results or appropriate message
95142 const renderResults = ( ) => {
96143 // Case 1: We have data to show
@@ -195,6 +242,11 @@ function Home() {
195242 </ form >
196243 </ div >
197244
245+ { /* .eth Auto-Complete */ }
246+ { shouldShowEthAutoComplete ( ) && (
247+ < SuggestedSearch searchTerm = { debouncedSearchTerm } />
248+ ) }
249+
198250 { /* Results section */ }
199251 < div className = "rounded-lg overflow-hidden relative" >
200252 { renderResults ( ) }
0 commit comments