"use client"; import { useState } from "react"; import { Loader2, Radio } from "lucide-react"; import { useRouter } from "next/navigation"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { createTest } from "@/app/(frontend)/minigames/radio/custom/actions"; const MAX_MESSAGES = 100; export function CreateTestDialog({ unlocked, children, }: { unlocked: boolean; children?: React.ReactNode; }) { const router = useRouter(); const [open, setOpen] = useState(false); const [name, setName] = useState(""); const [poolText, setPoolText] = useState(""); const [order, setOrder] = useState<"fixed" | "shuffled">("fixed"); const [error, setError] = useState(null); const [submitting, setSubmitting] = useState(false); const pool = poolText .split("\n") .map((line) => line.trim()) .filter((line) => line.length > 0); const submit = async () => { setError(null); const trimmed = name.trim(); if (trimmed.length < 1 || trimmed.length > 100) { setError("Name must be 1-100 characters."); return; } if (pool.length < 1 || pool.length > MAX_MESSAGES) { setError(`Message pool must contain 1-${MAX_MESSAGES} messages (one per line).`); return; } if (pool.some((message) => message.length > 500)) { setError("Each message must be 1-500 characters."); return; } setSubmitting(true); const result = await createTest({ name: trimmed, messages: pool, order }); setSubmitting(false); if (result.success) { setOpen(false); setName(""); setPoolText(""); setOrder("fixed"); router.refresh(); } else { setError(result.error ?? "Could not publish the test."); } }; if (!unlocked) return null; return ( { setOpen(next); if (!next) setError(null); }} > {children ?? ( )} Author a custom radio test Build a message pool, one transmission per line. Published tests are instantly playable by every operator and scored like the official game.
setName(event.target.value)} placeholder="Night Watch Drill" className="w-48" />
{pool.length} messages