|
| 1 | +import { useState } from 'react'; |
| 2 | +import { mockAliens } from '../data/mockAliens'; |
| 3 | +import type { AlienProfile } from '../data/mockAliens'; |
| 4 | +import { useAppContext } from '../context/AppContext'; |
| 5 | +import ProfileModal from './ProfileModal'; |
| 6 | +import MatchOverlay from './MatchOverlay'; |
| 7 | + |
| 8 | +export default function OrbitSystem() { |
| 9 | + const { preferences, addMatch } = useAppContext(); |
| 10 | + const [selectedAlien, setSelectedAlien] = useState<AlienProfile | null>(null); |
| 11 | + const [matchedAlien, setMatchedAlien] = useState<AlienProfile | null>(null); |
| 12 | + |
| 13 | + if (!preferences) return null; |
| 14 | + |
| 15 | + // Filter aliens based on max distance |
| 16 | + const visibleAliens = mockAliens.filter(a => a.distanceAU <= preferences.maxDistanceAU); |
| 17 | + |
| 18 | + const handleMatch = (alien: AlienProfile) => { |
| 19 | + addMatch(alien); |
| 20 | + setSelectedAlien(null); |
| 21 | + setMatchedAlien(alien); |
| 22 | + }; |
| 23 | + |
| 24 | + return ( |
| 25 | + <> |
| 26 | + <style>{` |
| 27 | + @keyframes orbit { |
| 28 | + from { transform: rotate(0deg) translateX(var(--radius)) rotate(0deg); } |
| 29 | + to { transform: rotate(360deg) translateX(var(--radius)) rotate(-360deg); } |
| 30 | + } |
| 31 | + .orbit-ring { |
| 32 | + position: absolute; |
| 33 | + top: 50%; |
| 34 | + left: 50%; |
| 35 | + border: 1px dashed rgba(217, 3, 104, 0.2); |
| 36 | + border-radius: 50%; |
| 37 | + transform: translate(-50%, -50%); |
| 38 | + pointer-events: none; |
| 39 | + } |
| 40 | + .orbit-item { |
| 41 | + position: absolute; |
| 42 | + top: 50%; |
| 43 | + left: 50%; |
| 44 | + margin-top: -30px; |
| 45 | + margin-left: -30px; |
| 46 | + width: 60px; |
| 47 | + height: 60px; |
| 48 | + border-radius: 50%; |
| 49 | + cursor: pointer; |
| 50 | + transition: transform 0.2s; |
| 51 | + box-shadow: 0 0 15px rgba(234, 222, 218, 0.2); |
| 52 | + border: 2px solid var(--color-primary); |
| 53 | + background-size: cover; |
| 54 | + background-position: center; |
| 55 | + animation: orbit var(--duration) linear infinite; |
| 56 | + } |
| 57 | + .orbit-item:hover { |
| 58 | + transform: scale(1.2) !important; |
| 59 | + z-index: 50; |
| 60 | + box-shadow: 0 0 25px var(--color-secondary); |
| 61 | + animation-play-state: paused; |
| 62 | + } |
| 63 | + `}</style> |
| 64 | + |
| 65 | + <div style={{ position: 'relative', width: '100%', maxWidth: '800px', height: '600px', display: 'flex', alignItems: 'center', justifyContent: 'center', overflow: 'hidden' }}> |
| 66 | + |
| 67 | + {/* User Center */} |
| 68 | + <div style={{ |
| 69 | + width: '80px', |
| 70 | + height: '80px', |
| 71 | + borderRadius: '50%', |
| 72 | + background: 'linear-gradient(135deg, var(--color-primary), var(--color-secondary))', |
| 73 | + boxShadow: '0 0 30px var(--color-secondary)', |
| 74 | + display: 'flex', |
| 75 | + alignItems: 'center', |
| 76 | + justifyContent: 'center', |
| 77 | + fontWeight: 'bold', |
| 78 | + zIndex: 10, |
| 79 | + fontSize: '1.2rem', |
| 80 | + color: 'white' |
| 81 | + }}> |
| 82 | + {preferences.name.substring(0, 2).toUpperCase() || 'YOU'} |
| 83 | + </div> |
| 84 | + |
| 85 | + {/* Orbit Rings and Aliens */} |
| 86 | + {visibleAliens.map((alien, i) => { |
| 87 | + // Calculate radius based on distance (min 80px, max 280px) |
| 88 | + const radiusRatio = preferences.maxDistanceAU > 0 ? alien.distanceAU / preferences.maxDistanceAU : 1; |
| 89 | + const radius = 80 + (radiusRatio * 200); |
| 90 | + const duration = 15 + (radius / 10); // Slower orbit for further objects |
| 91 | + const startAngle = (i * (360 / visibleAliens.length)); |
| 92 | + |
| 93 | + return ( |
| 94 | + <div key={alien.id}> |
| 95 | + {/* Ring */} |
| 96 | + <div className="orbit-ring" style={{ width: `${radius * 2}px`, height: `${radius * 2}px` }} /> |
| 97 | + |
| 98 | + {/* Profile */} |
| 99 | + <div |
| 100 | + className="orbit-item" |
| 101 | + onClick={() => setSelectedAlien(alien)} |
| 102 | + style={{ |
| 103 | + backgroundImage: `url(${alien.profilePic})`, |
| 104 | + // @ts-ignore |
| 105 | + '--radius': `${radius}px`, |
| 106 | + '--duration': `${duration}s`, |
| 107 | + animationDelay: `-${startAngle}s` // Stagger start positions |
| 108 | + }} |
| 109 | + title={`${alien.name} (${alien.distanceAU} AU)`} |
| 110 | + /> |
| 111 | + </div> |
| 112 | + ); |
| 113 | + })} |
| 114 | + </div> |
| 115 | + |
| 116 | + {selectedAlien && ( |
| 117 | + <ProfileModal |
| 118 | + alien={selectedAlien} |
| 119 | + onClose={() => setSelectedAlien(null)} |
| 120 | + onMatch={handleMatch} |
| 121 | + /> |
| 122 | + )} |
| 123 | + |
| 124 | + {matchedAlien && ( |
| 125 | + <MatchOverlay |
| 126 | + alien={matchedAlien} |
| 127 | + userName={preferences.name || 'User'} |
| 128 | + /> |
| 129 | + )} |
| 130 | + </> |
| 131 | + ); |
| 132 | +} |
0 commit comments