Skip to content

Commit e42c09d

Browse files
authored
Merge pull request #37 from hammer-code/refactor-files
refactor components file and name
2 parents 9760ff7 + 84acfdc commit e42c09d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+315
-270
lines changed

Diff for: .editorconfig

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
# Use 4 spaces for the Python files
13+
[*.py]
14+
indent_size = 4
15+
max_line_length = 80
16+
17+
# The JSON files contain newlines inconsistently
18+
[*.json]
19+
insert_final_newline = ignore
20+
21+
# Minified JavaScript files shouldn't be changed
22+
[**.min.js]
23+
indent_style = ignore
24+
insert_final_newline = ignore
25+
26+
# Makefiles always use tabs for indentation
27+
[Makefile]
28+
indent_style = tab
29+
30+
# Batch files use tabs for indentation
31+
[*.bat]
32+
indent_style = tab
33+
34+
[*.md]
35+
trim_trailing_whitespace = false
36+

Diff for: src/app/[locale]/about/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import AboutPage from "@/features/about";
1+
import { AboutPage } from "@/features/about";
22

33
const About = () => {
44
return <AboutPage />;

Diff for: src/app/[locale]/certificates/[slug]/page.tsx

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
import { notFound } from "next/navigation";
2+
import { EventCertificate, CertificatePage } from "@/features/certificate";
23

3-
import Certificate from "@/features/certificate/Certificate";
4-
import { CertificateType } from "@/features/certificate/types";
4+
function getCertificateData(slug: string): Promise<EventCertificate> {
5+
return fetch(`https://moonlight.hammercode.org/v1/certificates/${slug}`).then((res) => res.json());
6+
}
57

6-
type Props = {
8+
type CertificateDetailProps = {
79
params: {
810
slug: string;
911
};
1012
};
1113

12-
const CertificateDetail = async ({ params }: Props) => {
13-
const data = await fetch(`https://moonlight.hammercode.org/v1/certificates/${params.slug}`);
14-
const certificateDetail: CertificateType = await data.json();
14+
const CertificateDetail = async ({ params }: CertificateDetailProps) => {
15+
const data = await getCertificateData(params.slug);
1516

16-
if (!certificateDetail.name) {
17+
if (!data.name) {
1718
return notFound();
1819
}
1920

20-
return <Certificate certificate={certificateDetail} />;
21+
return <CertificatePage certificate={data} />;
2122
};
2223

2324
export default CertificateDetail;

Diff for: src/app/[locale]/events/[id]/page.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import EventDetail from "@/features/events/components/EventDetail";
1+
import { EventDetailPage } from "@/features/events";
22

33
const EventsDetail = ({ params }: { params: { id: string } }) => {
4-
return <EventDetail params={params} />;
4+
return <EventDetailPage eventId={params.id} />;
55
};
66

77
export default EventsDetail;

Diff for: src/app/[locale]/events/page.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import EventsPage from "@/features/events";
1+
import { EventListPage } from "@/features/events";
22

3-
const Events = () => {
4-
return <EventsPage />;
3+
const EventList = () => {
4+
return <EventListPage />;
55
};
6-
export default Events;
6+
7+
export default EventList;

Diff for: src/app/[locale]/layout.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { NextIntlClientProvider } from "next-intl";
33
import { getMessages, getTranslations, unstable_setRequestLocale } from "next-intl/server";
44
import { Sora } from "next/font/google";
55
import "./globals.css";
6-
import Wrapper from "@/components/layout/wrapper";
6+
import WrapperLayout from "@/components/layout/WrapperLayout";
77
import { locales } from "@/lib/config";
88
import { notFound } from "next/navigation";
99
const sora = Sora({ subsets: ["latin"] });
@@ -42,7 +42,7 @@ export default async function LocaleRootLayout({ children, params: { locale } }:
4242
</head>
4343
<body className={`${sora.className} pt-8`}>
4444
<NextIntlClientProvider messages={messages}>
45-
<Wrapper>{children}</Wrapper>
45+
<WrapperLayout>{children}</WrapperLayout>
4646
</NextIntlClientProvider>
4747
</body>
4848
</html>

Diff for: src/app/[locale]/page.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import Home from "@/features/home";
2+
import { HomePage } from "@/features/home";
33
import { locales } from "@/lib/config";
44
import { unstable_setRequestLocale } from "next-intl/server";
55
import { notFound } from "next/navigation";
@@ -10,9 +10,9 @@ type Props = {
1010
};
1111
};
1212

13-
export default function HomePage({ params: { locale } }: Props) {
13+
export default function Home({ params: { locale } }: Props) {
1414
if (!locales.includes(locale as any)) notFound();
1515
unstable_setRequestLocale(locale);
1616

17-
return <Home />;
17+
return <HomePage />;
1818
}

Diff for: src/components/common/locale-toggle/index.tsx renamed to src/components/common/LocaleToggle/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useParams } from "next/navigation";
44

55
import { usePathname, useRouter } from "@/lib/navigation";
66
import { Locale } from "@/lib/i18n";
7-
import { Button } from "@/components/ui/button";
7+
import { Button } from "@/components/ui/Button";
88

99
const LocaleToggle = () => {
1010
const locale = useLocale();

Diff for: src/components/common/mode-toggle/index.tsx renamed to src/components/common/ThemeToggle/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as React from "react";
22
import { Moon, Sun } from "lucide-react";
33
import { useTheme } from "next-themes";
44

5-
import { Button } from "@/components/ui/button";
5+
import { Button } from "@/components/ui/Button";
66

7-
export function ModeToggle() {
7+
export function ThemeToggle() {
88
const { theme, setTheme } = useTheme();
99

1010
const handleSetTheme = () => {

Diff for: src/components/common/footer/Footer.tsx renamed to src/components/common/footer/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import { dataFooter } from "./constants";
33
import { Link } from "@/lib/navigation";
4-
import { Button } from "@/components/ui/button";
4+
import { Button } from "@/components/ui/Button";
55
import { useTranslations } from "next-intl";
66

77
const Footer = () => {

Diff for: src/components/common/navbar/NavbarList.tsx renamed to src/components/common/navbar/NavItem.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { pathnames } from "@/lib/config";
44

55
export type NavbarListProps<Pathname extends keyof typeof pathnames> = ComponentProps<typeof Link<Pathname>>;
66

7-
function NavbarList<Pathname extends keyof typeof pathnames>({ href, onClick, ...rest }: NavbarListProps<Pathname>) {
7+
function NavItem<Pathname extends keyof typeof pathnames>({ href, onClick, ...rest }: NavbarListProps<Pathname>) {
88
return (
99
<Link href={href} onClick={onClick}>
1010
<span>{rest.title}</span>
1111
</Link>
1212
);
1313
}
1414

15-
export default NavbarList;
15+
export default NavItem;

Diff for: src/components/common/navbar/constant.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { NavbarListProps } from "./NavbarList";
1+
import { NavbarListProps } from "./NavItem";
22
import { ValidPathnames } from "./type";
33

4-
export const LINK: NavbarListProps<ValidPathnames>[] = [
4+
export const LINKS: NavbarListProps<ValidPathnames>[] = [
55
{
66
id: "1",
77
href: "/about",
@@ -10,8 +10,4 @@ export const LINK: NavbarListProps<ValidPathnames>[] = [
1010
id: "2",
1111
href: "/events",
1212
},
13-
// {
14-
// id: "3",
15-
// href: "/contact",
16-
// },
1713
];

Diff for: src/components/common/navbar/index.tsx

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { Link } from "@/lib/navigation";
2-
3-
import NavbarList from "./NavbarList";
4-
import { ModeToggle } from "../mode-toggle";
2+
import NavItem from "./NavItem";
3+
import { ThemeToggle } from "../ThemeToggle";
54
import { useTranslations } from "next-intl";
6-
import LocaleToggle from "../locale-toggle";
7-
import { LINK } from "./constant";
8-
import Sidebar from "../sidebar";
9-
import AnnouncementLayout from "@/components/layout/announcement";
5+
import LocaleToggle from "../LocaleToggle";
6+
import { LINKS } from "./constant";
7+
import Sidebar from "../Sidebar";
8+
import AnnouncementLayout from "@/components/layout/AnnouncementLayout";
109

1110
const Navbar = () => {
1211
const t = useTranslations("Layout");
@@ -21,11 +20,11 @@ const Navbar = () => {
2120
</Link>
2221

2322
<nav className="lg:flex items-center gap-7 hidden">
24-
{LINK.map(({ href, id }) => (
25-
<NavbarList key={id} href={href} title={t(`navbar.link-${id}`)} />
23+
{LINKS.map(({ href, id }) => (
24+
<NavItem key={id} href={href} title={t(`navbar.link-${id}`)} />
2625
))}
2726
<div className="flex gap-2 items-center">
28-
<ModeToggle />
27+
<ThemeToggle />
2928
<LocaleToggle />
3029
</div>
3130
</nav>

Diff for: src/components/common/sidebar/index.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { Menu } from "lucide-react";
44
import Link from "next/link";
55
import { useTranslations } from "next-intl";
66

7-
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, SheetTrigger } from "@/components/ui/sheet";
8-
import NavbarList from "../navbar/NavbarList";
9-
import { ModeToggle } from "../mode-toggle";
10-
import LocaleToggle from "../locale-toggle";
11-
import { LINK } from "../navbar/constant";
7+
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, SheetTrigger } from "@/components/ui/Sheet";
8+
import NavItem from "../Navbar/NavItem";
9+
import { ThemeToggle } from "../ThemeToggle";
10+
import LocaleToggle from "../LocaleToggle";
11+
import { LINKS } from "../Navbar/constant";
1212

1313
const Sidebar: FC = () => {
1414
const t = useTranslations("Layout");
@@ -28,11 +28,11 @@ const Sidebar: FC = () => {
2828
</SheetTitle>
2929
<SheetDescription>
3030
<nav className="flex flex-col items-center gap-4 mt-2">
31-
{LINK.map(({ href, id }) => (
32-
<NavbarList key={id} href={href} title={t(`navbar.link-${id}`)} onClick={() => setIsOpen(false)} />
31+
{LINKS.map(({ href, id }) => (
32+
<NavItem key={id} href={href} title={t(`navbar.link-${id}`)} onClick={() => setIsOpen(false)} />
3333
))}
3434
<div className="flex gap-2 items-center">
35-
<ModeToggle />
35+
<ThemeToggle />
3636
<LocaleToggle />
3737
</div>
3838
</nav>

Diff for: src/components/layout/announcement/index.tsx renamed to src/components/layout/AnnouncementLayout/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Announcement } from "@/components/ui/announcement";
1+
import Announcement from "@/components/ui/Announcement";
22
import { useTranslations } from "next-intl";
33

44
export default function AnnouncementLayout() {
@@ -7,6 +7,7 @@ export default function AnnouncementLayout() {
77
message: t("pdd-2024"),
88
url: "https://pdd2024.hammercode.org/",
99
};
10+
1011
return (
1112
<div>
1213
<Announcement message={pdd.message} url={pdd.url} />

Diff for: src/components/layout/wrapper/index.tsx renamed to src/components/layout/WrapperLayout/index.tsx

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

3-
import Navbar from "@/components/common/navbar";
4-
import { ThemeProvider } from "../theme-provider";
5-
import Footer from "@/components/common/footer/Footer";
3+
import Navbar from "@/components/common/Navbar";
4+
import { ThemeProvider } from "./ThemeProvider";
5+
import Footer from "@/components/common/Footer";
66
import { useParams, usePathname } from "next/navigation";
77

8-
const Wrapper = ({ children }: { children: React.ReactNode }) => {
8+
const WrapperLayout = ({ children }: { children: React.ReactNode }) => {
99
const params = useParams();
1010
const pathname = usePathname();
1111
const isCertificateDetailPage = !!params?.slug && pathname.includes("certificates");
@@ -24,4 +24,4 @@ const Wrapper = ({ children }: { children: React.ReactNode }) => {
2424
</ThemeProvider>
2525
);
2626
};
27-
export default Wrapper;
27+
export default WrapperLayout;

Diff for: src/components/ui/announcement.test.tsx renamed to src/components/ui/Announcement/Announcement.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { render } from "@testing-library/react";
2-
import { Announcement } from "./announcement";
2+
import Announcement from "./";
33
import userEvent from "@testing-library/user-event";
44

55
describe("Announcement", () => {

Diff for: src/components/ui/announcement.tsx renamed to src/components/ui/Announcement/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ function Announcement({ message, url }: AnnouncementProps) {
3030
);
3131
}
3232

33-
export { Announcement };
33+
export default Announcement;

Diff for: src/components/ui/avatar.tsx renamed to src/components/ui/Avatar/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ const AvatarFallback = React.forwardRef<
3838
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName;
3939

4040
export { Avatar, AvatarImage, AvatarFallback };
41+
export default Avatar;

Diff for: src/components/ui/badge.tsx renamed to src/components/ui/Badge/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ function Badge({ className, variant, ...props }: BadgeProps) {
2929
return <div className={cn(badgeVariants({ variant }), className)} {...props} />;
3030
}
3131

32-
export { Badge, badgeVariants };
32+
export default Badge;
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: src/components/ui/carousel.tsx renamed to src/components/ui/Carousel/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import useEmblaCarousel, { type UseEmblaCarouselType } from "embla-carousel-reac
55
import { ArrowLeft, ArrowRight } from "lucide-react";
66

77
import { cn } from "@/lib/utils";
8-
import { Button } from "@/components/ui/button";
8+
import { Button } from "@/components/ui/Button";
99

1010
// import Autoplay from "embla-carousel-autoplay";
1111

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: src/components/ui/skeleton.tsx renamed to src/components/ui/Skeleton/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ function Skeleton({ className, ...props }: React.HTMLAttributes<HTMLDivElement>)
44
return <div className={cn("animate-pulse rounded-md bg-muted", className)} {...props} />;
55
}
66

7-
export { Skeleton };
7+
export default Skeleton;

Diff for: src/components/ui/title.tsx renamed to src/components/ui/TitleContainer/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type TitleBarProps = {
55
className?: string;
66
};
77

8-
const TitleBar = ({ children, className }: TitleBarProps) => {
8+
const TitleContainer = ({ children, className }: TitleBarProps) => {
99
return (
1010
<div className={cn("flex items-stretch w-fit", className)}>
1111
<div className="w-1 bg-primary rounded-r-xl" />
@@ -14,4 +14,4 @@ const TitleBar = ({ children, className }: TitleBarProps) => {
1414
);
1515
};
1616

17-
export { TitleBar };
17+
export default TitleContainer;
File renamed without changes.

0 commit comments

Comments
 (0)