Skip to content

Commit 54ea8f5

Browse files
fix: slots list when no you slots
1 parent bd560dc commit 54ea8f5

File tree

4 files changed

+51
-15
lines changed

4 files changed

+51
-15
lines changed

src/features/Navigation/SlotsList.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
slotNavFilterAtom,
99
slotOverrideAtom,
1010
} from "../../atoms";
11-
import { Box } from "@radix-ui/themes";
11+
import { Box, Flex, Text } from "@radix-ui/themes";
1212
import type { RefObject } from "react";
1313
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
1414
import styles from "./slotsList.module.css";
@@ -72,6 +72,7 @@ function InnerSlotsList({
7272
const visibleStartIndexRef = useRef<number | null>(null);
7373

7474
const [hideList, setHideList] = useState(true);
75+
const [totalListHeight, setTotalListHeight] = useState(0);
7576

7677
useEffect(() => {
7778
// initially hide list to
@@ -156,7 +157,11 @@ function InnerSlotsList({
156157
getIndexForSlot={getIndexForSlot}
157158
debouncedScroll={debouncedScroll}
158159
/>
159-
<SlotsPlaceholder width={width} height={height} />
160+
<SlotsPlaceholder
161+
width={width}
162+
height={height}
163+
totalListHeight={totalListHeight}
164+
/>
160165
<ResetLive />
161166
<Virtuoso
162167
ref={listRef}
@@ -174,6 +179,7 @@ function InnerSlotsList({
174179
rangeChanged={rangeChanged}
175180
components={{ ScrollSeekPlaceholder: MScrollSeekPlaceHolder }}
176181
scrollSeekConfiguration={scrollSeekConfiguration}
182+
totalListHeightChanged={(height) => setTotalListHeight(height)}
177183
/>
178184
</Box>
179185
);
@@ -336,6 +342,23 @@ function MySlotsList({ width, height }: SlotsListProps) {
336342

337343
if (!mySlots) return null;
338344

345+
if (mySlots.length === 0) {
346+
return (
347+
<Flex
348+
width={`${width}px`}
349+
height={`${height}px`}
350+
justify="center"
351+
align="center"
352+
>
353+
<Text className={styles.noSlotsText}>
354+
No Slots
355+
<br />
356+
Available
357+
</Text>
358+
</Flex>
359+
);
360+
}
361+
339362
return (
340363
<InnerSlotsList
341364
width={width}

src/features/Navigation/SlotsRenderer.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { atom, useAtomValue } from "jotai";
22
import {
33
currentLeaderSlotAtom,
44
currentSlotAtom,
5-
earliestProcessedSlotLeaderAtom,
5+
firstProcessedSlotAtom,
6+
leaderSlotsAtom,
67
nextLeaderSlotAtom,
78
slotDurationAtom,
89
} from "../../atoms";
@@ -40,10 +41,13 @@ export default function SlotsRenderer(props: { leaderSlotForGroup: number }) {
4041

4142
const getStatusAtom = atom((get) => {
4243
const currentLeaderSlot = get(currentLeaderSlotAtom);
43-
const earliestProcessedSlotLeader = get(earliestProcessedSlotLeaderAtom);
44+
const firstProcessedSlot = get(firstProcessedSlotAtom);
45+
const leaderSlots = get(leaderSlotsAtom);
46+
4447
if (
48+
!leaderSlots ||
4549
currentLeaderSlot === undefined ||
46-
earliestProcessedSlotLeader === undefined
50+
firstProcessedSlot === undefined
4751
)
4852
return;
4953

@@ -55,7 +59,7 @@ const getStatusAtom = atom((get) => {
5559
currentLeaderSlot <= slot && slot < currentLeaderSlot + slotsPerLeader,
5660
isFutureSlotGroup: currentLeaderSlot + slotsPerLeader <= slot,
5761
isProcessedSlotGroup:
58-
earliestProcessedSlotLeader <= slot && slot <= currentLeaderSlot,
62+
firstProcessedSlot <= slot && slot <= currentLeaderSlot,
5963
isYourNextLeaderGroup:
6064
nextLeaderSlot &&
6165
nextLeaderSlot <= slot &&
@@ -233,11 +237,14 @@ function SlotContent({ firstSlot }: SlotGroupProps) {
233237
export function SlotsPlaceholder({
234238
width,
235239
height,
240+
totalListHeight,
236241
}: {
237242
width: number;
238243
height: number;
244+
totalListHeight: number;
239245
}) {
240246
const items = useMemo(() => Math.ceil(height / 46), [height]);
247+
if (totalListHeight < height) return;
241248

242249
return (
243250
<Box

src/features/Navigation/slotsList.module.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
visibility: hidden;
55
}
66
}
7+
8+
.no-slots-text {
9+
font-size: 12px;
10+
color: var(--regular-text-color);
11+
text-align: center;
12+
}

src/features/Overview/SlotPerformance/atoms.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { produce } from "immer";
1010
import { countBy } from "lodash";
1111
import {
1212
currentSlotAtom,
13-
earliestProcessedSlotLeaderAtom,
1413
epochAtom,
14+
firstProcessedSlotAtom,
1515
leaderSlotsAtom,
1616
slotOverrideAtom,
1717
} from "../../../atoms";
@@ -30,22 +30,22 @@ function getSlotState(
3030
slot?: number,
3131
epoch?: Epoch,
3232
leaderSlots?: number[],
33-
earliestProcessedSlotLeader?: number,
33+
firstProcessedSlot?: number,
3434
currentSlot?: number,
3535
) {
3636
if (slot === undefined) return SelectedSlotValidityState.Valid;
3737
if (
3838
!epoch ||
3939
!leaderSlots ||
40-
earliestProcessedSlotLeader === undefined ||
40+
firstProcessedSlot === undefined ||
4141
currentSlot === undefined
4242
)
4343
return SelectedSlotValidityState.NotReady;
4444
if (slot < epoch.start_slot || epoch.end_slot < slot)
4545
return SelectedSlotValidityState.OutsideEpoch;
4646
if (!leaderSlots.includes(getSlotGroupLeader(slot)))
4747
return SelectedSlotValidityState.NotYou;
48-
if (slot < earliestProcessedSlotLeader)
48+
if (slot < firstProcessedSlot)
4949
return SelectedSlotValidityState.BeforeFirstProcessed;
5050
if (slot >= currentSlot) return SelectedSlotValidityState.Future;
5151
return SelectedSlotValidityState.Valid;
@@ -60,13 +60,13 @@ export const baseSelectedSlotAtom = (function () {
6060
const epoch = get(epochAtom);
6161
const slot = get(_baseSelectedSlotAtom);
6262
const leaderSlots = get(leaderSlotsAtom);
63-
const earliestProcessedSlotLeader = get(earliestProcessedSlotLeaderAtom);
63+
const firstProcessedSlot = get(firstProcessedSlotAtom);
6464
const currentSlot = get(currentSlotAtom);
6565
const state = getSlotState(
6666
slot,
6767
epoch,
6868
leaderSlots,
69-
earliestProcessedSlotLeader,
69+
firstProcessedSlot,
7070
currentSlot,
7171
);
7272
return {
@@ -78,12 +78,12 @@ export const baseSelectedSlotAtom = (function () {
7878
},
7979
(get, set, slot?: number, epoch?: Epoch) => {
8080
const leaderSlots = get(leaderSlotsAtom);
81-
const earliestProcessedSlotLeader = get(earliestProcessedSlotLeaderAtom);
81+
const firstProcessedSlot = get(firstProcessedSlotAtom);
8282
const currentSlot = get(currentSlotAtom);
8383
if (
8484
!epoch ||
8585
!leaderSlots ||
86-
earliestProcessedSlotLeader === undefined ||
86+
firstProcessedSlot === undefined ||
8787
currentSlot === undefined
8888
) {
8989
set(_baseSelectedSlotAtom, undefined);
@@ -97,7 +97,7 @@ export const baseSelectedSlotAtom = (function () {
9797
slot,
9898
epoch,
9999
leaderSlots,
100-
earliestProcessedSlotLeader,
100+
firstProcessedSlot,
101101
currentSlot,
102102
) === SelectedSlotValidityState.Valid;
103103

0 commit comments

Comments
 (0)