Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions apps/code/src/renderer/components/DotsCircleSpinner.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
import { useEffect, useState } from "react";
import { useSyncExternalStore } from "react";

const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
const INTERVAL = 80;

let globalFrameIndex = 0;
let subscriberCount = 0;
let globalTimer: ReturnType<typeof setInterval> | null = null;
const listeners = new Set<() => void>();

function subscribe(callback: () => void) {
listeners.add(callback);
subscriberCount++;
if (subscriberCount === 1) {
globalTimer = setInterval(() => {
globalFrameIndex = (globalFrameIndex + 1) % FRAMES.length;
for (const listener of listeners) {
listener();
}
}, INTERVAL);
}
return () => {
listeners.delete(callback);
subscriberCount--;
if (subscriberCount === 0 && globalTimer) {
clearInterval(globalTimer);
globalTimer = null;
}
};
}

function getSnapshot() {
return globalFrameIndex;
}

interface DotsCircleSpinnerProps {
size?: number;
className?: string;
Expand All @@ -12,15 +42,7 @@ export function DotsCircleSpinner({
size = 12,
className,
}: DotsCircleSpinnerProps) {
const [frameIndex, setFrameIndex] = useState(0);

useEffect(() => {
const timer = setInterval(() => {
setFrameIndex((prev) => (prev + 1) % FRAMES.length);
}, INTERVAL);

return () => clearInterval(timer);
}, []);
const frameIndex = useSyncExternalStore(subscribe, getSnapshot);

return (
<span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,8 @@ function CloudStatusIcon({
if (taskRunStatus === "started" || taskRunStatus === "in_progress") {
return (
<Tooltip content="Cloud (running)" side="right">
<span className="relative flex items-center justify-center">
<CloudIcon size={ICON_SIZE} className="text-accent-11" />
<DotsCircleSpinner
size={8}
className="-right-0.5 -bottom-0.5 absolute text-accent-11"
/>
<span className="flex items-center justify-center">
<CloudIcon size={ICON_SIZE} className="ph-pulse" />
</span>
</Tooltip>
);
Expand Down
Loading