@@ -22,6 +22,7 @@ import ResetLive from "./ResetLive";
22
22
import type { DebouncedState } from "use-debounce" ;
23
23
import { useDebouncedCallback } from "use-debounce" ;
24
24
import { useCurrentRoute } from "../../hooks/useCurrentRoute" ;
25
+ import { getSlotGroupLeader } from "../../utils" ;
25
26
26
27
const computeItemKey = ( slot : number ) => slot ;
27
28
@@ -274,13 +275,23 @@ function AllSlotsList({ width, height }: SlotsListProps) {
274
275
}
275
276
276
277
function MySlotsList ( { width, height } : SlotsListProps ) {
277
- const leaderSlots = useAtomValue ( leaderSlotsAtom ) ;
278
+ const mySlots = useAtomValue ( leaderSlotsAtom ) ;
278
279
279
280
const slotGroupsDescending = useMemo (
280
- ( ) => leaderSlots ?. toReversed ( ) ?? [ ] ,
281
- [ leaderSlots ] ,
281
+ ( ) => mySlots ?. toReversed ( ) ?? [ ] ,
282
+ [ mySlots ] ,
282
283
) ;
283
284
285
+ const slotToIndexMapping = useMemo ( ( ) => {
286
+ return slotGroupsDescending . reduce < { [ slot : number ] : number } > (
287
+ ( acc , slot , index ) => {
288
+ acc [ slot ] = index ;
289
+ return acc ;
290
+ } ,
291
+ { } ,
292
+ ) ;
293
+ } , [ slotGroupsDescending ] ) ;
294
+
284
295
const getSlotAtIndex = useCallback (
285
296
( index : number ) => slotGroupsDescending [ index ] ,
286
297
[ slotGroupsDescending ] ,
@@ -289,12 +300,15 @@ function MySlotsList({ width, height }: SlotsListProps) {
289
300
// Get the slot index, or if unavailable, the closest past index
290
301
const getClosestIndexForSlot = useCallback (
291
302
( slot : number ) => {
292
- return slotGroupsDescending . findIndex ( ( s ) => s <= slot ) ;
303
+ return (
304
+ slotToIndexMapping [ getSlotGroupLeader ( slot ) ] ??
305
+ slotGroupsDescending . findIndex ( ( s ) => s <= slot )
306
+ ) ;
293
307
} ,
294
- [ slotGroupsDescending ] ,
308
+ [ slotGroupsDescending , slotToIndexMapping ] ,
295
309
) ;
296
310
297
- if ( ! leaderSlots ) return null ;
311
+ if ( ! mySlots ) return null ;
298
312
299
313
return (
300
314
< InnerSlotsList
0 commit comments