|
| 1 | +import { useState } from 'react'; |
| 2 | +import { useNavigate } from 'react-router'; |
| 3 | +import { useAppContext } from '../context/AppContext'; |
| 4 | + |
| 5 | +export default function Preferences() { |
| 6 | + const navigate = useNavigate(); |
| 7 | + const { preferences, setPreferences } = useAppContext(); |
| 8 | + |
| 9 | + const [formData, setFormData] = useState({ |
| 10 | + alienType: preferences?.alienType === 'Humanoid' || !preferences?.alienType ? 'Open to all' : preferences.alienType, |
| 11 | + size: preferences?.size || 'No preference', |
| 12 | + maxDistanceAU: preferences?.maxDistanceAU || 10, |
| 13 | + goals: preferences?.goals || 'Long term fusion', |
| 14 | + }); |
| 15 | + |
| 16 | + const handleSubmit = (e: React.FormEvent) => { |
| 17 | + e.preventDefault(); |
| 18 | + if (preferences) { |
| 19 | + setPreferences({ |
| 20 | + ...preferences, |
| 21 | + ...formData |
| 22 | + }); |
| 23 | + } |
| 24 | + navigate('/explore'); |
| 25 | + }; |
| 26 | + |
| 27 | + const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>) => { |
| 28 | + const { name, value } = e.target; |
| 29 | + setFormData(prev => ({ |
| 30 | + ...prev, |
| 31 | + [name]: name === 'maxDistanceAU' ? Number(value) : value |
| 32 | + })); |
| 33 | + }; |
| 34 | + |
| 35 | + return ( |
| 36 | + <div style={{ maxWidth: '500px', margin: '40px auto', padding: '0 20px' }}> |
| 37 | + <div className="glass-panel" style={{ padding: '32px' }}> |
| 38 | + <h1 style={{ textAlign: 'center', marginBottom: '24px', color: 'var(--color-secondary)' }}>Your Preferences</h1> |
| 39 | + <p style={{ textAlign: 'center', marginBottom: '32px', color: 'rgba(234, 222, 218, 0.8)' }}> |
| 40 | + What kind of being are you looking for? |
| 41 | + </p> |
| 42 | + |
| 43 | + <form onSubmit={handleSubmit} style={{ display: 'flex', flexDirection: 'column', gap: '16px' }}> |
| 44 | + |
| 45 | + <div> |
| 46 | + <h3 style={{ color: 'var(--color-secondary)', marginBottom: '16px', fontSize: '1.2rem', borderBottom: '1px solid rgba(255,255,255,0.1)', paddingBottom: '8px' }}>Biological Preferences</h3> |
| 47 | + |
| 48 | + <div style={{ marginBottom: '16px' }}> |
| 49 | + <label style={{ display: 'block', marginBottom: '8px', fontSize: '0.9rem' }}>Preferred Biological Type</label> |
| 50 | + <select name="alienType" value={formData.alienType} onChange={handleChange}> |
| 51 | + <option value="Human">Human</option> |
| 52 | + <option value="Alien">Alien</option> |
| 53 | + <option value="Hybrid">Hybrid</option> |
| 54 | + <option value="Open to all">Open to all</option> |
| 55 | + </select> |
| 56 | + </div> |
| 57 | + |
| 58 | + <div style={{ marginBottom: '16px' }}> |
| 59 | + <label style={{ display: 'block', marginBottom: '8px', fontSize: '0.9rem' }}>Preferred Size</label> |
| 60 | + <select name="size" value={formData.size} onChange={handleChange}> |
| 61 | + <option value="No preference">No preference</option> |
| 62 | + <option value="Small">Small</option> |
| 63 | + <option value="Medium">Medium</option> |
| 64 | + <option value="Large">Large</option> |
| 65 | + <option value="Colossal">Colossal</option> |
| 66 | + </select> |
| 67 | + </div> |
| 68 | + </div> |
| 69 | + |
| 70 | + <div> |
| 71 | + <h3 style={{ color: 'var(--color-secondary)', marginBottom: '16px', fontSize: '1.2rem', borderBottom: '1px solid rgba(255,255,255,0.1)', paddingBottom: '8px' }}>Relationship Goals</h3> |
| 72 | + |
| 73 | + <div style={{ marginBottom: '16px' }}> |
| 74 | + <label style={{ display: 'block', marginBottom: '8px', fontSize: '0.9rem' }}>What are you seeking?</label> |
| 75 | + <select name="goals" value={formData.goals} onChange={handleChange}> |
| 76 | + <option value="Short term orbit">Short term orbit</option> |
| 77 | + <option value="Long term fusion">Long term fusion</option> |
| 78 | + <option value="Galactic friendship">Galactic friendship</option> |
| 79 | + <option value="Exploration">Exploration</option> |
| 80 | + </select> |
| 81 | + </div> |
| 82 | + |
| 83 | + <div> |
| 84 | + <label style={{ display: 'block', marginBottom: '8px', fontSize: '0.9rem' }}>Max Distance (AU)</label> |
| 85 | + <div style={{ display: 'flex', alignItems: 'center', gap: '16px' }}> |
| 86 | + <input type="range" name="maxDistanceAU" min="0" max="100" value={formData.maxDistanceAU} onChange={handleChange} style={{ flex: 1 }} /> |
| 87 | + <span style={{ width: '40px', textAlign: 'right' }}>{formData.maxDistanceAU}</span> |
| 88 | + </div> |
| 89 | + </div> |
| 90 | + </div> |
| 91 | + |
| 92 | + <div style={{ marginTop: '16px', display: 'flex', gap: '16px' }}> |
| 93 | + <button type="button" onClick={() => navigate('/')} className="btn-outline" style={{ flex: 1 }}>Back</button> |
| 94 | + <button type="submit" className="btn-primary" style={{ flex: 2 }}>Launch Search</button> |
| 95 | + </div> |
| 96 | + </form> |
| 97 | + </div> |
| 98 | + </div> |
| 99 | + ); |
| 100 | +} |
0 commit comments