Skip to content

Commit b3f6bb2

Browse files
chore: always show epoch bar on leader schedule page
1 parent e4bf3ef commit b3f6bb2

File tree

9 files changed

+93
-56
lines changed

9 files changed

+93
-56
lines changed

src/atoms.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const clientAtom = atom(() => {
3939
export const containerElAtom = atom<HTMLDivElement | null>();
4040
export const slotsListElAtom = atom<HTMLDivElement | null>();
4141

42-
export const isNavCollapsedAtom = atom(false);
42+
export const _isNavCollapsedAtom = atom(false);
4343

4444
const _epochsAtom = atomWithImmer<Epoch[]>([]);
4545
export const epochAtom = atom(

src/features/Header/index.tsx

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,29 @@ import {
1414
import Logo from "./Logo";
1515
import { CluserIndicator, Cluster } from "./Cluster";
1616
import NavCollapseToggle from "../Navigation/NavCollapseToggle";
17-
import { isNavCollapsedAtom } from "../../atoms";
18-
import { useAtomValue } from "jotai";
1917
import NavBlur from "../Navigation/NavBlur";
2018
import { slotNavBackgroundColor } from "../../colors";
21-
import { useCurrentRoute } from "../../hooks/useCurrentRoute";
2219
import { useMemo } from "react";
20+
import { useSlotsNavigation } from "../../hooks/useSlotsNavigation";
2321

2422
export default function Header() {
2523
const showDropdownNav = useMedia("(max-width: 900px)");
2624
const isXNarrow = useMedia("(max-width: 401px)");
27-
const isNarrow = useMedia("(max-width: 768px)");
28-
const isNavCollapsed = useAtomValue(isNavCollapsedAtom);
2925

30-
const currentRoute = useCurrentRoute();
31-
const isSchedule = currentRoute === "Schedule";
26+
const { isNarrowScreen, blurBackground, showNav, showOnlyEpochBar } =
27+
useSlotsNavigation();
3228

3329
const leftBackground = useMemo(() => {
34-
if (isNavCollapsed) return undefined;
35-
if (isSchedule) {
30+
if (!showNav) return undefined;
31+
if (showOnlyEpochBar) {
3632
// only color the epoch bar portion
3733
const width = `${slotNavWithoutListWidth + epochThumbPadding}px`;
3834
return `linear-gradient(to right, ${slotNavBackgroundColor} 0px ${width}, transparent ${width} 100%)`;
3935
}
4036
return slotNavBackgroundColor;
41-
}, [isNavCollapsed, isSchedule]);
37+
}, [showOnlyEpochBar, showNav]);
4238

43-
const useExtraNarrowGap = isNavCollapsed && isXNarrow;
39+
const useExtraNarrowGap = !showNav && isXNarrow;
4440
const extraNarrowGap = "3px";
4541

4642
return (
@@ -69,11 +65,7 @@ export default function Header() {
6965
ml={`${-epochThumbPadding}px`}
7066
pl={`${epochThumbPadding}px`}
7167
>
72-
{isNarrow && isNavCollapsed && (
73-
<div style={{ width: isNavCollapsed ? undefined : "0" }}>
74-
<NavCollapseToggle isLarge />
75-
</div>
76-
)}
68+
{isNarrowScreen && !showNav && <NavCollapseToggle isLarge />}
7769
<Logo />
7870
<Cluster />
7971
</Flex>
@@ -97,11 +89,11 @@ export default function Header() {
9789

9890
<IdentityKey />
9991

100-
{isNarrow && !isNavCollapsed && <NavBlur />}
92+
{blurBackground && <NavBlur />}
10193
</Flex>
10294
</Flex>
10395

104-
{!isNarrow && (
96+
{!isNarrowScreen && (
10597
<div
10698
style={{
10799
position: "relative",
@@ -114,7 +106,7 @@ export default function Header() {
114106
left: 0,
115107
}}
116108
>
117-
<NavCollapseToggle isFloating={isNavCollapsed} />
109+
<NavCollapseToggle isFloating={!showNav} />
118110
</div>
119111
</div>
120112
)}

src/features/Navigation/EpochSlider.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
currentLeaderSlotAtom,
88
epochAtom,
99
firstProcessedSlotAtom,
10-
isNavCollapsedAtom,
1110
leaderSlotsAtom,
1211
mostRecentSlotLeaderAtom,
1312
SlotNavFilter,
@@ -32,6 +31,7 @@ import {
3231
} from "@floating-ui/react";
3332
import { isScrollingAtom } from "./atoms";
3433
import { useEventListener } from "../../hooks/useEventListener";
34+
import { useSlotsNavigation } from "../../hooks/useSlotsNavigation";
3535

3636
// 1 tick about 10 leaders or 40 slots
3737
const sliderMaxValue = 10_800;
@@ -301,7 +301,7 @@ function SliderEpochProgress({
301301
const MSliderEpochProgress = memo(SliderEpochProgress);
302302

303303
function SliderThumbTooltip({ isOpen }: { isOpen: boolean }) {
304-
const isNavCollapsed = useAtomValue(isNavCollapsedAtom);
304+
const { showNav } = useSlotsNavigation();
305305
const { refs, elements, floatingStyles, update } = useFloating({
306306
placement: "right",
307307
middleware: [offset(5)],
@@ -324,7 +324,7 @@ function SliderThumbTooltip({ isOpen }: { isOpen: boolean }) {
324324
<Slider.Thumb
325325
ref={refs.setReference}
326326
className={clsx(styles.sliderThumb, {
327-
[styles.collapsed]: isNavCollapsed,
327+
[styles.collapsed]: !showNav,
328328
})}
329329
/>
330330
<FloatingPortal id="app">

src/features/Navigation/NavBlur.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { useSetAtom } from "jotai";
2-
import { isNavCollapsedAtom } from "../../atoms";
31
import { maxZIndex } from "../../consts";
2+
import { useSlotsNavigation } from "../../hooks/useSlotsNavigation";
43

54
export default function NavBlur() {
6-
const setIsNavCollapsed = useSetAtom(isNavCollapsedAtom);
5+
const { setIsNavCollapsed } = useSlotsNavigation();
76

87
return (
98
<div

src/features/Navigation/NavCollapseToggle.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { IconButton } from "@radix-ui/themes";
22
import clsx from "clsx";
3-
import { useAtom } from "jotai";
4-
import { isNavCollapsedAtom } from "../../atoms";
53
import styles from "./navigation.module.css";
64
import ReadMore from "@material-design-icons/svg/filled/read_more.svg?react";
75
import { largeNavToggleHeight, navToggleHeight } from "../../consts";
6+
import { useSlotsNavigation } from "../../hooks/useSlotsNavigation";
87

98
interface NavCollapseToggleProps {
109
isFloating?: boolean;
@@ -15,28 +14,39 @@ export default function NavCollapseToggle({
1514
isFloating,
1615
isLarge,
1716
}: NavCollapseToggleProps) {
18-
const [isNavCollapsed, setIsNavCollapsed] = useAtom(isNavCollapsedAtom);
17+
const { showNav, setIsNavCollapsed, showOnlyEpochBar } = useSlotsNavigation();
1918

2019
const buttonSize = `${isLarge ? largeNavToggleHeight : navToggleHeight}px`;
21-
const iconSize = isLarge ? "18px" : "15px";
20+
21+
if (showOnlyEpochBar) {
22+
// Don't allow collapsing when only the epoch bar is shown
23+
return (
24+
<div
25+
style={{
26+
height: buttonSize,
27+
width: buttonSize,
28+
}}
29+
/>
30+
);
31+
}
2232

2333
return (
2434
<IconButton
2535
size="1"
2636
onClick={() => setIsNavCollapsed((prev) => !prev)}
27-
className={clsx(styles.toggleButton, { [styles.floating]: isFloating })}
37+
className={clsx(styles.toggleButton, {
38+
[styles.floating]: isFloating,
39+
})}
2840
style={{
2941
height: buttonSize,
3042
width: buttonSize,
3143
}}
3244
>
3345
<ReadMore
3446
className={clsx({
35-
[styles.mirror]: !isNavCollapsed,
47+
[styles.lg]: isLarge,
48+
[styles.mirror]: showNav,
3649
})}
37-
style={{
38-
height: iconSize,
39-
}}
4050
/>
4151
</IconButton>
4252
);

src/features/Navigation/index.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@ import {
1919
} from "../../consts";
2020
import { StatusIndicator } from "./Status";
2121
import AutoSizer from "react-virtualized-auto-sizer";
22-
import { useCurrentRoute } from "../../hooks/useCurrentRoute";
2322
import NavFilterToggles from "./NavFilterToggles";
2423
import EpochSlider from "./EpochSlider";
25-
import { isNavCollapsedAtom } from "../../atoms";
26-
import { useAtomValue } from "jotai";
2724
import clsx from "clsx";
2825
import styles from "./navigation.module.css";
2926
import NavCollapseToggle from "./NavCollapseToggle";
3027
import { useMedia } from "react-use";
28+
import { useSlotsNavigation } from "../../hooks/useSlotsNavigation";
3129

3230
const top = clusterIndicatorHeight + headerHeight;
3331

@@ -36,29 +34,29 @@ const top = clusterIndicatorHeight + headerHeight;
3634
* On collapse, content width shrinks to 0
3735
*/
3836
export default function Navigation() {
39-
const isNavCollapsed = useAtomValue(isNavCollapsedAtom);
4037
const isNarrow = useMedia(narrowNavMedia);
4138

39+
const { showNav, occupyRowWidth, showOnlyEpochBar } = useSlotsNavigation();
40+
4241
// padding to make sure epoch thumb is visible,
4342
// as it is positioned slightly outside of the container
44-
const thumbPadding = isNavCollapsed ? 0 : epochThumbPadding;
43+
const thumbPadding = showNav ? epochThumbPadding : 0;
4544

46-
const currentRoute = useCurrentRoute();
4745
const width = useMemo(() => {
48-
return currentRoute === "Schedule" ? slotNavWithoutListWidth : slotNavWidth;
49-
}, [currentRoute]);
46+
return showOnlyEpochBar ? slotNavWithoutListWidth : slotNavWidth;
47+
}, [showOnlyEpochBar]);
5048

5149
return (
5250
<div
5351
style={{
5452
// resizes outlet content immediately
5553
flexShrink: 0,
56-
width: isNarrow || isNavCollapsed ? "0" : `${width}px`,
54+
width: occupyRowWidth ? `${width}px` : "0",
5755
}}
5856
>
5957
<Flex
6058
// width transitions
61-
width={isNavCollapsed ? "0" : `${width + thumbPadding}px`}
59+
width={showNav ? `${width + thumbPadding}px` : "0"}
6260
overflow="hidden"
6361
className={clsx("sticky", styles.slotNavContainer)}
6462
style={{
@@ -87,7 +85,7 @@ export default function Navigation() {
8785
<EpochSlider />
8886
</Flex>
8987

90-
{currentRoute !== "Schedule" && (
88+
{!showOnlyEpochBar && (
9189
<Flex
9290
ml={`${logoRightSpacing}px`}
9391
direction="column"

src/features/Navigation/navigation.module.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@
4040
}
4141
}
4242

43+
.toggle-button-size {
44+
height: 15px;
45+
width: 15px;
46+
47+
&.lg {
48+
height: 18px;
49+
width: 18px;
50+
}
51+
}
52+
4353
.toggle-button {
4454
border-radius: 5px;
4555
background-color: var(--epoch-slider-progress-color);
@@ -54,6 +64,13 @@
5464

5565
svg {
5666
fill: var(--nav-button-text-color);
67+
height: 15px;
68+
width: 15px;
69+
70+
&.lg {
71+
height: 18px;
72+
width: 18px;
73+
}
5774

5875
&.mirror {
5976
transform: scaleX(-1);

src/hooks/useSlotsNavigation.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { narrowNavMedia } from "../consts";
2+
import { useCurrentRoute } from "./useCurrentRoute";
3+
import { useAtom } from "jotai";
4+
import { _isNavCollapsedAtom } from "../atoms";
5+
import { useMedia } from "react-use";
6+
7+
export function useSlotsNavigation() {
8+
const isNarrowScreen = useMedia(narrowNavMedia);
9+
const [isNavCollapsed, setIsNavCollapsed] = useAtom(_isNavCollapsedAtom);
10+
const isLeaderSchedule = useCurrentRoute() === "Schedule";
11+
12+
const showNav = isLeaderSchedule || !isNavCollapsed;
13+
const showOnlyEpochBar = isLeaderSchedule;
14+
15+
return {
16+
isNarrowScreen,
17+
showNav,
18+
setIsNavCollapsed,
19+
showOnlyEpochBar,
20+
blurBackground: isNarrowScreen && !isNavCollapsed && !showOnlyEpochBar,
21+
occupyRowWidth: showOnlyEpochBar || (!isNarrowScreen && !isNavCollapsed),
22+
};
23+
}

src/routes/__root.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import StartupProgress from "../features/StartupProgress";
55
import Toast from "../features/Toast";
66
import Navigation from "../features/Navigation";
77
import Header from "../features/Header";
8-
import { useMedia } from "react-use";
9-
import { isNavCollapsedAtom } from "../atoms";
10-
import { useAtom } from "jotai";
11-
import { headerSpacing, narrowNavMedia, slotsNavSpacing } from "../consts";
8+
import { headerSpacing, slotsNavSpacing } from "../consts";
129
import NavBlur from "../features/Navigation/NavBlur";
1310
import { useCurrentRoute } from "../hooks/useCurrentRoute";
11+
import { useSlotsNavigation } from "../hooks/useSlotsNavigation";
1412

1513
// import { TanStackRouterDevtools } from '@tanstack/router-devtools'
1614

@@ -59,14 +57,14 @@ function Root() {
5957
}
6058

6159
function OutletContainer() {
62-
const isNarrow = useMedia(narrowNavMedia);
63-
const [isNavCollapsed, setIsNavCollapsed] = useAtom(isNavCollapsedAtom);
6460
const isSchedule = useCurrentRoute() === "Schedule";
61+
const { setIsNavCollapsed, isNarrowScreen, occupyRowWidth, blurBackground } =
62+
useSlotsNavigation();
6563

6664
useEffect(() => {
6765
// automatically open / close on narrow switch
68-
setIsNavCollapsed(isNarrow);
69-
}, [isNarrow, setIsNavCollapsed]);
66+
setIsNavCollapsed(isNarrowScreen);
67+
}, [isNarrowScreen, setIsNavCollapsed]);
7068

7169
return (
7270
<Box
@@ -75,13 +73,13 @@ function OutletContainer() {
7573
minWidth="0"
7674
pb="2"
7775
pl={
78-
isNarrow || isNavCollapsed || isSchedule
76+
isSchedule || !occupyRowWidth
7977
? "0px"
8078
: `${headerSpacing - slotsNavSpacing}px`
8179
}
8280
>
8381
<Outlet />
84-
{isNarrow && !isNavCollapsed && <NavBlur />}
82+
{blurBackground && <NavBlur />}
8583
</Box>
8684
);
8785
}

0 commit comments

Comments
 (0)