Skip to content

Commit dc656bc

Browse files
committed
refactor navigation and locales
1 parent e42c09d commit dc656bc

File tree

20 files changed

+58
-54
lines changed

20 files changed

+58
-54
lines changed

src/app/[locale]/layout.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getMessages, getTranslations, unstable_setRequestLocale } from "next-in
44
import { Sora } from "next/font/google";
55
import "./globals.css";
66
import WrapperLayout from "@/components/layout/WrapperLayout";
7-
import { locales } from "@/lib/config";
7+
import { locales } from "@/lib/locales";
88
import { notFound } from "next/navigation";
99
const sora = Sora({ subsets: ["latin"] });
1010

src/app/[locale]/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { HomePage } from "@/features/home";
3-
import { locales } from "@/lib/config";
3+
import { locales } from "@/lib/locales";
44
import { unstable_setRequestLocale } from "next-intl/server";
55
import { notFound } from "next/navigation";
66

src/app/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { unstable_setRequestLocale } from "next-intl/server";
22
import { redirect } from "@/lib/navigation";
33
import { notFound } from "next/navigation";
4-
import { locales } from "@/lib/config";
4+
import { locales } from "@/lib/locales";
55

66
type Props = {
77
params: {

src/components/common/LocaleToggle/index.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useTransition } from "react";
22
import { useLocale } from "next-intl";
33
import { useParams } from "next/navigation";
4-
54
import { usePathname, useRouter } from "@/lib/navigation";
65
import { Locale } from "@/lib/i18n";
76
import { Button } from "@/components/ui/Button";

src/components/common/footer/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from "react";
22
import { dataFooter } from "./constants";
3-
import { Link } from "@/lib/navigation";
43
import { Button } from "@/components/ui/Button";
54
import { useTranslations } from "next-intl";
5+
import { Link } from "@/lib/navigation";
66

77
const Footer = () => {
88
const date = new Date();

src/components/common/navbar/NavItem.tsx

-15
This file was deleted.

src/components/common/navbar/constant.ts

-13
This file was deleted.

src/components/common/sidebar/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import Link from "next/link";
55
import { useTranslations } from "next-intl";
66

77
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, SheetTrigger } from "@/components/ui/Sheet";
8-
import NavItem from "../Navbar/NavItem";
8+
import NavLink from "../../../lib/navigation/NavLink";
99
import { ThemeToggle } from "../ThemeToggle";
1010
import LocaleToggle from "../LocaleToggle";
11-
import { LINKS } from "../Navbar/constant";
11+
import { LINKS } from "../../layout/Navbar/constant";
1212

1313
const Sidebar: FC = () => {
1414
const t = useTranslations("Layout");
@@ -29,7 +29,7 @@ const Sidebar: FC = () => {
2929
<SheetDescription>
3030
<nav className="flex flex-col items-center gap-4 mt-2">
3131
{LINKS.map(({ href, id }) => (
32-
<NavItem key={id} href={href} title={t(`navbar.link-${id}`)} onClick={() => setIsOpen(false)} />
32+
<NavLink key={id} href={href} title={t(`navbar.link-${id}`)} onClick={() => setIsOpen(false)} />
3333
))}
3434
<div className="flex gap-2 items-center">
3535
<ThemeToggle />
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { NavLinkProps } from "../../../lib/navigation/NavLink";
2+
import { ValidPathnames } from "../../../lib/navigation/types";
3+
4+
export const LINKS: NavLinkProps<ValidPathnames>[] = [
5+
{
6+
id: "1",
7+
href: "/about",
8+
},
9+
{
10+
id: "2",
11+
href: "/events",
12+
},
13+
];

src/components/common/navbar/index.tsx src/components/layout/Navbar/index.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Link } from "@/lib/navigation";
2-
import NavItem from "./NavItem";
3-
import { ThemeToggle } from "../ThemeToggle";
2+
import NavLink from "../../../lib/navigation/NavLink";
3+
import { ThemeToggle } from "../../common/ThemeToggle";
44
import { useTranslations } from "next-intl";
5-
import LocaleToggle from "../LocaleToggle";
5+
import LocaleToggle from "../../common/LocaleToggle";
66
import { LINKS } from "./constant";
7-
import Sidebar from "../Sidebar";
7+
import Sidebar from "../../common/Sidebar";
88
import AnnouncementLayout from "@/components/layout/AnnouncementLayout";
99

1010
const Navbar = () => {
@@ -21,7 +21,7 @@ const Navbar = () => {
2121

2222
<nav className="lg:flex items-center gap-7 hidden">
2323
{LINKS.map(({ href, id }) => (
24-
<NavItem key={id} href={href} title={t(`navbar.link-${id}`)} />
24+
<NavLink key={id} href={href} title={t(`navbar.link-${id}`)} />
2525
))}
2626
<div className="flex gap-2 items-center">
2727
<ThemeToggle />

src/components/layout/WrapperLayout/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import Navbar from "@/components/common/Navbar";
3+
import Navbar from "@/components/layout/Navbar";
44
import { ThemeProvider } from "./ThemeProvider";
55
import Footer from "@/components/common/Footer";
66
import { useParams, usePathname } from "next/navigation";

src/features/events/EventListPage.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { eventsService } from "@/services/events";
66
import EventCardV2 from "./components/EventCardV2";
77
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/Select";
88
import { TechEvent } from "./types";
9-
import { eventsData } from "./constants";
9+
import { mockEvents } from "./constants";
1010

1111
const EventListPage = () => {
1212
const t = useTranslations("EventsPage");
@@ -56,7 +56,7 @@ const EventListPage = () => {
5656
<EventCardV2 data={event} />
5757
</Link>
5858
))}
59-
{eventsData.map((event) => (
59+
{mockEvents.map((event) => (
6060
<Link key={event.id} href={`/events/${event.id}`}>
6161
<EventCardV2 data={event} />
6262
</Link>

src/features/events/components/EventBreadcrumb.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
BreadcrumbLink,
88
BreadcrumbSeparator,
99
} from "@/components/ui/Breadcrumb";
10-
import { LINKS } from "@/components/common/Navbar/constant";
10+
import { LINKS } from "@/components/layout/Navbar/constant";
1111

1212
const EventBreadcrumbs = () => {
1313
const t = useTranslations("Layout");

src/features/events/constants.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CalendarRange, Clock, MapPin } from "lucide-react";
22
import { EventInfoType, TechEvent } from "./types";
33

4-
export const eventsData: TechEvent[] = [
4+
export const mockEvents: TechEvent[] = [
55
{
66
id: 1,
77
title: "Advanced Frontend Workshop",

src/lib/i18n.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { notFound } from "next/navigation";
44
import { getRequestConfig } from "next-intl/server";
5-
import { locales } from "./config";
5+
import { locales } from "./locales";
66

77
export type Locale = (typeof locales)[number];
88

src/lib/locales.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const defaultLocale = "id" as const;
2+
export const locales = ["en", "id"] as const;
3+
4+
export type Locales = typeof locales;

src/lib/navigation/NavLink.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Link } from "@/lib/navigation";
2+
import { ComponentProps } from "react";
3+
import { pathnames } from "@/lib/navigation/config";
4+
5+
export type NavLinkProps<Pathname extends keyof typeof pathnames> = ComponentProps<typeof Link<Pathname>>;
6+
7+
function NavLink<Pathname extends keyof typeof pathnames>({ href, onClick, ...rest }: NavLinkProps<Pathname>) {
8+
return (
9+
<Link href={href} onClick={onClick}>
10+
<span>{rest.title}</span>
11+
</Link>
12+
);
13+
}
14+
15+
export default NavLink;

src/lib/config.ts src/lib/navigation/config.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { Pathnames, LocalePrefix } from "next-intl/routing";
2-
3-
export const defaultLocale = "id" as const;
4-
export const locales = ["en", "id"] as const;
5-
6-
export type Locales = typeof locales;
2+
import { Locales } from "../locales";
73

84
export const pathnames: Pathnames<Locales> = {
95
"/": "/",
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { createLocalizedPathnamesNavigation } from "next-intl/navigation";
2-
import { locales, pathnames, localePrefix } from "./config";
2+
import { pathnames, localePrefix } from "./config";
3+
import { locales } from "../locales";
4+
35
export const { Link, getPathname, redirect, usePathname, useRouter } = createLocalizedPathnamesNavigation({
46
locales,
57
pathnames,
68
localePrefix,
79
});
10+
11+
export { default as NavLink } from "./NavLink";
12+
export * from "./types";

src/components/common/navbar/type.ts src/lib/navigation/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { pathnames } from "@/lib/config";
1+
import { pathnames } from "@/lib/navigation/config";
22

33
export type PathnamesKeys = keyof typeof pathnames;
44
export type PathnameValues = {

0 commit comments

Comments
 (0)