Reduce intesity of Timer.tsx ticks

This commit is contained in:
0x1eef 2024-05-24 15:57:42 -03:00
parent 7d8867e991
commit e8f2f11734
2 changed files with 8 additions and 5 deletions

View file

@ -39,7 +39,7 @@ export function Timer({ locale, surah, ayah, isPaused, audioStatus, onComplete }
} else if (ms <= 0) { } else if (ms <= 0) {
onComplete(surah, ayah); onComplete(surah, ayah);
} else { } else {
const tid = setTimeout(() => setMs(ms - 100), 100); const tid = setTimeout(() => setMs(ms - 1000), 1000);
return () => clearTimeout(tid); return () => clearTimeout(tid);
} }
}, [isStalled, isPaused, ms]); }, [isStalled, isPaused, ms]);
@ -50,7 +50,9 @@ export function Timer({ locale, surah, ayah, isPaused, audioStatus, onComplete }
return ( return (
<div className="timer text-base w-10 flex justify-end"> <div className="timer text-base w-10 flex justify-end">
{!ms || ms / 1000 <= 0 ? formatNumber(locale, 0) : formatNumber(locale, ms / 1000)} {!ms || ms / 1000 <= 0
? formatNumber(locale, 0)
: formatNumber(locale, ms / 1000, { maximumFractionDigits: 0 })}
</div> </div>
); );
} }

View file

@ -17,8 +17,9 @@ export function T(phrases: PhraseMap<string>): TFunction {
}; };
} }
export function formatNumber(locale: TLocale, num: number): string { export function formatNumber(locale: TLocale, num: number, options = {}): string {
const numl = locale.name === "ar" ? "ar-SA" : locale.name; const numl = locale.name === "ar" ? "ar-SA" : locale.name;
const options = { maximumFractionDigits: 1 }; return new Intl.NumberFormat(numl, { maximumFractionDigits: 1, ...options }).format(
return new Intl.NumberFormat(numl, options).format(num); num,
);
} }