From dfd278a7135e97190d550a9070373372a61340ad Mon Sep 17 00:00:00 2001 From: Malted Date: Fri, 6 Sep 2024 16:52:05 -0400 Subject: [PATCH] Fix File & repl counters --- components/replit/scale-up.js | 14 ++++++++++---- pages/replit.js | 2 -- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/components/replit/scale-up.js b/components/replit/scale-up.js index f49bff6c..11c903e3 100644 --- a/components/replit/scale-up.js +++ b/components/replit/scale-up.js @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react' +import React, { useState, useEffect, useRef } from 'react' const easeInOutExpo = x => x === 0 @@ -11,8 +11,11 @@ const easeInOutExpo = x => const ScaleUp = ({ number, from = 0 }) => { const [displayNumber, setDisplayNumber] = useState(from) + const previousNumberRef = useRef(from) useEffect(() => { + const startValue = previousNumberRef.current + console.warn(`scaling from ${startValue} to ${number}`) const duration = 2000 const startTime = performance.now() @@ -20,17 +23,20 @@ const ScaleUp = ({ number, from = 0 }) => { const time = performance.now() - startTime const progress = time / duration const easedProgress = easeInOutExpo(progress) - - setDisplayNumber(Math.round(number * easedProgress)) + const currentValue = startValue + (number - startValue) * easedProgress + setDisplayNumber(Math.round(currentValue)) if (progress < 1) { requestAnimationFrame(animate) } else { setDisplayNumber(number) + previousNumberRef.current = number } } - requestAnimationFrame(animate) + if (startValue !== number) { + requestAnimationFrame(animate) + } }, [number]) return {displayNumber} diff --git a/pages/replit.js b/pages/replit.js index eb33b94d..ce506d71 100644 --- a/pages/replit.js +++ b/pages/replit.js @@ -35,8 +35,6 @@ const ReplitPage = () => { if (!response.ok) throw new Error('Failed to fetch progress') const data = await response.json() console.info(data) - oldFileCount = progress.file_count - oldReplCount = formData.repl_count setProgress(data) await fetchStats()