Skip to content

Commit bb224f8

Browse files
committed
chore: clickable links
1 parent 38b4f80 commit bb224f8

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

apps/web/src/components/Search/SearchBar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ export default function SearchBar({ recentSearches = [], characters = [] }: { re
106106
</div>
107107
<div className="mt-4">
108108
{loading && <div className="text-center text-gray-500 py-4">Loading results...</div>}
109-
{!loading && results.user?.length > 0 && <SearchSection title="USER RESULTS" items={results} />}
110-
{!loading && results.artwork?.length > 0 && <SearchSection title="ARTWORK RESULTS" items={results} />}
111-
{!loading && results.character?.length > 0 && <SearchSection title="CHARACTER RESULTS" items={results} isCharacter />}
109+
{!loading && (results.user ?? []).length > 0 && <SearchSection title="USER RESULTS" items={results} />}
110+
{!loading && (results.artwork ?? []).length > 0 && <SearchSection title="ARTWORK RESULTS" items={results} />}
111+
{!loading && (results.character ?? []).length > 0 && <SearchSection title="CHARACTER RESULTS" items={results} isCharacter />}
112112
{!loading && query.trim() && results.user?.length === 0 && results.artwork?.length === 0 && results.character?.length === 0 && (
113113
<>
114114
<div className="text-center text-gray-500 py-4">No results found for "<strong>{query}</strong>"</div>

apps/web/src/components/Search/Section.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
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

36
interface 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

Comments
 (0)