-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
139 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Navbar from 'app/@navbar/page'; | ||
|
||
export default Navbar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use client'; | ||
|
||
import { MagnifyingGlassIcon } from '@heroicons/react/24/outline'; | ||
import { useGlobalTransition } from 'lib/transition'; | ||
import { useRouter } from 'next/navigation'; | ||
|
||
export default function Search({ value }: { value: string }) { | ||
const router = useRouter(); | ||
const { startTransition } = useGlobalTransition(); | ||
|
||
function searchAction(formData: FormData) { | ||
const search = formData.get('search') as string; | ||
console.log('starting transition...'); | ||
startTransition(() => { | ||
router.push(`/search?q=${search}`); | ||
}); | ||
} | ||
|
||
return ( | ||
<form action={searchAction} className="w-max-[550px] relative w-full lg:w-80 xl:w-full"> | ||
<input | ||
key={value} | ||
type="text" | ||
name="search" | ||
placeholder="Search for products..." | ||
autoComplete="off" | ||
defaultValue={value} | ||
className="w-full rounded-lg border bg-white px-4 py-2 text-sm text-black placeholder:text-neutral-500 dark:border-neutral-800 dark:bg-transparent dark:text-white dark:placeholder:text-neutral-400" | ||
/> | ||
<div className="absolute right-0 top-0 mr-3 flex h-full items-center"> | ||
<MagnifyingGlassIcon className="h-4" /> | ||
</div> | ||
</form> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use client'; | ||
|
||
import { ReactNode, createContext, use, useTransition } from 'react'; | ||
|
||
const GlobalTransitionContext = createContext<ReturnType< | ||
typeof useGlobalTransitionInternal | ||
> | null>(null); | ||
|
||
export function useGlobalTransition() { | ||
const transition = use(GlobalTransitionContext); | ||
|
||
if (transition === null) { | ||
throw new Error('Make sure to use `GlobalTransitionProvider` first.'); | ||
} | ||
|
||
return transition; | ||
} | ||
|
||
function useGlobalTransitionInternal() { | ||
const [isPending, startTransition] = useTransition(); | ||
|
||
return { isPending, startTransition }; | ||
} | ||
|
||
export function GlobalTransitionProvider({ children }: { children: ReactNode }) { | ||
const transition = useGlobalTransitionInternal(); | ||
return ( | ||
<GlobalTransitionContext.Provider value={transition}> | ||
{children} | ||
</GlobalTransitionContext.Provider> | ||
); | ||
} |