From 88f84c5113891fa3fdfffa78fa3d65a39e69e166 Mon Sep 17 00:00:00 2001 From: Aniruddha Upadhya K Date: Wed, 5 Jun 2024 00:49:49 +0530 Subject: [PATCH] fix: Locale switcher --- src/components/Header/Header.tsx | 7 +---- src/components/Header/LocaleSwitcher.tsx | 35 ++++++++++-------------- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 4aeae4e..24046bc 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -1,13 +1,10 @@ "use client"; import { navigation } from "~/constants"; -// import Button from "../design/Button"; -// import MenuSvg from "~/assets/svg/MenuSvg"; import { useTranslations } from "next-intl"; import LocaleLink from "../ui/LocaleLink"; import LocalSwitcher from "./LocaleSwitcher"; import styles from "./styles.module.css"; import { usePathname } from "next/navigation"; -import { useEffect } from "react"; const Header = () => { const t = useTranslations("links"); @@ -42,9 +39,7 @@ const Header = () => { ))}
- +
diff --git a/src/components/Header/LocaleSwitcher.tsx b/src/components/Header/LocaleSwitcher.tsx index 26d5b41..4a37d04 100644 --- a/src/components/Header/LocaleSwitcher.tsx +++ b/src/components/Header/LocaleSwitcher.tsx @@ -1,31 +1,26 @@ -'use client'; -import { useLocale } from 'next-intl'; -import { useRouter } from 'next/navigation'; -import { ChangeEvent, useTransition } from 'react'; +"use client"; +import { useLocale } from "next-intl"; +import { usePathname, useRouter } from "next/navigation"; +import { ChangeEvent, useTransition } from "react"; export default function LocalSwitcher() { const [isPending, startTransition] = useTransition(); const router = useRouter(); + const path = usePathname(); const localActive = useLocale(); - const onSelectChange = (e: ChangeEvent) => { - const nextLocale = e.target.value; + const onClick = () => { startTransition(() => { - router.replace(`/${nextLocale}`); + router.push(localActive === "en" ? "kn" : "en"); + router.refresh(); }); }; return ( - + ); -} \ No newline at end of file +}