1- import { SearchResult , Character , Artwork , UserType } from "@/types/utils"
1+ import { Character , Artwork } from "@/types/characters" ;
2+ import { UserType } from "@/types/users" ;
3+ import { SearchResult } from "@/types/utils" ;
4+ import Link from "next/link" ;
25
36interface SearchSectionProps {
47 title : string
58 items ?: string [ ] | { name : string ; image ?: string } [ ] | SearchResult
69 isCharacter ?: boolean
710}
811
9- export function SearchSection ( { title, items, isCharacter = false } : SearchSectionProps ) {
10- let formattedItems : { name : string ; image ?: string } [ ] = [ ]
12+ export function SearchSection ( { title, items } : SearchSectionProps ) {
13+ let formattedItems : { name : string ; image ?: string , href : string } [ ] = [ ]
1114
1215 if ( ! items ) {
1316 return null
@@ -17,21 +20,24 @@ export function SearchSection({ title, items, isCharacter = false }: SearchSecti
1720 formattedItems = items . map ( ( item ) =>
1821 typeof item === "string"
1922 ? { name : item }
20- : { name : item . name , image : ( item as { image ?: string } ) . image }
23+ : { name : item . name , image : ( item as { image ?: string } ) . image , href : `/search?q= ${ item . name } ` }
2124 )
2225 } else if ( typeof items === "object" ) {
2326 formattedItems = [
2427 ...( items . user ?. map ( ( user : UserType ) => ( {
2528 name : user . displayName || user . handle ,
2629 image : user . avatarUrl ,
30+ href : `/@${ user . handle } ` ,
2731 } ) ) ?? [ ] ) ,
2832 ...( items . character ?. map ( ( char : Character ) => ( {
2933 name : char . name ,
3034 image : char . avatarUrl ,
35+ href : `/@${ char . owner . handle } /${ char . name } ` ,
3136 } ) ) ?? [ ] ) ,
3237 ...( items . artwork ?. map ( ( art : Artwork ) => ( {
3338 name : art . title || "Untitled Artwork" ,
3439 image : art . artworkUrl || art . watermarkUrl ,
40+ href : `/artworks/${ art . id } ` ,
3541 } ) ) ?? [ ] ) ,
3642 ]
3743 }
@@ -45,10 +51,12 @@ export function SearchSection({ title, items, isCharacter = false }: SearchSecti
4551 key = { index }
4652 className = "flex items-center gap-2 py-1 cursor-pointer hover:bg-300 px-2 rounded"
4753 >
48- { item . image && (
49- < img src = { item . image } alt = { item . name } className = "w-6 h-6 rounded-full" />
50- ) }
51- { item . name }
54+ < Link href = { item . href || "#" } className = "flex items-center gap-2" >
55+ { item . image && (
56+ < img src = { item . image } alt = { item . name } className = "w-6 h-6 rounded-full" />
57+ ) }
58+ { item . name }
59+ </ Link >
5260 </ li >
5361 ) ) }
5462 </ ul >
0 commit comments