Skip to content

Commit 29cd7d2

Browse files
aidenybaiamiagent
andcommitted
skip animation on repeat visits using localStorage
Generated with [Ami](https://ami.dev) Co-Authored-By: Ami <noreply@ami.dev>
1 parent 7cec5fb commit 29cd7d2

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

packages/website/src/components/terminal.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const TOTAL_WARNING_COUNT = 14;
2626
const AFFECTED_FILE_COUNT = 18;
2727
const ELAPSED_TIME = "2.1s";
2828

29+
const ANIMATION_COMPLETED_KEY = "react-doctor-animation-completed";
2930
const COMMAND = "npx -y react-doctor@latest .";
3031
const GITHUB_URL = "https://github.com/aidenybai/react-doctor";
3132
const GITHUB_ICON_PATH =
@@ -277,10 +278,38 @@ const INITIAL_STATE: AnimationState = {
277278
showSummary: false,
278279
};
279280

281+
const COMPLETED_STATE: AnimationState = {
282+
typedCommand: COMMAND,
283+
isTyping: false,
284+
showHeader: true,
285+
visibleDiagnosticCount: DIAGNOSTICS.length,
286+
showSeparator: true,
287+
score: TARGET_SCORE,
288+
showSummary: true,
289+
};
290+
291+
const didAnimationComplete = () => {
292+
try {
293+
return localStorage.getItem(ANIMATION_COMPLETED_KEY) === "true";
294+
} catch {
295+
return false;
296+
}
297+
};
298+
299+
const markAnimationCompleted = () => {
300+
try {
301+
localStorage.setItem(ANIMATION_COMPLETED_KEY, "true");
302+
} catch {}
303+
};
304+
280305
const Terminal = () => {
281-
const [state, setState] = useState<AnimationState>(INITIAL_STATE);
306+
const [state, setState] = useState<AnimationState>(
307+
didAnimationComplete() ? COMPLETED_STATE : INITIAL_STATE,
308+
);
282309

283310
useEffect(() => {
311+
if (didAnimationComplete()) return;
312+
284313
let cancelled = false;
285314

286315
const update = (patch: Partial<AnimationState>) => {
@@ -324,6 +353,7 @@ const Terminal = () => {
324353
await sleep(POST_SCORE_DELAY_MS);
325354
if (cancelled) return;
326355
update({ showSummary: true });
356+
markAnimationCompleted();
327357
};
328358

329359
run();

0 commit comments

Comments
 (0)