-
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
Open
asuzuki-jumptrading
wants to merge
5
commits into
amliu/navigation1
Choose a base branch
from
asuzuki/shreds-header
base: amliu/navigation1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b54404c
feat: shreds slot labels
asuzuki-jumptrading 0d34304
chore: color changes
asuzuki-jumptrading 7ab605a
chore: address feedback
asuzuki-jumptrading c528ff6
fix: opacity flicker
asuzuki-jumptrading 13ac8ff
chore: address comments
asuzuki-jumptrading File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
src/features/Overview/ShredsProgression/ShredsSlotLabels.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| 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; | ||
| 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); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?