fix(downloads): stabilize remaining metric updates
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user