Skip to content

Commit

Permalink
refactor: move to fn dec
Browse files Browse the repository at this point in the history
  • Loading branch information
secondl1ght committed Jul 5, 2024
1 parent 63549f2 commit 6ca2efd
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/components/LanguageToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import {
} from '@/components/ui/dropdown-menu';
import { SupportedLanguage } from '@/i18n';

const getCookie = () =>
document.cookie
.split('; ')
.find(c => c.startsWith('locale='))
?.split('=')[1] as SupportedLanguage | undefined;

const setCookie = (locale: SupportedLanguage) =>
(document.cookie = `locale=${locale}; max-age=31536000; path=/;`);

Expand All @@ -24,14 +30,7 @@ export function LanguageToggle() {
const { refresh } = useRouter();

const [language, setLanguage] = useState<SupportedLanguage | undefined>(
() => {
const localeCookie = document.cookie
.split('; ')
.find(c => c.startsWith('locale='))
?.split('=')[1] as SupportedLanguage | undefined;

return localeCookie;
}
getCookie()
);

return (
Expand Down

0 comments on commit 6ca2efd

Please sign in to comment.