Skip to content

Commit da87e7f

Browse files
committed
fix(web): keep sidebar terminal pulses in sync
1 parent a467177 commit da87e7f

4 files changed

Lines changed: 69 additions & 4 deletions

File tree

‎apps/web/src/components/LegacySidebar.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
prStatusIndicator,
1818
PrStatusTooltipContent,
1919
terminalStatusFromRunningIds,
20+
synchronizeTerminalPulse,
2021
ThreadStatusLabel,
2122
ThreadWorktreeIndicator,
2223
useLinkedThreadPullRequest,
@@ -824,7 +825,10 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
824825
/>
825826
}
826827
>
827-
<TerminalIcon className="size-3" />
828+
<TerminalIcon
829+
className={`size-3 ${terminalStatus.pulse ? "animate-status-pulse" : ""}`}
830+
onAnimationStart={synchronizeTerminalPulse}
831+
/>
828832
</TooltipTrigger>
829833
<TooltipPopup side="top">{terminalStatus.label}</TooltipPopup>
830834
</Tooltip>

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ import {
205205
prStatusIndicator,
206206
resolveThreadPullRequestBadge,
207207
terminalStatusFromRunningIds,
208+
synchronizeTerminalPulse,
208209
type TerminalStatusIndicator,
209210
useLinkedThreadPullRequest,
210211
} from "./ThreadStatusIndicators";
@@ -1526,7 +1527,10 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
15261527
data-testid={`sidebar-terminal-status-${thread.id}`}
15271528
className={cn("inline-flex shrink-0 items-center justify-center", terminalStatus.colorClass)}
15281529
>
1529-
<TerminalIcon className="size-3.5" />
1530+
<TerminalIcon
1531+
className={cn("size-3.5", terminalStatus.pulse && "animate-status-pulse")}
1532+
onAnimationStart={synchronizeTerminalPulse}
1533+
/>
15301534
</span>
15311535
) : null;
15321536
// Same pen the new-thread draft rows lead with, so both kinds of unsent

‎apps/web/src/components/ThreadStatusIndicators.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,55 @@
11
import { ProjectId, type PullRequestSummary, type VcsStatusResult } from "@t3tools/contracts";
22
import { describe, expect, it } from "@effect/vitest";
3+
import type { AnimationEvent } from "react";
34

45
import {
56
ChangeRequestStatusIcon,
67
prStatusIndicator,
78
resolveThreadPullRequestBadgePresentation,
9+
synchronizeTerminalPulse,
810
} from "./ThreadStatusIndicators";
911
import { newestPullRequestSummary } from "../state/pullRequests";
1012
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
1113

14+
describe("synchronizeTerminalPulse", () => {
15+
function animationStartEvent(animations: Animation[], animationName = "status-pulse") {
16+
return {
17+
animationName,
18+
currentTarget: { getAnimations: () => animations },
19+
} as AnimationEvent<SVGSVGElement>;
20+
}
21+
22+
it("aligns terminal pulses started at different times to the same document clock", () => {
23+
const first = { animationName: "status-pulse", startTime: 125 } as CSSAnimation;
24+
const later = { animationName: "status-pulse", startTime: 975 } as CSSAnimation;
25+
26+
synchronizeTerminalPulse(animationStartEvent([first]));
27+
synchronizeTerminalPulse(animationStartEvent([later]));
28+
29+
expect([first.startTime, later.startTime]).toEqual([0, 0]);
30+
});
31+
32+
it("does not change other CSS or Web Animations on the icon", () => {
33+
const pulse = { animationName: "status-pulse", startTime: 975 } as CSSAnimation;
34+
const otherCss = { animationName: "other-animation", startTime: 125 } as CSSAnimation;
35+
const otherAnimation = { startTime: 250 } as Animation;
36+
37+
synchronizeTerminalPulse(animationStartEvent([pulse, otherCss, otherAnimation]));
38+
39+
expect(pulse.startTime).toBe(0);
40+
expect(otherCss.startTime).toBe(125);
41+
expect(otherAnimation.startTime).toBe(250);
42+
});
43+
44+
it("ignores the start of another animation", () => {
45+
const pulse = { animationName: "status-pulse", startTime: 975 } as CSSAnimation;
46+
47+
synchronizeTerminalPulse(animationStartEvent([pulse], "other-animation"));
48+
49+
expect(pulse.startTime).toBe(975);
50+
});
51+
});
52+
1253
describe("ChangeRequestStatusIcon", () => {
1354
it.each([
1455
["open", "open", false, PullRequestGlyph.pullRequest],

‎apps/web/src/components/ThreadStatusIndicators.tsx‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
type ThreadPullRequestBadge,
1616
} from "@t3tools/shared/threadPullRequests";
1717
import { FolderGit2Icon, TerminalIcon } from "lucide-react";
18-
import { useMemo, type MouseEvent } from "react";
18+
import { useMemo, type AnimationEvent, type MouseEvent } from "react";
1919
import { buttonVariants, InlineButton } from "./ui/button";
2020
import { cn } from "../lib/utils";
2121
import { useEnvironment, usePrimaryEnvironmentId } from "../state/environments";
@@ -51,6 +51,7 @@ export interface PrStatusIndicator {
5151
export interface TerminalStatusIndicator {
5252
label: "Terminal process running";
5353
colorClass: string;
54+
pulse: boolean;
5455
}
5556

5657
export type ThreadPr = VcsStatusResult["pr"];
@@ -370,9 +371,21 @@ export function terminalStatusFromRunningIds(
370371
return {
371372
label: "Terminal process running",
372373
colorClass: "text-teal-600 dark:text-teal-300/90",
374+
pulse: true,
373375
};
374376
}
375377

378+
/** Align newly started pulses with the document clock without a timer or frame loop. */
379+
export function synchronizeTerminalPulse(event: AnimationEvent<SVGSVGElement>) {
380+
if (event.animationName !== "status-pulse") return;
381+
382+
for (const animation of event.currentTarget.getAnimations()) {
383+
if ("animationName" in animation && animation.animationName === "status-pulse") {
384+
animation.startTime = 0;
385+
}
386+
}
387+
}
388+
376389
export function ThreadWorktreeIndicator({
377390
thread,
378391
}: {
@@ -560,7 +573,10 @@ export function ThreadRowTrailingStatus({ thread }: { thread: SidebarThreadSumma
560573
/>
561574
}
562575
>
563-
<TerminalIcon className="size-3" />
576+
<TerminalIcon
577+
className={`size-3 ${terminalStatus.pulse ? "animate-status-pulse" : ""}`}
578+
onAnimationStart={synchronizeTerminalPulse}
579+
/>
564580
</TooltipTrigger>
565581
<TooltipPopup side="top">{terminalStatus.label}</TooltipPopup>
566582
</Tooltip>

0 commit comments

Comments
 (0)