fix(downloads): stabilize remaining metric updates

This commit is contained in:
Sucukdeluxe
2026-08-25 05:22:42 +02:00
parent 9d3d627401
commit afcc1fe782
3 changed files with 20 additions and 4 deletions
+5 -1
View File
@@ -22,6 +22,10 @@ export function getRollingMetricDirection(previous: number, next: number): Rolli
return "none";
}
export function shouldAnimateRollingMetric(previousValue: string, nextValue: string): boolean {
return previousValue !== nextValue;
}
export function RollingMetricValue({ numericValue, value }: RollingMetricValueProps): ReactElement {
const previousRef = useRef({ numericValue, value });
const sequenceRef = useRef(0);
@@ -31,8 +35,8 @@ export function RollingMetricValue({ numericValue, value }: RollingMetricValuePr
useMetricLayoutEffect(() => {
const previous = previousRef.current;
if (previous.value === value && previous.numericValue === numericValue) return;
previousRef.current = { numericValue, value };
if (!shouldAnimateRollingMetric(previous.value, value)) return;
const direction = getRollingMetricDirection(previous.numericValue, numericValue);
if (direction === "none") {
setTransition(null);
@@ -117,8 +117,11 @@ export function getRemainingDownloadBytes(items: Iterable<DownloadItem>): { byte
}
export function formatRemainingDownloadBytes(summary: { bytes: number; unknownItems: number }): string {
if (summary.unknownItems <= 0) return humanSize(summary.bytes);
return summary.bytes > 0 ? `${humanSize(summary.bytes)}` : "Unbekannt";
const value = summary.bytes >= 1024 ** 4
? `${(summary.bytes / 1024 ** 4).toFixed(4)} TB`
: humanSize(summary.bytes);
if (summary.unknownItems <= 0) return value;
return summary.bytes > 0 ? `${value}` : "Unbekannt";
}
export function formatRemainingDownloadTooltip(summary: { bytes: number; unknownItems: number }): string {