import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { Box, Card, CardContent, Typography, Button, FormControl, InputLabel, Select, MenuItem, CircularProgress, Fade } from '@mui/material'; const PLATES = [ { src: '/tutorial/colorblind/plate_demo.png', question: 'What number do you see?', options: ['12', '4', '10', "I can't tell"], correctAnswer: '12', }, { src: '/tutorial/colorblind/plate_redgreen.png', question: 'What number do you see?', options: ['74', '21', "I can't tell", 'Something else'], correctAnswer: '74', field: 'cb_redgreen', }, { src: '/tutorial/colorblind/plate_blueyellow.png', question: 'What number do you see?', options: ['6', "I can't tell", '8', 'I see nothing'], correctAnswer: '6', field: 'cb_blueyellow', }, ]; function classifyAnswer(plate, answer) { if (answer === plate.correctAnswer) return 'normal'; if (answer === "I can't tell" || answer === 'I see nothing' || answer === 'Something else') return 'unsure'; return 'deficient'; } function detectDevice() { const ua = navigator.userAgent; if (/tablet|ipad|playbook|silk/i.test(ua)) return 'tablet'; if (/mobile|iphone|ipod|android|blackberry|opera mini|iemobile/i.test(ua)) return 'mobile'; return 'desktop'; } export default function Welcome() { const navigate = useNavigate(); const [plateStep, setPlateStep] = useState(0); const [plateAnswers, setPlateAnswers] = useState(['', '', '']); const [expertise, setExpertise] = useState(''); const [loading, setLoading] = useState(false); const allPlatesDone = plateStep >= PLATES.length; const handlePlateAnswer = (answer) => { const updated = [...plateAnswers]; updated[plateStep] = answer; setPlateAnswers(updated); }; const handlePlateNext = () => { setPlateStep((s) => s + 1); }; const handleStart = async () => { if (!allPlatesDone || !expertise) return; setLoading(true); // Classify colorblindness results const cbRedgreen = classifyAnswer(PLATES[1], plateAnswers[1]); const cbBlueyellow = classifyAnswer(PLATES[2], plateAnswers[2]); const colorblind = cbRedgreen !== 'normal' || cbBlueyellow !== 'normal' ? 1 : 0; const device = detectDevice(); try { const res = await fetch('/api/session/start', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ expertise, colorblind, device, cb_redgreen: cbRedgreen, cb_blueyellow: cbBlueyellow, }), }); const data = await res.json(); localStorage.setItem('session_id', data.session_id); localStorage.setItem('trials', JSON.stringify(data.trials)); localStorage.setItem('current_index', '0'); navigate('/tutorial'); } catch (err) { console.error('Failed to start session:', err); setLoading(false); } }; const currentPlate = !allPlatesDone ? PLATES[plateStep] : null; const currentAnswer = !allPlatesDone ? plateAnswers[plateStep] : ''; return ( Can you spot colorization artifacts? Look at 50 images and decide: are colorization artifacts present or absent? Takes about 5 minutes. {/* Colorblindness plates — sequential */} {!allPlatesDone && currentPlate && ( Vision check {plateStep + 1} of {PLATES.length} {currentPlate.question} {currentPlate.options.map((opt) => ( ))} )} {/* Expertise + Start — shown after all plates */} {allPlatesDone && ( Your background )} ); }