fix(web): reset update check animation latch
Co-authored-by: Wout Stiens <[email protected]>
This commit is contained in:
1 parent
2cc713b3b3
commit
ff762f8aa3
4 files changed
+63
-12
No files matched your search
@@ -1,7 +1,27 @@
|
||||
import { RefreshCwIcon } from "lucide-react";
|
||||
import type { AnimationEventHandler } from "react";
|
||||
|
||||
import { cn } from "../../lib/utils";
|
||||
|
||||
export function DesktopUpdateCheckIcon({ isAnimating }: { readonly isAnimating: boolean }) {
|
||||
return <RefreshCwIcon className={cn("size-4", isAnimating && "animate-spin-once")} />;
|
||||
export function shouldContinueDesktopUpdateCheckAnimation({
|
||||
isChecking,
|
||||
}: {
|
||||
readonly isChecking: boolean;
|
||||
}) {
|
||||
return isChecking;
|
||||
}
|
||||
|
||||
export function DesktopUpdateCheckIcon({
|
||||
isAnimating,
|
||||
onAnimationIteration,
|
||||
}: {
|
||||
readonly isAnimating: boolean;
|
||||
readonly onAnimationIteration?: AnimationEventHandler<SVGSVGElement>;
|
||||
}) {
|
||||
return (
|
||||
<RefreshCwIcon
|
||||
className={cn("size-4", isAnimating && "animate-spin")}
|
||||
onAnimationIteration={onAnimationIteration}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,18 +1,37 @@
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { DesktopUpdateCheckIcon } from "./DesktopUpdateCheckIcon";
|
||||
import {
|
||||
DesktopUpdateCheckIcon,
|
||||
shouldContinueDesktopUpdateCheckAnimation,
|
||||
} from "./DesktopUpdateCheckIcon";
|
||||
|
||||
describe("DesktopUpdateCheckIcon", () => {
|
||||
it("keeps the refresh icon spinning while a fast update check settles", () => {
|
||||
const markup = renderToStaticMarkup(<DesktopUpdateCheckIcon isAnimating />);
|
||||
|
||||
expect(markup).toContain("animate-spin-once");
|
||||
expect(markup).toContain("animate-spin");
|
||||
});
|
||||
|
||||
it("does not animate while idle", () => {
|
||||
const markup = renderToStaticMarkup(<DesktopUpdateCheckIcon isAnimating={false} />);
|
||||
|
||||
expect(markup).not.toContain("animate-spin-once");
|
||||
expect(markup).not.toContain("animate-spin");
|
||||
});
|
||||
|
||||
it("keeps status-driven checks spinning across rotations", () => {
|
||||
expect(
|
||||
shouldContinueDesktopUpdateCheckAnimation({
|
||||
isChecking: true,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("releases the manual animation latch after one rotation", () => {
|
||||
expect(
|
||||
shouldContinueDesktopUpdateCheckAnimation({
|
||||
isChecking: false,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import { DownloadIcon, RotateCwIcon, TriangleAlertIcon } from "lucide-react";
|
||||
import { useCallback, useState } from "react";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { isElectron } from "../../env";
|
||||
import { cn } from "../../lib/utils";
|
||||
import { ensureLocalApi } from "../../localApi";
|
||||
@@ -21,7 +21,10 @@ import { Alert, AlertDescription, AlertTitle } from "../ui/alert";
|
||||
import { Separator } from "../ui/separator";
|
||||
import { SidebarMenuItem } from "../ui/sidebar";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
|
||||
import { DesktopUpdateCheckIcon } from "./DesktopUpdateCheckIcon";
|
||||
import {
|
||||
DesktopUpdateCheckIcon,
|
||||
shouldContinueDesktopUpdateCheckAnimation,
|
||||
} from "./DesktopUpdateCheckIcon";
|
||||
|
||||
function keyReleaseNoteItems(items: ReadonlyArray<string>) {
|
||||
const occurrences = new Map<string, number>();
|
||||
@@ -111,7 +114,11 @@ export function SidebarUpdatePill() {
|
||||
function SidebarUpdateControl() {
|
||||
const state = useDesktopUpdateState();
|
||||
const [isActionPending, setIsActionPending] = useState(false);
|
||||
const [checkAnimationKey, setCheckAnimationKey] = useState(0);
|
||||
const [isCheckIconAnimating, setIsCheckIconAnimating] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (state?.status === "checking") setIsCheckIconAnimating(true);
|
||||
}, [state?.status]);
|
||||
|
||||
const action = state ? resolveDesktopUpdateButtonAction(state) : "none";
|
||||
const isDownloading = state?.status === "downloading";
|
||||
@@ -211,7 +218,7 @@ function SidebarUpdateControl() {
|
||||
return;
|
||||
}
|
||||
|
||||
setCheckAnimationKey((key) => key + 1);
|
||||
setIsCheckIconAnimating(true);
|
||||
void bridge
|
||||
.checkForUpdate()
|
||||
.then((result) => {
|
||||
@@ -237,6 +244,12 @@ function SidebarUpdateControl() {
|
||||
.finally(() => setIsActionPending(false));
|
||||
}, [action, disabled, isActionPending, state]);
|
||||
|
||||
const handleCheckAnimationIteration = useCallback(() => {
|
||||
setIsCheckIconAnimating(
|
||||
shouldContinueDesktopUpdateCheckAnimation({ isChecking: state?.status === "checking" }),
|
||||
);
|
||||
}, [state?.status]);
|
||||
|
||||
return (
|
||||
<SidebarMenuItem className="ml-auto shrink-0">
|
||||
<Tooltip>
|
||||
@@ -261,8 +274,8 @@ function SidebarUpdateControl() {
|
||||
<DownloadIcon className="size-4" />
|
||||
) : (
|
||||
<DesktopUpdateCheckIcon
|
||||
key={checkAnimationKey}
|
||||
isAnimating={checkAnimationKey > 0 || state?.status === "checking"}
|
||||
isAnimating={isCheckIconAnimating}
|
||||
onAnimationIteration={handleCheckAnimationIteration}
|
||||
/>
|
||||
)}
|
||||
</button>
|
||||
|
||||
@@ -140,7 +140,6 @@ html[data-mobile-composer-route-transition="true"]::view-transition-old(t3-mobil
|
||||
}
|
||||
|
||||
@theme inline {
|
||||
--animate-spin-once: spin 1s linear 1;
|
||||
--color-zinc-25: oklch(99.2% 0 0);
|
||||
--animate-skeleton: skeleton 2s infinite linear;
|
||||
/* Duty-cycled indicator animations: long holds with stepped ramps, so the
|
||||
|
||||
Reference in new issue
Block a user