mirror of
https://github.com/vercel/next-learn.git
synced 2026-06-24 05:05:47 +00:00
* Update next to canary * Update layout.tsx * Use canary * Remove serverActions flag warning * Use unstable_noStore * Add Date.now() test * Update metadataBase url * Create wrapper component for Cards * Update page.tsx * Misc * Delete unused data fetch * Add noStore to /invoices and /customers functions * Remove date.now() * Use canary * Rename component * Fix imports * Update types for useFormStatus and useFormState * Rename folder, add team members * fixed images and added login button pending state * Update dashboard/final-example/app/lib/data.ts Co-authored-by: Matt Kane <m@mk.gg> --------- Co-authored-by: Steven Tey <stevensteel97@gmail.com> Co-authored-by: Matt Kane <m@mk.gg>
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
'use client';
|
|
|
|
import { MagnifyingGlassIcon } from '@heroicons/react/24/outline';
|
|
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
|
import { useDebouncedCallback } from 'use-debounce';
|
|
|
|
export default function Search({ placeholder }: { placeholder: string }) {
|
|
const searchParams = useSearchParams();
|
|
const { replace } = useRouter();
|
|
const pathname = usePathname();
|
|
|
|
const handleSearch = useDebouncedCallback((term) => {
|
|
console.log(`Searching... ${term}`);
|
|
|
|
const params = new URLSearchParams(searchParams);
|
|
|
|
params.set('page', '1');
|
|
|
|
if (term) {
|
|
params.set('query', term);
|
|
} else {
|
|
params.delete('query');
|
|
}
|
|
replace(`${pathname}?${params.toString()}`);
|
|
}, 300);
|
|
|
|
return (
|
|
<div className="relative flex flex-1 flex-shrink-0">
|
|
<label htmlFor="search" className="sr-only">
|
|
Search
|
|
</label>
|
|
<input
|
|
className="peer block w-full rounded-md border border-gray-200 py-[9px] pl-10 text-sm outline-2 placeholder:text-gray-500"
|
|
placeholder={placeholder}
|
|
onChange={(e) => {
|
|
handleSearch(e.target.value);
|
|
}}
|
|
defaultValue={searchParams.get('query')?.toString()}
|
|
/>
|
|
<MagnifyingGlassIcon className="absolute left-3 top-1/2 h-[18px] w-[18px] -translate-y-1/2 text-gray-500 peer-focus:text-gray-900" />
|
|
</div>
|
|
);
|
|
}
|