mirror of
https://github.com/System-End/site.git
synced 2026-04-19 19:45:07 +00:00
Fix File & repl counters
This commit is contained in:
parent
fb87cd55ac
commit
dfd278a713
2 changed files with 10 additions and 6 deletions
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue