-
Notifications
You must be signed in to change notification settings - Fork 5
feat: shreds slot labels #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: amliu/navigation1
Are you sure you want to change the base?
Changes from 3 commits
b54404c
0d34304
7ab605a
c528ff6
13ac8ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import { useAtomValue } from "jotai"; | ||
| import { Flex, Text } from "@radix-ui/themes"; | ||
| import { getSlotGroupLabelId, getSlotLabelId } from "./utils"; | ||
| import styles from "./shreds.module.css"; | ||
| import { useMemo } from "react"; | ||
| import { slotsPerLeader } from "../../../consts"; | ||
| import { shredsAtoms } from "./atoms"; | ||
| import { useSlotInfo } from "../../../hooks/useSlotInfo"; | ||
| import clsx from "clsx"; | ||
| import PeerIcon from "../../../components/PeerIcon"; | ||
| import { skippedClusterSlotsAtom } from "../../../atoms"; | ||
| import { isStartupProgressVisibleAtom } from "../../StartupProgress/atoms"; | ||
|
|
||
| const height = 30; | ||
|
|
||
| /** | ||
| * Labels for shreds slots. | ||
| * Don't render during startup, because there will be multiple overlapping slots | ||
| * during the catching up phase. | ||
| */ | ||
| export default function ShredsSlotLabels() { | ||
| const isStartup = useAtomValue(isStartupProgressVisibleAtom); | ||
| const groupLeaderSlots = useAtomValue(shredsAtoms.groupLeaderSlots); | ||
|
|
||
| if (isStartup) return; | ||
|
|
||
| return ( | ||
| <Flex | ||
| overflow="hidden" | ||
| position="relative" | ||
| // extra space for borders | ||
| height={`${height + 2}px`} | ||
|
||
| style={{ opacity: 0.8 }} | ||
| > | ||
| {groupLeaderSlots.map((slot) => ( | ||
| <SlotGroupLabel key={slot} firstSlot={slot} /> | ||
| ))} | ||
| </Flex> | ||
| ); | ||
| } | ||
|
|
||
| interface SlotGroupLabelProps { | ||
| firstSlot: number; | ||
| } | ||
| function SlotGroupLabel({ firstSlot }: SlotGroupLabelProps) { | ||
| const { peer, name, isLeader } = useSlotInfo(firstSlot); | ||
| const slots = useMemo(() => { | ||
| return Array.from({ length: slotsPerLeader }, (_, i) => firstSlot + i); | ||
| }, [firstSlot]); | ||
|
|
||
| const skippedClusterSlots = useAtomValue(skippedClusterSlotsAtom); | ||
| const skippedSlots = useMemo(() => { | ||
| const skipped = new Set<number>(); | ||
| for (const slot of slots) { | ||
| if (skippedClusterSlots.has(slot)) { | ||
| skipped.add(slot); | ||
| } | ||
| } | ||
| return skipped; | ||
| }, [slots, skippedClusterSlots]); | ||
|
|
||
| return ( | ||
| <Flex | ||
| height={`${height}px`} | ||
| direction="column" | ||
| gap="2px" | ||
| position="absolute" | ||
| align="center" | ||
| overflow="hidden" | ||
| id={getSlotGroupLabelId(firstSlot)} | ||
| className={clsx(styles.slotGroupLabel, { | ||
| [styles.you]: isLeader, | ||
| })} | ||
| > | ||
| <Flex | ||
| align="center" | ||
| flexGrow="1" | ||
| px="2px" | ||
| className={clsx(styles.slotGroupTopContainer, { | ||
| [styles.skipped]: skippedSlots.size > 0, | ||
| })} | ||
| > | ||
| <Flex | ||
| justify="center" | ||
| align="center" | ||
| width="100%" | ||
| gap="4px" | ||
| wrap="nowrap" | ||
| className={styles.slotGroupNameContainer} | ||
| > | ||
| <PeerIcon | ||
| url={peer?.info?.icon_url} | ||
| size={17} | ||
| isYou={isLeader} | ||
| hideTooltip | ||
| /> | ||
| <Text className={styles.name}>{name}</Text> | ||
| </Flex> | ||
| </Flex> | ||
|
|
||
| <Flex | ||
| width="100%" | ||
| height="3px" | ||
| position="relative" | ||
| overflow="hidden" | ||
| className={styles.slotBarsContainer} | ||
| > | ||
| {slots.map((slot) => ( | ||
| <div | ||
| key={slot} | ||
| className={clsx(styles.slotBar, { | ||
| [styles.skipped]: skippedSlots.has(slot), | ||
| })} | ||
| id={getSlotLabelId(slot)} | ||
| /> | ||
| ))} | ||
| </Flex> | ||
| </Flex> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| .slot-group-label { | ||
| --group-x: -100000px; | ||
| --group-name-opacity: 0; | ||
|
|
||
| background-color: #080b13; | ||
| border-radius: 2px; | ||
| border: 1px solid #3c4652; | ||
| will-change: transform, width; | ||
|
||
| transform: translate(var(--group-x)); | ||
|
|
||
| &.you { | ||
| border: 1px solid #2a7edf; | ||
| } | ||
|
|
||
| .slot-group-top-container { | ||
| width: 100%; | ||
| background-color: #15181e; | ||
|
|
||
| &.skipped { | ||
| background-color: var(--red-2); | ||
| } | ||
|
|
||
| .slot-group-name-container { | ||
| opacity: var(--group-name-opacity); | ||
| transition: opacity 0.8s; | ||
| will-change: opacity; | ||
|
|
||
| .name { | ||
| font-size: 14px; | ||
| line-height: normal; | ||
| color: #ccc; | ||
| white-space: nowrap; | ||
| overflow: hidden; | ||
| text-overflow: ellipsis; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .slot-bars-container { | ||
| flex-shrink: 0; | ||
| .slot-bar { | ||
| --slot-x: 0; | ||
|
|
||
| position: absolute; | ||
| will-change: transform, width; | ||
| transform: translate(var(--slot-x)); | ||
|
|
||
| height: 100%; | ||
| border-radius: 3px; | ||
| &:nth-child(1) { | ||
| background-color: var(--blue-7); | ||
| } | ||
| &:nth-child(2) { | ||
| background-color: var(--blue-6); | ||
| } | ||
| &:nth-child(3) { | ||
| background-color: var(--blue-5); | ||
| } | ||
| &:nth-child(4) { | ||
| background-color: var(--blue-4); | ||
| } | ||
|
|
||
| &.skipped { | ||
| background-color: var(--red-7); | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't get why we need this ref? This isn't used anywhere but the plugin right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so I can compare the last + current draw label positions, and not update width / x position if it hasn't changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but why a ref vs just making some vars in your plugin? Since you're not consuming the ref from anywhere outside the plugin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or are you re-initializing your plugin and you need a stable reference?