Skip to content

Commit 730ffdd

Browse files
committed
feat: add SearchBox component to Header for enhanced song and user search functionality
1 parent 58eb0cd commit 730ffdd

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

apps/frontend/src/modules/shared/components/layout/Header.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { checkLogin, getUserData } from '@web/modules/auth/features/auth.utils';
1313
import { BlockTab } from './BlockTab';
1414
import { NavLinks } from './NavLinks';
1515
import { RandomSongButton } from './RandomSongButton';
16+
import { SearchBox } from './SearchBox';
1617

1718
export async function Header() {
1819
let isLogged;
@@ -93,6 +94,7 @@ export async function Header() {
9394
label='About'
9495
className='bg-cyan-700 after:bg-cyan-900 before:bg-cyan-950'
9596
/>
97+
<SearchBox />
9698
<RandomSongButton />
9799
</div>
98100

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'use client';
2+
import { faMagnifyingGlass } from '@fortawesome/free-solid-svg-icons';
3+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
4+
import { useRouter } from 'next/navigation';
5+
import { useState } from 'react';
6+
7+
import { cn } from '@web/lib/tailwind.utils';
8+
import { Popover, PopoverContent, PopoverTrigger } from './popover';
9+
10+
export const SearchBox = () => {
11+
const [query, setQuery] = useState('');
12+
const router = useRouter();
13+
14+
return (
15+
<Popover>
16+
<PopoverTrigger
17+
className={cn(
18+
'bevel p-2 flex-1 w-8 md:min-w-20 max-w-28 flex items-center justify-center gap-2 bg-zinc-600 after:bg-zinc-800 before:bg-zinc-900 translate-y-[11px] hover:translate-y-1.5 transition-all duration-150 hover:brightness-125',
19+
)}
20+
id={'search-button'}
21+
>
22+
<FontAwesomeIcon icon={faMagnifyingGlass} />
23+
<span className='hidden sm:block'>Search</span>
24+
</PopoverTrigger>
25+
<PopoverContent className='w-fit p-[2px] pb-1.5 h-fit shadow-[inset_0px_0px_0px_2px_rgb(82_82_91)] drop-shadow-lg border-zinc-600 bg-zinc-800 text-white rounded-lg'>
26+
<div className='flex flex-row gap-2 p-4'>
27+
<input
28+
type='text'
29+
value={query}
30+
onChange={(e) => setQuery(e.target.value)}
31+
placeholder='Search for songs and users'
32+
className='w-full bg-zinc-800 text-white border border-zinc-600 rounded-md p-2'
33+
/>
34+
<button
35+
className='bg-zinc-600 text-white rounded-md p-2 hover:bg-zinc-500 w-12 h-12'
36+
onClick={() => {
37+
const queryParam = new URLSearchParams({
38+
page: '1',
39+
limit: '20',
40+
query,
41+
});
42+
43+
router.push(`/search-user?${queryParam.toString()}`);
44+
}}
45+
>
46+
<FontAwesomeIcon icon={faMagnifyingGlass} />
47+
</button>
48+
</div>
49+
</PopoverContent>
50+
</Popover>
51+
);
52+
};

0 commit comments

Comments
 (0)