Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

Feature/og user (#856)

Shrikrishna Joisaba74086e8c85
diff --git a/apps/og-image/app/api/user/route.tsx b/apps/og-image/app/api/user/route.tsx
index 2051aeeb..e70a64d9 100644
--- a/apps/og-image/app/api/user/route.tsx
+++ b/apps/og-image/app/api/user/route.tsx
@@ -3,6 +3,7 @@ import { userParam } from 'utils/zodParams';
import { fetchFont } from 'utils/fetchFont';
import { Grid } from 'app/components/grid';
import { Logo } from 'app/components/logo';
+import Image from 'next/image';
export const runtime = 'edge';
@@ -23,14 +24,19 @@ export async function GET(req: Request) {
return new ImageResponse(
(
- <div tw="bg-black h-full w-full text-white bg-cover flex flex-col px-32 py-14">
+ <div tw="bg-black h-full w-full text-white bg-cover flex flex-col px-14 py-10">
<Grid />
- <div tw="flex flex-col justify-center items-center text-center h-full w-full">
- <Logo />
- <h1 tw="text-6xl pt-3 font-bold mt-6">{props.username}</h1>
- <p tw="text-3xl text-zinc-300">
- A user that we can prolly pull data from the db or at least their avatar maybe?
- </p>
+ <div tw="flex flex-col text-center h-full w-full gap-4 justify-between">
+ <div tw="flex justify-between">
+ {props.avatar ? (
+ <img src={props.avatar} tw="object-cover h-36 w-36 rounded-full" />
+ ) : null}
+ <Logo />
+ </div>
+ <div tw="flex flex-col text-left">
+ <h1 tw="text-6xl font-bold">{props.username}</h1>
+ {props.bio ? <p tw="text-4xl text-zinc-300">{props.bio}</p> : null}
+ </div>
</div>
</div>
),
diff --git a/apps/og-image/app/page.tsx b/apps/og-image/app/page.tsx
index ac488bc3..d30c599e 100644
--- a/apps/og-image/app/page.tsx
+++ b/apps/og-image/app/page.tsx
@@ -52,6 +52,8 @@ export default function Page() {
alt="ayo"
src={`/api/user?${userParam.toSearchString({
username: 'Hacksore',
+ bio: 'This is a test card that has a has a nice description lorem40 ipsum dolor sit amet, consectetur adipiscing elit. lorem more text here s aothesntohks anatoh esn uthsanotedhusn hwanoejt hsaont hesnathdoneitsdhsas asnoehusnatohesunthaoenst',
+ avatar: 'https://avatars.githubusercontent.com/u/32938743?v=4',
})}&random=${nonce}`}
/>
</div>
diff --git a/apps/og-image/utils/zodParams.ts b/apps/og-image/utils/zodParams.ts
index 2bb7784e..792d1dd3 100644
--- a/apps/og-image/utils/zodParams.ts
+++ b/apps/og-image/utils/zodParams.ts
@@ -63,5 +63,7 @@ export const challengeParam = zodParams(
export const userParam = zodParams(
z.object({
username: truncatedWordSchema({ maxCharacters: 70 }),
+ bio: truncatedWordSchema({ maxCharacters: 145 }).optional(),
+ avatar: z.string().optional(),
}),
);
diff --git a/apps/web/src/app/[locale]/[username]/page.tsx b/apps/web/src/app/[locale]/[username]/page.tsx
index 1405470e..18a3bc43 100644
--- a/apps/web/src/app/[locale]/[username]/page.tsx
+++ b/apps/web/src/app/[locale]/[username]/page.tsx
@@ -1,5 +1,6 @@
import { buildMetaForDefault, buildMetaForUser } from '~/app/metadata';
import { Profile } from './_components/profile';
+import { prisma } from '@repo/db';
interface Props {
params: {
@@ -16,11 +17,31 @@ export async function generateMetadata({ params: { username: usernameFromQuery }
if (!username) return {};
+ const user = await prisma.user.findFirst({
+ where: {
+ name: {
+ equals: username,
+ },
+ },
+ select: {
+ id: true,
+ createdAt: true,
+ bio: true,
+ image: true,
+ name: true,
+ },
+ });
+
+ const bio = user ? user.bio : '';
+ const avatar = user && user.image ? user.image : '';
+
if (username)
return buildMetaForUser({
username,
title: `${username}'s profile | TypeHero`,
description: `View the profile of ${username} on TypeHero.`,
+ bio,
+ avatar,
});
return buildMetaForDefault({
title: 'Profile | TypeHero',
diff --git a/apps/web/src/app/[locale]/challenge/[id]/page.tsx b/apps/web/src/app/[locale]/challenge/[id]/page.tsx
index 3a8fa593..7d29c498 100644
--- a/apps/web/src/app/[locale]/challenge/[id]/page.tsx
+++ b/apps/web/src/app/[locale]/challenge/[id]/page.tsx
@@ -29,7 +29,7 @@ export default async function Challenges({ params: { id: challengeId } }: Props)
const challenge = await getChallengeRouteData(challengeId, session);
return (
- <div className="relative h-full">
+ <div className="relative h-full ">
<Description challenge={challenge} />
<Comments rootId={challenge.id} type="CHALLENGE" />
</div>
diff --git a/apps/web/src/app/metadata.ts b/apps/web/src/app/metadata.ts
index 6b63b05c..d614575f 100644
--- a/apps/web/src/app/metadata.ts
+++ b/apps/web/src/app/metadata.ts
@@ -59,15 +59,21 @@ interface MetaParamsForUser {
title: string;
description: string;
username: string;
+ bio: string;
+ avatar: string;
}
/** Helper to build opengraph metadata for a user, you should call this in generateMetadata() next function */
export const buildMetaForUser = async ({
title,
description,
username,
+ bio,
+ avatar,
}: MetaParamsForUser): Promise<Metadata> => {
const params = `${userParam.toSearchString({
username,
+ bio,
+ avatar,
})}`;
const ogImageUrl = `${OG_URL}/api/user?${params}`;