-
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
8 changed files
with
105 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,72 @@ | ||
import { type NextPage } from "next"; | ||
import type { GetStaticProps, NextPage } from "next"; | ||
import Head from "next/head"; | ||
import { api } from "~/utils/api"; | ||
import Image from "next/image"; | ||
import { PageLayout } from "~/components/Layout"; | ||
|
||
const ProfilePage: NextPage<{ username: string }> = ({ username }) => { | ||
const { data } = api.profile.getUserByUsername.useQuery({ | ||
username, | ||
}); | ||
|
||
if (!data) return <div>404</div>; | ||
|
||
const ProfilePage: NextPage = () => { | ||
return ( | ||
<> | ||
<Head> | ||
<title>Create T3 App</title> | ||
<meta name="description" content="Generated by create-t3-app" /> | ||
<link rel="icon" href="/favicon.ico" /> | ||
<title>{data.username}</title> | ||
</Head> | ||
<main className="flex h-screen justify-center">Profile View</main> | ||
<PageLayout> | ||
<div className="relative h-36 bg-slate-600"> | ||
<Image | ||
src={data.profileImageUrl} | ||
width={128} | ||
height={128} | ||
alt={`${data.username ?? ""}'s profile image`} | ||
className="absolute bottom-0 left-0 -mb-16 ml-4 rounded-full border-4 border-black bg-black" | ||
/> | ||
</div> | ||
<div className="h-16" /> | ||
<div className="p-4 text-2xl font-bold">{`@${ | ||
data.username ?? "" | ||
}`}</div> | ||
<div className="w-full border-b border-slate-400"></div> | ||
</PageLayout> | ||
</> | ||
); | ||
}; | ||
|
||
import { createProxySSGHelpers } from "@trpc/react-query/ssg"; | ||
import { appRouter } from "~/server/api/root"; | ||
import { prisma } from "~/server/db"; | ||
import superjson from "superjson"; | ||
|
||
export const getStaticProps: GetStaticProps = async (context) => { | ||
const ssg = createProxySSGHelpers({ | ||
router: appRouter, | ||
ctx: { prisma, userId: null }, | ||
transformer: superjson, | ||
}); | ||
|
||
const slug = context.params?.slug; | ||
|
||
// Should actually return you to a different page, but for now this is ok | ||
if (typeof slug !== "string") throw new Error("No slug"); | ||
|
||
const username = slug.replace("@", ""); | ||
|
||
await ssg.profile.getUserByUsername.prefetch({ username }); | ||
|
||
return { | ||
props: { | ||
trpcState: ssg.dehydrate(), | ||
username, | ||
}, | ||
}; | ||
}; | ||
|
||
export const getStaticPaths = () => { | ||
return { paths: [], fallback: "blocking" }; | ||
}; | ||
|
||
export default ProfilePage; |
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
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
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,24 @@ | ||
import { clerkClient } from "@clerk/nextjs/server"; | ||
import { TRPCError } from "@trpc/server"; | ||
import * as z from "zod"; | ||
|
||
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc"; | ||
import { filterUserForClient } from "~/server/helpers/filterUserForClient"; | ||
|
||
export const profileRouter = createTRPCRouter({ | ||
getUserByUsername: publicProcedure | ||
.input(z.object({ username: z.string() })) | ||
.query(async ({ input }) => { | ||
const [user] = await clerkClient.users.getUserList({ | ||
username: [input.username], | ||
}); | ||
|
||
if (!user) { | ||
throw new TRPCError({ | ||
code: "NOT_FOUND", | ||
message: "User not found", | ||
}); | ||
} | ||
return filterUserForClient(user); | ||
}), | ||
}); |
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 |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
|
||
body { | ||
@apply bg-black text-slate-100; | ||
overscroll-behavior: none; | ||
} |