fix:content filter query

This commit is contained in:
Rama Priyanto 2025-07-22 14:11:38 +07:00
parent 5807e389b4
commit 9563ad5987
1 changed files with 19 additions and 6 deletions

View File

@ -1,7 +1,7 @@
"use client";
import { useLocale } from "next-intl";
import { useParams } from "next/navigation";
import { useParams, useSearchParams } from "next/navigation";
import { locales } from "@/config";
import { usePathname, useRouter } from "@/i18n/routing";
@ -33,13 +33,22 @@ export default function LocalSwitcher() {
const params = useParams();
const localActive = useLocale() || "in";
const [selectedLang, setSelectedLang] = useState<string>("");
const searchParams = useSearchParams();
useEffect(() => {
const storedLang = getLanguage();
let joinParam = "";
if (searchParams) {
joinParam = Array.from(searchParams.entries())
.map(([key, value]) => `${key}=${value}`)
.join("&");
}
if (pathname.includes("polda")){
if (pathname.includes("polda")) {
startTransition(() => {
router.replace(pathname, { locale: "in" });
router.replace(pathname + joinParam === "" ? "" : `?${joinParam}`, {
locale: "in",
});
});
} else {
if (!storedLang) {
@ -47,16 +56,20 @@ export default function LocalSwitcher() {
setSelectedLang("in");
startTransition(() => {
router.replace(pathname, { locale: "in" });
router.replace(pathname + joinParam === "" ? "" : `?${joinParam}`, {
locale: "in",
});
});
} else {
setSelectedLang(storedLang);
startTransition(() => {
router.replace(pathname, { locale: storedLang });
router.replace(pathname + joinParam === "" ? "" : `?${joinParam}`, {
locale: storedLang,
});
});
}
}
}, []);
}, [searchParams]);
const onSelectChange = (nextLocale: string) => {
setLanguage(nextLocale);