Skip to content

Commit

Permalink
Merge pull request #25 from hackerspace-ntnu/naming-conventions
Browse files Browse the repository at this point in the history
Rename main route group, enforce naming conventions for layouts and pages
  • Loading branch information
michaelbrusegard authored Aug 21, 2024
2 parents 1a1dd3b + 17a2498 commit 3cba1ad
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 17 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,8 @@ We are using [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.
- To keep the code as consistent as possible use functions for react components or hooks instead of const variables with arrow function syntax. An exception is when using the forwardRef hook or when creating compound components.
- Only use default export for pages or layouts etc. since it is required by Next.js. For everything else use named exports. This is to make it easier to find the components in the codebase or change them without ending up with different names for the same component.
- Use `type` instead of `interface` for typescript types. This is to keep the code consistent and to make it easier to read. Aldso `type` is more flexible than `interface` since it can be used for unions and intersections.

### Naming conventions

- All layout components should end with Layout. For example: `DefaultLayout`.
- All page components should end with Page to make it clear it is a whole page. For example: `AboutPage`.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function generateMetadata({
};
}

export default function About({
export default function AboutPage({
params: { locale },
}: {
params: { locale: string };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function generateMetadata({
};
}

export default function Events({
export default function EventsPage({
params: { locale },
}: {
params: { locale: string };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { Footer } from '@/components/layout/Footer';
import { Header } from '@/components/layout/Header';
import { Main } from '@/components/layout/Main';

type DashboardProps = {
type DefaultLayoutProps = {
children: React.ReactNode;
params: { locale: string };
};

export default function Dashboard({
export default function DefaultLayout({
children,
params: { locale },
}: DashboardProps) {
}: DefaultLayoutProps) {
unstable_setRequestLocale(locale);
return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { Link } from '@/lib/navigation';

import { Button } from '@/components/ui/Button';

type NewsHeaderProps = {
type NewsHeaderLayoutProps = {
children: React.ReactNode;
params: { locale: string };
};

export default function NewsHeader({
export default function NewsHeaderLayout({
children,
params: { locale },
}: NewsHeaderProps) {
}: NewsHeaderLayoutProps) {
unstable_setRequestLocale(locale);
const t = useTranslations('news');
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function generateMetadata({
};
}

export default function News({
export default function NewsPage({
params: { locale },
searchParams,
}: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function generateMetadata({
};
}

export default function Article({
export default function ArticlePage({
params,
}: {
params: { locale: string; article: string };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { unstable_setRequestLocale } from 'next-intl/server';

export default function Home({
export default function HomePage({
params: { locale },
}: {
params: { locale: string };
Expand Down
8 changes: 4 additions & 4 deletions src/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { cx } from '@/lib/utils';

import { RootProviders } from '@/components/providers/RootProviders';

type LocalelayoutProps = {
type LocaleLayoutProps = {
children: React.ReactNode;
params: { locale: string };
};
Expand All @@ -30,7 +30,7 @@ export function generateStaticParams() {

export async function generateMetadata({
params: { locale },
}: Omit<LocalelayoutProps, 'children'>) {
}: Omit<LocaleLayoutProps, 'children'>) {
const t = await getTranslations({ locale, namespace: 'meta' });

return {
Expand Down Expand Up @@ -71,10 +71,10 @@ export async function generateMetadata({
};
}

export default function Localelayout({
export default function LocaleLayout({
children,
params: { locale },
}: LocalelayoutProps) {
}: LocaleLayoutProps) {
if (!locales.includes(locale)) notFound();
unstable_setRequestLocale(locale);
return (
Expand Down
4 changes: 2 additions & 2 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import '@/styles/globals.css';

type RootlayoutProps = {
type RootLayoutProps = {
children: React.ReactNode;
};

export default function Rootlayout({ children }: RootlayoutProps) {
export default function RootLayout({ children }: RootLayoutProps) {
return children;
}

0 comments on commit 3cba1ad

Please sign in to comment.