()
| 83 | } |
| 84 | |
| 85 | function PickPage() { |
| 86 | const searchParams = useSearchParams(); |
| 87 | const sessionId = searchParams.get("session"); |
| 88 | |
| 89 | const [picked, setPicked] = useState(false); |
| 90 | const [error, setError] = useState(""); |
| 91 | |
| 92 | const options = useMemo(() => pickRandom(ALL_PROMPTS, 3), []); |
| 93 | |
| 94 | // Notify desktop that QR was scanned |
| 95 | useEffect(() => { |
| 96 | if (sessionId) { |
| 97 | fetch("/api/pick", { |
| 98 | method: "PUT", |
| 99 | headers: { "Content-Type": "application/json" }, |
| 100 | body: JSON.stringify({ sessionId }), |
| 101 | }).catch(() => {}); |
| 102 | } |
| 103 | }, [sessionId]); |
| 104 | |
| 105 | const handlePick = async (prompt: string) => { |
| 106 | if (!sessionId || picked) return; |
| 107 | setPicked(true); |
| 108 | try { |
| 109 | const res = await fetch("/api/pick", { |
| 110 | method: "POST", |
| 111 | headers: { "Content-Type": "application/json" }, |
| 112 | body: JSON.stringify({ sessionId, prompt }), |
| 113 | }); |
| 114 | if (!res.ok) throw new Error("Failed to submit"); |
| 115 | } catch { |
| 116 | setError("Something went wrong. Try again."); |
| 117 | setPicked(false); |
| 118 | } |
| 119 | }; |
| 120 | |
| 121 | if (!sessionId) { |
| 122 | return ( |
| 123 | <div style={styles.container}> |
| 124 | <p style={styles.errorText}>Invalid link — scan the QR code from the main app.</p> |
| 125 | </div> |
| 126 | ); |
| 127 | } |
| 128 | |
| 129 | if (picked) { |
| 130 | return ( |
| 131 | <div style={styles.container}> |
| 132 | <div style={styles.successCard}> |
| 133 | <span style={{ fontSize: 48 }}>✓</span> |
| 134 | <h2 style={styles.successTitle}>Sent!</h2> |
| 135 | <p style={styles.successSub}>Look up at the big screen to see it come to life.</p> |
| 136 | </div> |
| 137 | </div> |
| 138 | ); |
| 139 | } |
| 140 | |
| 141 | return ( |
| 142 | <div style={styles.container}> |
nothing calls this directly
no test coverage detected