Skip to content

Commit

Permalink
feat: add rich metadata to share page (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
CaliCastle authored Oct 19, 2023
1 parent de64bf6 commit ac0583f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/share/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
import { clerkClient, currentUser } from '@clerk/nextjs'
import { desc, eq } from 'drizzle-orm'
import type { Metadata } from 'next'
import { notFound } from 'next/navigation'

import { GameLayout } from '~/app/_game/components/GameLayout'
import { ResultDisplay } from '~/app/_game/components/ResultDisplay'
import { filterUser } from '~/app/_game/helpers/filterUser'
import { getResultTier } from '~/app/_game/helpers/getResultTier'
import { getTestId } from '~/app/_game/helpers/getTestId'
import { db } from '~/db'
import { userScores } from '~/db/schema'
import { sqids } from '~/lib/sqids'

import { Actions } from './_components/Actions'

export async function generateMetadata({
params,
}: {
params: { id: string }
}): Promise<Metadata> {
const [id] = sqids.decode(params.id)
if (!id) return {}
const [userScore] = await db
.select()
.from(userScores)
.where(eq(userScores.id, id))
if (!userScore) return {}

const clerkUser = await clerkClient.users.getUser(userScore.userId)
const user = filterUser(clerkUser)
const testId = getTestId({ date: userScore.createdAt })
const tier = getResultTier(userScore.score, userScore.total, userScore.time)

return {
title: user.name ? `${user.name} on isthat.ai` : undefined,
description: `I scored ${tier.title} on Test #${testId} 🕵️`,
} satisfies Metadata
}

export default async function Share({ params }: { params: { id: string } }) {
const [id] = sqids.decode(params.id)
if (!id) return notFound()
Expand Down

0 comments on commit ac0583f

Please sign in to comment.