Skip to content

Commit 3f2b9f9

Browse files
committed
more updates
1 parent 2a654a7 commit 3f2b9f9

File tree

37 files changed

+145
-81
lines changed

37 files changed

+145
-81
lines changed

apps/nextjs-app/src/app/app/discussions/[discussionId]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { useParams } from 'next/navigation';
44
import { ErrorBoundary } from 'react-error-boundary';
55

6-
import { ContentLayout } from '@/components/layouts';
6+
import { ContentLayout } from '@/components/layouts/content-layout';
77
import { Spinner } from '@/components/ui/spinner';
88
import { Comments } from '@/features/comments/components/comments';
99
import { useDiscussion } from '@/features/discussions/api/get-discussion';

apps/nextjs-app/src/app/app/discussions/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { useQueryClient } from '@tanstack/react-query';
44

5-
import { ContentLayout } from '@/components/layouts';
5+
import { ContentLayout } from '@/components/layouts/content-layout';
66
import { getInfiniteCommentsQueryOptions } from '@/features/comments/api/get-comments';
77
import { CreateDiscussion } from '@/features/discussions/components/create-discussion';
88
import { DiscussionsList } from '@/features/discussions/components/discussions-list';

apps/nextjs-app/src/app/app/layout.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { ReactNode } from 'react';
22

3-
import { DashboardLayout } from '@/components/layouts';
3+
import { DashboardLayout } from '@/components/layouts/dashboard-layout';
4+
5+
export const metadata = {
6+
title: 'Dashboard',
7+
description: 'Dashboard',
8+
};
49

510
const AppLayout = ({ children }: { children: ReactNode }) => {
611
return <DashboardLayout>{children}</DashboardLayout>;

apps/nextjs-app/src/app/app/users/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { ContentLayout } from '@/components/layouts';
3+
import { ContentLayout } from '@/components/layouts/content-layout';
44
import { UsersList } from '@/features/users/components/users-list';
55
import { Authorization, ROLES } from '@/lib/authorization';
66

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
'use client';
2-
3-
import { usePathname } from 'next/navigation';
41
import { ReactNode } from 'react';
52

63
import { AuthLayout as AuthLayoutComponent } from '@/components/layouts/auth-layout';
74

8-
const AuthLayout = ({ children }: { children: ReactNode }) => {
9-
const pathname = usePathname();
10-
const isLoginPage = pathname === '/auth/login';
11-
const title = isLoginPage
12-
? 'Log in to your account'
13-
: 'Register your account';
5+
export const generateMetadata = (...args: any[]) => {
6+
console.log(args);
7+
return {
8+
title: 'Bulletproof React',
9+
description: 'Welcome to Bulletproof React',
10+
};
11+
};
1412

15-
return <AuthLayoutComponent title={title}>{children}</AuthLayoutComponent>;
13+
const AuthLayout = ({ children }: { children: ReactNode }) => {
14+
return <AuthLayoutComponent>{children}</AuthLayoutComponent>;
1615
};
1716

1817
export default AuthLayout;

apps/nextjs-app/src/app/layout.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { AppProvider } from '@/app/provider';
44

55
import '@/styles/globals.css';
66

7+
export const metadata = {
8+
title: 'Bulletproof React',
9+
description: 'Showcasing Best Practices For Building React Applications',
10+
};
11+
712
const RootLayout = ({ children }: { children: ReactNode }) => {
813
return (
914
<html lang="en">

apps/nextjs-app/src/app/page.tsx

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
1-
'use client';
2-
import { useRouter } from 'next/navigation';
3-
41
import { Button } from '@/components/ui/button';
5-
import { useUser } from '@/lib/auth';
6-
7-
// export const metadata = {
8-
// title: 'Bulletproof React',
9-
// description: 'Welcome to bulletproof react',
10-
// };
2+
import { Link } from '@/components/ui/link';
3+
import { checkLoggedIn } from '@/utils/auth';
114

125
const HomePage = () => {
13-
const router = useRouter();
14-
const user = useUser();
15-
16-
const handleStart = () => {
17-
if (user.data) {
18-
router.push('/app');
19-
} else {
20-
router.push('/auth/login');
21-
}
22-
};
6+
const isLoggedIn = checkLoggedIn();
237

248
return (
259
<div className="flex h-screen items-center bg-white">
@@ -31,27 +15,28 @@ const HomePage = () => {
3115
<p>Showcasing Best Practices For Building React Applications</p>
3216
<div className="mt-8 flex justify-center">
3317
<div className="inline-flex rounded-md shadow">
34-
<Button
35-
onClick={handleStart}
36-
icon={
37-
<svg
38-
xmlns="http://www.w3.org/2000/svg"
39-
className="size-6"
40-
fill="none"
41-
viewBox="0 0 24 24"
42-
stroke="currentColor"
43-
>
44-
<path
45-
strokeLinecap="round"
46-
strokeLinejoin="round"
47-
strokeWidth="2"
48-
d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"
49-
/>
50-
</svg>
51-
}
52-
>
53-
Get started
54-
</Button>
18+
<Link href={isLoggedIn ? '/app' : '/auth/login'}>
19+
<Button
20+
icon={
21+
<svg
22+
xmlns="http://www.w3.org/2000/svg"
23+
className="size-6"
24+
fill="none"
25+
viewBox="0 0 24 24"
26+
stroke="currentColor"
27+
>
28+
<path
29+
strokeLinecap="round"
30+
strokeLinejoin="round"
31+
strokeWidth="2"
32+
d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"
33+
/>
34+
</svg>
35+
}
36+
>
37+
Get started
38+
</Button>
39+
</Link>
5540
</div>
5641
<div className="ml-3 inline-flex">
5742
<a

apps/nextjs-app/src/app/public/discussions/[discussionId]/page.tsx

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,36 @@ import {
33
HydrationBoundary,
44
QueryClient,
55
} from '@tanstack/react-query';
6-
import { cookies } from 'next/headers';
76

87
import DiscussionPage from '@/app/app/discussions/[discussionId]/page';
98
import { getInfiniteCommentsQueryOptions } from '@/features/comments/api/get-comments';
10-
import { getDiscussionQueryOptions } from '@/features/discussions/api/get-discussion';
9+
import {
10+
getDiscussion,
11+
getDiscussionQueryOptions,
12+
} from '@/features/discussions/api/get-discussion';
1113

12-
const preloadData = async (discussionId: string) => {
13-
const queryClient = new QueryClient();
14+
export const generateMetadata = async ({
15+
params,
16+
}: {
17+
params: { discussionId: string };
18+
}) => {
19+
const discussion = await getDiscussion({
20+
discussionId: params.discussionId,
21+
});
22+
23+
const name = discussion.data.title;
1424

15-
const cookieStore = cookies();
25+
return {
26+
title: name,
27+
};
28+
};
1629

17-
const cookie = cookieStore.get('bulletproof_react_app_token')?.value;
30+
const preloadData = async (discussionId: string) => {
31+
const queryClient = new QueryClient();
1832

19-
await queryClient.prefetchQuery(
20-
getDiscussionQueryOptions(discussionId, cookie),
21-
);
33+
await queryClient.prefetchQuery(getDiscussionQueryOptions(discussionId));
2234
await queryClient.prefetchInfiniteQuery(
23-
getInfiniteCommentsQueryOptions(discussionId, cookie),
35+
getInfiniteCommentsQueryOptions(discussionId),
2436
);
2537

2638
return {

apps/nextjs-app/src/components/layouts/auth-layout.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
'use client';
22

33
import { useRouter, usePathname } from 'next/navigation';
4-
import * as React from 'react';
5-
import { useEffect } from 'react';
4+
import { ReactNode, useEffect, Suspense } from 'react';
65
import { ErrorBoundary } from 'react-error-boundary';
76

87
import { Link } from '@/components/ui/link';
98
import { Spinner } from '@/components/ui/spinner';
109
import { useUser } from '@/lib/auth';
1110

1211
type LayoutProps = {
13-
children: React.ReactNode;
14-
title: string;
12+
children: ReactNode;
1513
};
1614

17-
// export const metadata = {
18-
// title: 'Bulletproof React',
19-
// description: 'Welcome to bulletproof react',
20-
// };
21-
22-
export const AuthLayout = ({ children, title }: LayoutProps) => {
15+
export const AuthLayout = ({ children }: LayoutProps) => {
2316
const user = useUser();
24-
2517
const router = useRouter();
2618
const pathname = usePathname();
19+
const isLoginPage = pathname === '/auth/login';
20+
const title = isLoginPage
21+
? 'Log in to your account'
22+
: 'Register your account';
2723

2824
useEffect(() => {
2925
if (user.data) {
@@ -32,7 +28,7 @@ export const AuthLayout = ({ children, title }: LayoutProps) => {
3228
}, [user.data, router]);
3329

3430
return (
35-
<React.Suspense
31+
<Suspense
3632
fallback={
3733
<div className="flex size-full items-center justify-center">
3834
<Spinner size="xl" />
@@ -60,6 +56,6 @@ export const AuthLayout = ({ children, title }: LayoutProps) => {
6056
</div>
6157
</div>
6258
</ErrorBoundary>
63-
</React.Suspense>
59+
</Suspense>
6460
);
6561
};

apps/nextjs-app/src/components/layouts/content-layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as React from 'react';
1+
import { ReactNode } from 'react';
22

33
type ContentLayoutProps = {
4-
children: React.ReactNode;
4+
children: ReactNode;
55
title: string;
66
};
77

0 commit comments

Comments
 (0)