grand commit

This commit is contained in:
2025-02-07 08:34:42 +02:00
parent f594f001f6
commit c6c34f0453
53 changed files with 1283 additions and 625 deletions

View File

@@ -1,39 +1,37 @@
'use client'
import cookies from 'js-cookie'
import {useLocale} from 'next-intl'
import {redirect} from 'next/navigation'
import {Link, usePathname, useRouter} from '@/i18n/routing'
import {useRouter} from '@/i18n/routing'
import {Link} from '@/i18n/routing'
import {Label} from '@/ui/label'
import {Switch} from '@/ui/switch'
export default function LocaleSwitcher() {
const router = useRouter()
const pathname = usePathname()
const locale = useLocale()
const initialState = locale !== 'uk'
//const [localeState, setLocaleState] = useState(initialState)
const handler = (state: boolean) => {
const newPath = `/${locale}${pathname}`
//window.history.replaceState(null, '', newPath)
const link = document.getElementById('lang-switch')
if (link) {
link.innerText = `${state ? '/ru' : ''}${pathname}`
link.setAttribute('href', `${state ? '/ru' : ''}${pathname}`)
link.click()
}
const handleLocaleChange = (state: boolean) => {
const locale = cookies.get('NEXT_LOCALE') === 'ru' ? 'uk' : 'ru'
cookies.set('NEXT_LOCALE', locale, {
expires: 7,
path: '/',
sameSite: 'Lax'
})
router.replace(window.location.pathname.replace(/^\/ru/, ''), {locale})
}
// router.replace('/cabinet', {locale: checked ? 'ru' : 'uk'}
return (
<div className='flex items-center space-x-2'>
<Link id='lang-switch' href='/' locale='uk'>
LA
</Link>
<Label htmlFor='locale-switcher'>Укр</Label>
<Switch
className='bg-brand-violet-900'
id='locale-switcher'
defaultChecked={initialState}
onCheckedChange={handler}
onCheckedChange={handleLocaleChange}
/>
<Label htmlFor='locale-switcher'>Рус</Label>
</div>