fix: refactor wizard edit mode to use lazy state init instead of effect setState

This commit is contained in:
2026-04-28 09:51:26 +08:00
parent d8d0e8f826
commit d6a9601591
8 changed files with 868 additions and 97 deletions
+15
View File
@@ -33,6 +33,9 @@ import { FpsBoxplot } from "@/components/charts/FpsBoxplot"
import { FpsRangeChart } from "@/components/charts/FpsRangeChart"
import { DeviceDonut } from "@/components/charts/DeviceDonut"
// Comments
import { CommentSection } from "@/components/comments/comment-section"
// Types
interface Game {
id: string
@@ -1011,6 +1014,18 @@ export function GamePageClient({
</div>
</motion.div>
{/* Section 6: Comments */}
<motion.div
initial={{ opacity: 0, y: 12 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.4, delay: 0.3 }}
className='px-4 md:px-[10svw]'
>
<div className='max-w-7xl mx-auto'>
<CommentSection gameId={gameId} initialCount={counts.comments} />
</div>
</motion.div>
</section>
<AnimatePresence>
{selectedPresetId && (() => {
+26 -6
View File
@@ -1,6 +1,6 @@
import { notFound } from "next/navigation"
import { db } from "@/lib/db/index"
import { games, gameVersions } from "@/lib/db/schema"
import { games, gameVersions, performanceEntries } from "@/lib/db/schema"
import { eq, sql } from "drizzle-orm"
import { GameEntryWizard } from "@/components/wizard/game-entry-wizard"
@@ -11,12 +11,17 @@ export const metadata = {
title: "Submit Benchmark",
}
interface PageProps {
params: Promise<{ id: string }>
searchParams: Promise<{ edit?: string }>
}
export default async function SubmitBenchmarkPage({
params,
}: {
params: Promise<{ id: string }>
}) {
searchParams,
}: PageProps) {
const { id } = await params
const { edit } = await searchParams
// Resolve game
const isNumeric = /^\d+$/.test(id)
@@ -63,18 +68,33 @@ export default async function SubmitBenchmarkPage({
.returning()
}
// If editing, fetch the existing performance entry
let editEntry = null
if (edit) {
const [entry] = await db
.select()
.from(performanceEntries)
.where(eq(performanceEntries.id, edit))
.limit(1)
editEntry = entry ?? null
}
return (
<div className="max-w-7xl mx-auto px-4 py-8 w-full">
<div className="mb-8">
<h1 className="text-2xl font-bold mb-2">Submit Benchmark</h1>
<h1 className="text-2xl font-bold mb-2">
{editEntry ? "Edit Benchmark" : "Submit Benchmark"}
</h1>
<p className="text-sm text-text/60">
Submit performance data for <span className="text-text font-medium">{game.title}</span>
{editEntry ? "Update your performance data for" : "Submit performance data for"}{" "}
<span className="text-text font-medium">{game.title}</span>
</p>
</div>
<GameEntryWizard
gameId={game.id}
gameVersionId={version.id}
editEntry={editEntry}
/>
</div>
)