Add Generate All 3 button to admin panel

This commit is contained in:
2026-03-14 19:56:45 -07:00
parent fa334bb739
commit 9ad88680c7
+38 -4
View File
@@ -12,6 +12,7 @@ import {
listUsers,
recalculateScores,
generateChallenge,
generateAllChallenges,
retroactiveAchievements,
backfillUsernames,
type PlatformStats,
@@ -288,6 +289,7 @@ function GenerateChallengeSection() {
const [date, setDate] = useState('');
const [difficulty, setDifficulty] = useState('medium');
const [loading, setLoading] = useState(false);
const [loadingAll, setLoadingAll] = useState(false);
const [success, setSuccess] = useState('');
const [error, setError] = useState('');
@@ -299,15 +301,33 @@ function GenerateChallengeSection() {
try {
const challenge = await generateChallenge(date, difficulty);
setSuccess(
`Generated: ${challenge.movieATitle} \u2194 ${challenge.movieBTitle}`,
`Generated ${difficulty}: ${challenge.movieATitle} \u2194 ${challenge.movieBTitle}`,
);
} catch {
setError('Failed to generate challenge. Date may already exist.');
setError('Failed to generate challenge.');
} finally {
setLoading(false);
}
};
const handleGenerateAll = async () => {
if (!date) return;
setLoadingAll(true);
setError('');
setSuccess('');
try {
const challenges = await generateAllChallenges(date);
const summaries = challenges.map(
(c: any) => `${c.difficulty}: ${c.movieATitle} \u2194 ${c.movieBTitle}`,
);
setSuccess(`Generated all 3:\n${summaries.join('\n')}`);
} catch {
setError('Failed to generate challenges.');
} finally {
setLoadingAll(false);
}
};
return (
<div>
<h2 className="mb-3 flex items-center gap-2 text-lg font-semibold">
@@ -340,7 +360,7 @@ function GenerateChallengeSection() {
<option value="hard">Hard</option>
</select>
</div>
<Button onClick={handleGenerate} disabled={loading || !date}>
<Button onClick={handleGenerate} disabled={loading || loadingAll || !date}>
{loading ? (
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
) : (
@@ -348,10 +368,24 @@ function GenerateChallengeSection() {
)}
Generate
</Button>
<Button
variant="secondary"
onClick={handleGenerateAll}
disabled={loading || loadingAll || !date}
>
{loadingAll ? (
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
) : (
<CalendarPlus className="mr-2 h-4 w-4" />
)}
Generate All 3
</Button>
</div>
{success && (
<Alert className="mt-3">
<AlertDescription>{success}</AlertDescription>
<AlertDescription className="whitespace-pre-line">
{success}
</AlertDescription>
</Alert>
)}
{error && (