Fix File & repl counters

This commit is contained in:
Malted 2024-09-06 16:52:05 -04:00
parent fb87cd55ac
commit dfd278a713
No known key found for this signature in database
2 changed files with 10 additions and 6 deletions

View file

@ -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 <span>{displayNumber}</span>

View file

@ -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()