Skip to content

Commit 609e5d3

Browse files
chore: address feedback
1 parent 8c851af commit 609e5d3

File tree

2 files changed

+26
-42
lines changed

2 files changed

+26
-42
lines changed

src/features/Overview/ShredsProgression/ShredsSlotLabels.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default function ShredsSlotLabels() {
3030
position="relative"
3131
// extra space for borders
3232
height={`${height + 2}px`}
33+
style={{ opacity: 0.8 }}
3334
>
3435
{groupLeaderSlots.map((slot) => (
3536
<SlotGroupLabel key={slot} firstSlot={slot} />

src/features/Overview/ShredsProgression/shredsProgressionPlugin.ts

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -655,46 +655,28 @@ function getGroupTsDeltas(
655655
} = {};
656656

657657
for (const leaderSlot of groupLeaderSlots) {
658-
// get first defined slot
659-
// ignore missing slots at the start when positioning group
660-
let firstDefinedSlot = undefined;
661-
for (
662-
let slotNumber = leaderSlot;
663-
slotNumber < leaderSlot + slotsPerLeader;
664-
slotNumber++
665-
) {
666-
if (slotNumber in slotTsDeltas) {
667-
firstDefinedSlot = slotNumber;
668-
break;
669-
}
670-
}
658+
const slotNumbers = Array.from(
659+
{ length: slotsPerLeader },
660+
(_, i) => i + leaderSlot,
661+
);
662+
const definedSlotTsDeltas = slotNumbers
663+
.map((slotNumber) => slotTsDeltas[slotNumber])
664+
.filter((v) => v !== undefined);
671665

672-
if (firstDefinedSlot === undefined) {
666+
if (definedSlotTsDeltas.length === 0) {
673667
continue;
674668
}
675669

676-
let groupStart = Infinity;
677-
let groupEnd = -Infinity;
678-
679-
for (
680-
let slotNumber = firstDefinedSlot;
681-
slotNumber < leaderSlot + slotsPerLeader;
682-
slotNumber++
683-
) {
684-
const slotTsDeltaRange = slotTsDeltas[slotNumber];
685-
const slotStart = slotTsDeltaRange?.[0];
686-
const slotEnd = slotTsDeltaRange?.[1];
670+
// ignore missing slots at the start when positioning group
671+
const minStart = Math.min(...definedSlotTsDeltas.map(([start]) => start));
672+
const ends = definedSlotTsDeltas.map(([, end]) => end);
673+
const definedEnds = ends.filter((end) => end !== undefined);
687674

688-
if (slotStart != null) {
689-
groupStart = Math.min(groupStart, slotStart);
690-
}
691-
// undefined slot end will extend to max x
692-
groupEnd = Math.max(groupEnd, slotEnd ?? Infinity);
693-
}
675+
// undefined slot end will extend to max x
676+
const hasUndefinedEnd = ends.length > definedEnds.length;
677+
const maxEnd = hasUndefinedEnd ? undefined : Math.max(...definedEnds);
694678

695-
// replace Infinity with undefined for end
696-
const end = groupEnd === Infinity ? undefined : groupEnd;
697-
groupTsDeltas[leaderSlot] = [groupStart, end];
679+
groupTsDeltas[leaderSlot] = [minStart, maxEnd];
698680
}
699681
return groupTsDeltas;
700682
}
@@ -737,6 +719,7 @@ function moveLabelPosition(
737719

738720
const key = isGroup ? "groups" : "slots";
739721
const positionsToMutate = labelPositionsToMutate[key];
722+
const xPosProp = isGroup ? "--group-x" : "--slot-x";
740723

741724
const isVisible = !!position;
742725
const prevPositions = prevLabelPositions?.[key];
@@ -745,8 +728,7 @@ function moveLabelPosition(
745728
if (!isVisible) {
746729
if (forceUpdates || prevVisible) {
747730
// hide
748-
const prop = isGroup ? "--group-x" : "--slot-x";
749-
el.style.setProperty(prop, isVisible ? "0" : "-100000px");
731+
el.style.setProperty(xPosProp, "-100000px");
750732
}
751733
return;
752734
}
@@ -757,25 +739,26 @@ function moveLabelPosition(
757739
const prevXPos = prevPositions?.[slotNumber]?.[0];
758740

759741
if (forceUpdates || xPos !== prevXPos) {
760-
const prop = isGroup ? "--group-x" : "--slot-x";
761-
el.style.setProperty(prop, `${xPos}px`);
742+
el.style.setProperty(xPosProp, `${xPos}px`);
762743
}
763744

764745
// no width data -- extend to max width
765746
const width = position[1];
766747
const isExtended = position[1] == null;
767-
// extend past maxXPos to hide right border
768-
const extendedWidth = width ?? maxXPos + 1 - xPos;
769748
const prevWidth = prevPositions?.[slotNumber]?.[1];
749+
// extend past maxXPos to hide right border
750+
const newWidth = isExtended ? maxXPos - xPos + 1 : width;
770751

771-
if (forceUpdates || extendedWidth !== prevWidth) {
772-
el.style.width = `${extendedWidth}px`;
752+
if (forceUpdates || newWidth !== prevWidth) {
753+
el.style.width = `${newWidth}px`;
773754
}
774755

775756
const wasPrevExtended =
776757
prevPositions?.[slotNumber] && prevPositions[slotNumber][1] == null;
777758

778759
if (isGroup && (forceUpdates || isExtended !== wasPrevExtended)) {
760+
// Extended groups don't have a defined end, so we don't know where to center the name text.
761+
// Set to opacity 0, and transition to 1 when the group end becomes defined.
779762
el.style.setProperty("--group-name-opacity", isExtended ? "0" : "1");
780763
}
781764
}

0 commit comments

Comments
 (0)