|
1 | 1 | import Link from "next/link";
|
2 | 2 |
|
3 |
| -import { CreatePost } from "~/app/_components/create-post"; |
| 3 | +import { LatestPost } from "~/app/_components/post"; |
4 | 4 | import { getServerAuthSession } from "~/server/auth";
|
5 |
| -import { api } from "~/trpc/server"; |
| 5 | +import { api, HydrateClient } from "~/trpc/server"; |
6 | 6 |
|
7 | 7 | export default async function Home() {
|
8 | 8 | const hello = await api.post.hello({ text: "from tRPC" });
|
9 | 9 | const session = await getServerAuthSession();
|
10 | 10 |
|
11 |
| - return ( |
12 |
| - <main className="flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-[#2e026d] to-[#15162c] text-white"> |
13 |
| - <div className="container flex flex-col items-center justify-center gap-12 px-4 py-16 "> |
14 |
| - <h1 className="text-5xl font-extrabold tracking-tight sm:text-[5rem]"> |
15 |
| - Create <span className="text-[hsl(280,100%,70%)]">T3</span> App |
16 |
| - </h1> |
17 |
| - <div className="grid grid-cols-1 gap-4 sm:grid-cols-2 md:gap-8"> |
18 |
| - <Link |
19 |
| - className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 hover:bg-white/20" |
20 |
| - href="https://create.t3.gg/en/usage/first-steps" |
21 |
| - target="_blank" |
22 |
| - > |
23 |
| - <h3 className="text-2xl font-bold">First Steps →</h3> |
24 |
| - <div className="text-lg"> |
25 |
| - Just the basics - Everything you need to know to set up your |
26 |
| - database and authentication. |
27 |
| - </div> |
28 |
| - </Link> |
29 |
| - <Link |
30 |
| - className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 hover:bg-white/20" |
31 |
| - href="https://create.t3.gg/en/introduction" |
32 |
| - target="_blank" |
33 |
| - > |
34 |
| - <h3 className="text-2xl font-bold">Documentation →</h3> |
35 |
| - <div className="text-lg"> |
36 |
| - Learn more about Create T3 App, the libraries it uses, and how to |
37 |
| - deploy it. |
38 |
| - </div> |
39 |
| - </Link> |
40 |
| - </div> |
41 |
| - <div className="flex flex-col items-center gap-2"> |
42 |
| - <p className="text-2xl text-white"> |
43 |
| - {hello ? hello.greeting : "Loading tRPC query..."} |
44 |
| - </p> |
| 11 | + void api.post.getLatest.prefetch(); |
45 | 12 |
|
46 |
| - <div className="flex flex-col items-center justify-center gap-4"> |
47 |
| - <p className="text-center text-2xl text-white"> |
48 |
| - {session && <span>Logged in as {session.user?.name}</span>} |
49 |
| - </p> |
| 13 | + return ( |
| 14 | + <HydrateClient> |
| 15 | + <main className="flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-[#2e026d] to-[#15162c] text-white"> |
| 16 | + <div className="container flex flex-col items-center justify-center gap-12 px-4 py-16 "> |
| 17 | + <h1 className="text-5xl font-extrabold tracking-tight sm:text-[5rem]"> |
| 18 | + Create <span className="text-[hsl(280,100%,70%)]">T3</span> App |
| 19 | + </h1> |
| 20 | + <div className="grid grid-cols-1 gap-4 sm:grid-cols-2 md:gap-8"> |
50 | 21 | <Link
|
51 |
| - href={session ? "/api/auth/signout" : "/api/auth/signin"} |
52 |
| - className="rounded-full bg-white/10 px-10 py-3 font-semibold no-underline transition hover:bg-white/20" |
| 22 | + className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 hover:bg-white/20" |
| 23 | + href="https://create.t3.gg/en/usage/first-steps" |
| 24 | + target="_blank" |
53 | 25 | >
|
54 |
| - {session ? "Sign out" : "Sign in"} |
| 26 | + <h3 className="text-2xl font-bold">First Steps →</h3> |
| 27 | + <div className="text-lg"> |
| 28 | + Just the basics - Everything you need to know to set up your |
| 29 | + database and authentication. |
| 30 | + </div> |
| 31 | + </Link> |
| 32 | + <Link |
| 33 | + className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 hover:bg-white/20" |
| 34 | + href="https://create.t3.gg/en/introduction" |
| 35 | + target="_blank" |
| 36 | + > |
| 37 | + <h3 className="text-2xl font-bold">Documentation →</h3> |
| 38 | + <div className="text-lg"> |
| 39 | + Learn more about Create T3 App, the libraries it uses, and how |
| 40 | + to deploy it. |
| 41 | + </div> |
55 | 42 | </Link>
|
56 | 43 | </div>
|
57 |
| - </div> |
58 |
| - |
59 |
| - <CrudShowcase /> |
60 |
| - </div> |
61 |
| - </main> |
62 |
| - ); |
63 |
| -} |
64 |
| - |
65 |
| -async function CrudShowcase() { |
66 |
| - const session = await getServerAuthSession(); |
67 |
| - if (!session?.user) return null; |
68 |
| - |
69 |
| - const latestPost = await api.post.getLatest(); |
| 44 | + <div className="flex flex-col items-center gap-2"> |
| 45 | + <p className="text-2xl text-white"> |
| 46 | + {hello ? hello.greeting : "Loading tRPC query..."} |
| 47 | + </p> |
70 | 48 |
|
71 |
| - return ( |
72 |
| - <div className="w-full max-w-xs"> |
73 |
| - {latestPost ? ( |
74 |
| - <p className="truncate">Your most recent post: {latestPost.name}</p> |
75 |
| - ) : ( |
76 |
| - <p>You have no posts yet.</p> |
77 |
| - )} |
| 49 | + <div className="flex flex-col items-center justify-center gap-4"> |
| 50 | + <p className="text-center text-2xl text-white"> |
| 51 | + {session && <span>Logged in as {session.user?.name}</span>} |
| 52 | + </p> |
| 53 | + <Link |
| 54 | + href={session ? "/api/auth/signout" : "/api/auth/signin"} |
| 55 | + className="rounded-full bg-white/10 px-10 py-3 font-semibold no-underline transition hover:bg-white/20" |
| 56 | + > |
| 57 | + {session ? "Sign out" : "Sign in"} |
| 58 | + </Link> |
| 59 | + </div> |
| 60 | + </div> |
78 | 61 |
|
79 |
| - <CreatePost /> |
80 |
| - </div> |
| 62 | + {session?.user && <LatestPost />} |
| 63 | + </div> |
| 64 | + </main> |
| 65 | + </HydrateClient> |
81 | 66 | );
|
82 | 67 | }
|
0 commit comments