feat: skip css updates if progress hasn't changed

Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2346>
This commit is contained in:
Kasper Seweryn 2023-03-03 09:13:40 +01:00 committed by Marge
parent bbe2375f6b
commit 8ce20c5621
1 changed files with 12 additions and 4 deletions

View File

@ -167,12 +167,20 @@ export const usePlayer = createGlobalState(() => {
}, 1000) }, 1000)
// Progress // Progress
let lastProgress = 0
useRafFn(() => { useRafFn(() => {
const sound = currentSound.value const sound = currentSound.value
document.documentElement.style.setProperty('--fw-track-progress', sound const progress = sound
? `${(sound.currentTime / sound.duration * 100).toFixed(Math.log(window.innerWidth))}%` ? +(sound.currentTime / sound.duration * 100).toFixed(Math.log(window.innerWidth))
: '0' : 0
)
if (progress !== lastProgress) {
lastProgress = !isNaN(progress)
? progress
: 0
document.documentElement.style.setProperty('--fw-track-progress', `${lastProgress}%`)
}
}) })
// Loading // Loading