Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/app/p/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { VoteButton } from "@/components/vote-button";
import { StageDot } from "@/components/stage-dot";
import { CommentSection } from "@/components/comment-section";
import { isMockMode, MOCK_PRODUCTS, MOCK_COMMENTS } from "@/lib/mock-data";
import type { ProductWithCounts } from "@/types/database";
import type { ProductBuilder, ProductWithCounts } from "@/types/database";
import type { Metadata } from "next";

interface Props {
Expand Down Expand Up @@ -44,6 +44,16 @@ async function getProduct(id: string) {
return { product, userHasVoted, comments: [] };
}

function parseBuilder(builder: ProductWithCounts["builder"]): ProductBuilder | null {
if (typeof builder !== "string") return builder;

try {
return JSON.parse(builder) as ProductBuilder;
} catch {
return null;
}
}

export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { id } = await params;
if (isMockMode()) {
Expand All @@ -66,10 +76,7 @@ export default async function ProductPage({ params }: Props) {
if (!product) notFound();

const typedProduct = product as ProductWithCounts;
const builder =
typeof typedProduct.builder === "string"
? JSON.parse(typedProduct.builder)
: typedProduct.builder;
const builder = parseBuilder(typedProduct.builder);

return (
<div className="mx-auto max-w-2xl px-4 pt-24 pb-16 sm:px-6">
Expand Down