@@ -5,13 +5,14 @@ import { mockAliens } from '../data/mockAliens';
55import type { AlienProfile } from '../data/mockAliens' ;
66import { useAppContext } from '../context/AppContext' ;
77import ProfileModal from './ProfileModal' ;
8- import MatchOverlay from './MatchOverlay' ;
8+ import { getCompatibility } from '../utils/compatibility' ;
9+ import { useRocketNav } from '../context/TransitionContext' ;
910
1011export default function OrbitSystem ( ) {
1112 const navigate = useNavigate ( ) ;
1213 const { preferences, addMatch, matches } = useAppContext ( ) ;
14+ const triggerRocketNav = useRocketNav ( ) ;
1315 const [ selectedAlien , setSelectedAlien ] = useState < AlienProfile | null > ( null ) ;
14- const [ matchedAlien , setMatchedAlien ] = useState < AlienProfile | null > ( null ) ;
1516 const [ dismissedIds , setDismissedIds ] = useState < Set < string > > ( new Set ( ) ) ;
1617 const [ showBreakingAnim , setShowBreakingAnim ] = useState ( false ) ;
1718 const [ animStage , setAnimStage ] = useState < 'none' | 'heart' | 'break' | 'final' > ( 'none' ) ;
@@ -30,6 +31,10 @@ export default function OrbitSystem() {
3031 ! activeIds . includes ( a . id )
3132 ) ;
3233
34+ // Sort available aliens by compatibility descending, so the queue is ordered
35+ // from highest match to lowest match. The next alien pulled will always be the highest remaining match.
36+ available . sort ( ( a , b ) => getCompatibility ( b , preferences ) - getCompatibility ( a , preferences ) ) ;
37+
3338 let changed = false ;
3439 const newActiveIds = [ ...activeIds ] ;
3540
@@ -69,7 +74,7 @@ export default function OrbitSystem() {
6974 const handleMatch = ( alien : AlienProfile ) => {
7075 addMatch ( alien ) ;
7176 setSelectedAlien ( null ) ;
72- setMatchedAlien ( alien ) ;
77+ triggerRocketNav ( `/chat/ ${ alien . id } ` , { alienImg : alien . profilePic } ) ;
7378 } ;
7479
7580 const handleDismiss = ( alien : AlienProfile ) => {
@@ -78,10 +83,28 @@ export default function OrbitSystem() {
7883 newSet . add ( alien . id ) ;
7984 return newSet ;
8085 } ) ;
81- setSelectedAlien ( null ) ;
86+
87+ // Find the next available alien in activeIds
88+ const currentIndex = activeIds . indexOf ( alien . id ) ;
89+ let nextId = null ;
90+ if ( currentIndex >= 0 ) {
91+ for ( let i = 1 ; i < 5 ; i ++ ) {
92+ const candidate = activeIds [ ( currentIndex + i ) % 5 ] ;
93+ if ( candidate && candidate !== alien . id ) {
94+ nextId = candidate ;
95+ break ;
96+ }
97+ }
98+ }
99+
100+ if ( nextId ) {
101+ const nextAlien = mockAliens . find ( a => a . id === nextId ) ;
102+ setSelectedAlien ( nextAlien || null ) ;
103+ } else {
104+ setSelectedAlien ( null ) ;
105+ }
82106 } ;
83107
84- const visibleAliens = mockAliens . filter ( a => activeIds . includes ( a . id ) ) ;
85108
86109 return (
87110 < >
@@ -173,11 +196,12 @@ export default function OrbitSystem() {
173196 ) }
174197
175198 { /* Orbit Rings and Aliens */ }
176- { activeIds . map ( ( id , i ) => {
177- if ( ! id ) return null ; // If no alien is available for this slot, don't render it
178-
179- const alien = mockAliens . find ( a => a . id === id ) ;
180- if ( ! alien ) return null ;
199+ { activeIds
200+ . map ( id => id ? mockAliens . find ( a => a . id === id ) : null )
201+ . filter ( ( a ) : a is AlienProfile => a !== null && a !== undefined )
202+ // Sort by compatibility descending so the highest match is in the innermost track
203+ . sort ( ( a , b ) => getCompatibility ( b , preferences ) - getCompatibility ( a , preferences ) )
204+ . map ( ( alien , i ) => {
181205
182206 // Assign each slot to a distinct track (0 to 4)
183207 const rx = 120 + ( i * 65 ) ;
@@ -291,12 +315,6 @@ export default function OrbitSystem() {
291315 />
292316 ) }
293317
294- { matchedAlien && (
295- < MatchOverlay
296- alien = { matchedAlien }
297- userName = { preferences . name || 'User' }
298- />
299- ) }
300318 </ >
301319 ) ;
302320}
0 commit comments