-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update(tt): experiment with book modes
- Loading branch information
1 parent
ef105a0
commit 5c15ac9
Showing
3 changed files
with
111 additions
and
7 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
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
42 changes: 42 additions & 0 deletions
42
apps/total-typescript/src/app/book/_components/mode-toggle.tsx
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,42 @@ | ||
'use client' | ||
|
||
import type {ReadonlyRequestCookies} from 'next/dist/server/web/spec-extension/adapters/request-cookies' | ||
import React from 'react' | ||
import {useCookies} from 'react-cookie' | ||
import {useRouter} from 'next/navigation' | ||
|
||
const ModeToggle = React.forwardRef< | ||
HTMLButtonElement, | ||
React.PropsWithChildren<{ | ||
mode: 'video' | 'book' | ||
}> | ||
>(({children, mode, ...props}, ref) => { | ||
const [cookies, setCookie] = useCookies(['bookPrefs']) | ||
const router = useRouter() | ||
|
||
return ( | ||
<> | ||
<button | ||
ref={ref} | ||
{...props} | ||
onClick={() => { | ||
setCookie( | ||
'bookPrefs', | ||
{ | ||
...cookies.bookPrefs, | ||
mode: mode === 'book' ? 'video' : 'book', | ||
}, | ||
{ | ||
path: '/', | ||
}, | ||
) | ||
return router.refresh() | ||
}} | ||
> | ||
{children} | ||
</button> | ||
</> | ||
) | ||
}) | ||
|
||
export default ModeToggle |