-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
65 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,47 @@ | ||
import { type NextPage } from "next"; | ||
import type { GetStaticProps, NextPage } from "next"; | ||
import Head from "next/head"; | ||
import { api } from "~/utils/api"; | ||
import { PageLayout } from "~/components/Layout"; | ||
import { PostView } from "~/components/PostView"; | ||
import { generateSSGHelper } from "~/server/helpers/ssgHelper"; | ||
|
||
const SinglePostPage: NextPage<{ id: string }> = ({ id }) => { | ||
const { data } = api.posts.getById.useQuery(id); | ||
|
||
if (!data) return <div>404</div>; | ||
|
||
const SinglePostPage: NextPage = () => { | ||
return ( | ||
<> | ||
<Head> | ||
<title>Post</title> | ||
<title>{`${data.post.content} - ${data.author.username}`}</title> | ||
</Head> | ||
<main className="flex h-screen justify-center">Post View</main> | ||
<PageLayout> | ||
<PostView {...data} /> | ||
</PageLayout> | ||
</> | ||
); | ||
}; | ||
|
||
export const getStaticProps: GetStaticProps = async (context) => { | ||
const ssg = generateSSGHelper(); | ||
|
||
const id = context.params?.id; | ||
|
||
// Should actually return you to a different page, but for now this is ok | ||
if (typeof id !== "string") throw new Error("No id"); | ||
|
||
await ssg.posts.getById.prefetch(id); | ||
|
||
return { | ||
props: { | ||
trpcState: ssg.dehydrate(), | ||
id, | ||
}, | ||
}; | ||
}; | ||
|
||
export const getStaticPaths = () => { | ||
return { paths: [], fallback: "blocking" }; | ||
}; | ||
|
||
export default SinglePostPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { createProxySSGHelpers } from "@trpc/react-query/ssg"; | ||
import { appRouter } from "~/server/api/root"; | ||
import { prisma } from "~/server/db"; | ||
import superjson from "superjson"; | ||
|
||
export function generateSSGHelper() { | ||
return createProxySSGHelpers({ | ||
router: appRouter, | ||
ctx: { prisma, userId: null }, | ||
transformer: superjson, | ||
}); | ||
} |
5a4cc34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
chirpt3 – ./
chirpt3.vercel.app
chirpt3-geeraya.vercel.app
chirpt3-git-main-geeraya.vercel.app