From 248fb1046e86d85ae57e0b7160aef4065bb432a7 Mon Sep 17 00:00:00 2001 From: Kasper Seweryn Date: Fri, 3 Mar 2023 09:13:40 +0100 Subject: [PATCH] feat: skip css updates if progress hasn't changed Part-of: --- front/src/composables/audio/player.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/front/src/composables/audio/player.ts b/front/src/composables/audio/player.ts index 7490326f8..1fae61beb 100644 --- a/front/src/composables/audio/player.ts +++ b/front/src/composables/audio/player.ts @@ -167,12 +167,20 @@ export const usePlayer = createGlobalState(() => { }, 1000) // Progress + let lastProgress = 0 useRafFn(() => { const sound = currentSound.value - document.documentElement.style.setProperty('--fw-track-progress', sound - ? `${(sound.currentTime / sound.duration * 100).toFixed(Math.log(window.innerWidth))}%` - : '0' - ) + const progress = sound + ? +(sound.currentTime / sound.duration * 100).toFixed(Math.log(window.innerWidth)) + : 0 + + if (progress !== lastProgress) { + lastProgress = !isNaN(progress) + ? progress + : 0 + + document.documentElement.style.setProperty('--fw-track-progress', `${lastProgress}%`) + } }) // Loading