Skip to content
Merged
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
5 changes: 2 additions & 3 deletions src/components/focus/PixelArt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,15 @@ interface Refill {
readonly to: number;
}

const prefersReducedMotion = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;

/** Shows the coffee frame; when the cup jumps to a fuller level it fizzes up to it on a canvas over the empty cup. */
function CoffeeCup({ frame, frames, className, label }: { frame: number; frames: number; className: string; label: string }) {
const canvasRef = useRef<HTMLCanvasElement>(null);
const [lastFrame, setLastFrame] = useState(frame);
const [refill, setRefill] = useState<Refill | null>(null);
if (frame !== lastFrame) {
setLastFrame(frame);
if (isRefill(lastFrame, frame) && !prefersReducedMotion()) setRefill({ from: lastFrame, to: frame });
// Plays even with reduced motion on: the owner chose to always show this short refill.
if (isRefill(lastFrame, frame)) setRefill({ from: lastFrame, to: frame });
}

useEffect(() => {
Expand Down
Loading