Fixed implementation of unauth language switcher

Now we can go implement it for auth
This commit is contained in:
Justin Edmund 2022-03-05 10:46:52 -08:00
parent 8d9b68906c
commit 14c6b5e2da

View file

@ -29,7 +29,7 @@ const HeaderMenu = (props: Props) => {
const [checked, setChecked] = useState(false) const [checked, setChecked] = useState(false)
console.log(`Currently: ${checked} ${cookies['NEXT_LOCALE']}`) // console.log(`Currently: ${checked} ${cookies['NEXT_LOCALE']}`)
useEffect(() => { useEffect(() => {
const locale = cookies['NEXT_LOCALE'] const locale = cookies['NEXT_LOCALE']
@ -37,11 +37,10 @@ const HeaderMenu = (props: Props) => {
}, [cookies]) }, [cookies])
function handleCheckedChange(value: boolean) { function handleCheckedChange(value: boolean) {
setChecked(value) const language = (value) ? 'ja' : 'en'
setCookies('NEXT_LOCALE', (value) ? 'ja' : 'en', { path: '/'}) setCookies('NEXT_LOCALE', language, { path: '/'})
router.push(router.asPath, undefined, { locale: language })
// TODO: How do we persist the current page when changing languages? // router.reload()
window.location.href = '/'
} }
function authItems() { function authItems() {