feat: enhance locale handling and add new blocks route
- Added a new route for blocks to improve navigation structure. - Fixed locale inconsistency in BlocksNav component by removing custom locale handling. - Implemented checks in locale selector components to prevent unnecessary locale updates. - Updated comments to reflect changes and improve code clarity.
This commit is contained in:
parent
c9e4b7eb0b
commit
f1b1789207
@ -2,13 +2,7 @@ import { categories } from '@/components/blocks/blocks';
|
||||
import BlocksNav from '@/components/blocks/blocks-nav';
|
||||
import { PropsWithChildren } from 'react';
|
||||
|
||||
/**
|
||||
* TODO: bug to fix
|
||||
*
|
||||
* when in zh locale, click blocks nav will redirect to /zh/blocks/logo
|
||||
* but the navbar is not updated with the new locale
|
||||
*
|
||||
*/
|
||||
// The locale inconsistency issue has been fixed in the BlocksNav component
|
||||
export default function CategoryLayout({ children }: PropsWithChildren) {
|
||||
return (
|
||||
<>
|
||||
|
@ -3,23 +3,13 @@
|
||||
import { LocaleLink, useLocalePathname } from '@/i18n/navigation';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useLocale } from 'next-intl';
|
||||
import { routing } from '@/i18n/routing';
|
||||
import { useParams } from 'next/navigation';
|
||||
|
||||
export default function BlocksNav({ categories }: { categories: string[] }) {
|
||||
const pathname = useLocalePathname();
|
||||
const params = useParams();
|
||||
|
||||
// Get locale from URL params, which should be more reliable than useLocale in this case
|
||||
const urlLocale = params.locale as string;
|
||||
|
||||
// Fallback to useLocale if params.locale is not available
|
||||
const defaultLocale = useLocale();
|
||||
const locale = urlLocale || defaultLocale;
|
||||
|
||||
console.log("pathname", pathname);
|
||||
console.log("locale from params", urlLocale);
|
||||
console.log("locale from hook", defaultLocale);
|
||||
// Remove the custom locale handling which is causing the inconsistency
|
||||
// Just use the standard Next-intl locale system
|
||||
|
||||
return (
|
||||
<div className="mt-4 dark:border-border/50 relative z-20 border-t">
|
||||
@ -42,7 +32,7 @@ export default function BlocksNav({ categories }: { categories: string[] }) {
|
||||
>
|
||||
<LocaleLink
|
||||
href={href}
|
||||
locale={locale}
|
||||
// Remove explicit locale prop to use the system default locale behavior
|
||||
className={cn(
|
||||
isActive && 'text-foreground!',
|
||||
'hover:bg-muted dark:text-muted-foreground hover:text-foreground flex h-7 w-fit items-center text-nowrap rounded-full px-2 text-sm text-zinc-700 lg:-mx-2 lg:px-3'
|
||||
|
@ -60,6 +60,10 @@ export function NavUser({ user, className }: NavUserProps) {
|
||||
// }
|
||||
|
||||
const setLocale = (nextLocale: Locale) => {
|
||||
if (currentLocale === nextLocale) {
|
||||
return;
|
||||
}
|
||||
|
||||
setCurrentLocale(nextLocale);
|
||||
|
||||
startTransition(() => {
|
||||
|
@ -37,6 +37,10 @@ export default function LocaleSelector() {
|
||||
}, [locale, setCurrentLocale]);
|
||||
|
||||
const onSelectChange = (nextLocale: Locale) => {
|
||||
if (locale === nextLocale) {
|
||||
return;
|
||||
}
|
||||
|
||||
setCurrentLocale(nextLocale);
|
||||
|
||||
startTransition(() => {
|
||||
|
@ -37,6 +37,10 @@ export default function LocaleSwitcher() {
|
||||
}, [locale, setCurrentLocale]);
|
||||
|
||||
const setLocale = (nextLocale: Locale) => {
|
||||
if (locale === nextLocale) {
|
||||
return;
|
||||
}
|
||||
|
||||
setCurrentLocale(nextLocale);
|
||||
|
||||
startTransition(() => {
|
||||
|
@ -66,6 +66,7 @@ export const publicRoutes = [
|
||||
|
||||
// pages
|
||||
'/blog(/.*)?',
|
||||
'/blocks(/.*)?',
|
||||
'/terms-of-service(/.*)?',
|
||||
'/privacy-policy(/.*)?',
|
||||
'/cookie-policy(/.*)?',
|
||||
|
Loading…
Reference in New Issue
Block a user