fix(downloads): show total size after completion

This commit is contained in:
NimBold
2026-07-15 21:30:01 +03:30
parent ed54a048ab
commit 9f333618fc
4 changed files with 33 additions and 8 deletions
+9 -4
View File
@@ -8,6 +8,7 @@ import { canPauseDownload, canStartDownload, startActionLabel } from '../utils/d
import { isActiveDownloadStatus } from '../utils/downloads';
import {
downloadProgressColorClass,
formatDownloadTotal,
resolveDownloadSizeDisplay
} from '../utils/downloadProgress';
@@ -74,7 +75,11 @@ export const DownloadItem = React.memo<DownloadItemProps>(({
totalIsEstimate: liveProgress?.total_is_estimate ?? download.totalIsEstimate,
fallbackSize: download.size
});
const hasDownloadedAmount = Boolean(sizeDisplay.downloaded && sizeDisplay.total);
const hasDownloadedAmount = download.status !== 'completed' &&
Boolean(sizeDisplay.downloaded && sizeDisplay.total);
const completedSizeLabel = download.status === 'completed'
? formatDownloadTotal(sizeDisplay)
: sizeDisplay.fallback;
return (
<div
@@ -100,10 +105,10 @@ export const DownloadItem = React.memo<DownloadItemProps>(({
className="tabular-nums"
title={hasDownloadedAmount
? `${sizeDisplay.downloaded} downloaded of ${sizeDisplay.totalIsEstimate ? '~' : ''}${sizeDisplay.total} ${sizeDisplay.unit}`
: sizeDisplay.fallback}
: completedSizeLabel}
aria-label={hasDownloadedAmount
? `${sizeDisplay.downloaded} downloaded of ${sizeDisplay.totalIsEstimate ? 'approximately ' : ''}${sizeDisplay.total} ${sizeDisplay.unit}`
: sizeDisplay.fallback}
: completedSizeLabel}
>
{hasDownloadedAmount ? (
<>
@@ -113,7 +118,7 @@ export const DownloadItem = React.memo<DownloadItemProps>(({
{sizeDisplay.totalIsEstimate ? '~' : ''}{sizeDisplay.total} {sizeDisplay.unit}
</span>
</>
) : sizeDisplay.fallback}
) : completedSizeLabel}
</span>
</div>
+8 -3
View File
@@ -12,6 +12,7 @@ import {
} from '../utils/downloadActions';
import {
downloadProgressColorClass,
formatDownloadTotal,
resolveDownloadSizeDisplay
} from '../utils/downloadProgress';
@@ -195,7 +196,11 @@ export const PropertiesModal = () => {
totalIsEstimate: liveProgress?.total_is_estimate ?? item.totalIsEstimate,
fallbackSize: item.size
});
const hasDownloadedAmount = Boolean(sizeDisplay.downloaded && sizeDisplay.total);
const hasDownloadedAmount = item.status !== 'completed' &&
Boolean(sizeDisplay.downloaded && sizeDisplay.total);
const completedSizeLabel = item.status === 'completed'
? formatDownloadTotal(sizeDisplay)
: sizeDisplay.fallback;
let statusColor = 'text-text-secondary';
let StatusIcon = Info;
@@ -238,7 +243,7 @@ export const PropertiesModal = () => {
className="truncate"
title={hasDownloadedAmount
? `${sizeDisplay.downloaded} downloaded of ${sizeDisplay.totalIsEstimate ? 'approximately ' : ''}${sizeDisplay.total} ${sizeDisplay.unit}`
: sizeDisplay.fallback}
: completedSizeLabel}
>
{hasDownloadedAmount ? (
<>
@@ -248,7 +253,7 @@ export const PropertiesModal = () => {
{sizeDisplay.totalIsEstimate ? '~' : ''}{sizeDisplay.total} {sizeDisplay.unit}
</span>
</>
) : sizeDisplay.fallback}
) : completedSizeLabel}
</span>
</div>
<div className="flex gap-1.5 min-w-0"><span className="text-text-muted font-medium w-[40px] shrink-0">Speed</span><span className="text-text-secondary truncate">{displayedSpeed}</span></div>
+11 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { formatDownloadBytes, resolveDownloadSizeDisplay } from './downloadProgress';
import { formatDownloadBytes, formatDownloadTotal, resolveDownloadSizeDisplay } from './downloadProgress';
describe('download progress size display', () => {
it('formats byte counts using the binary units used by the download engines', () => {
@@ -33,4 +33,14 @@ describe('download progress size display', () => {
unit: 'GB'
});
});
it('formats a completed download using only its total size', () => {
const display = resolveDownloadSizeDisplay({
downloadedBytes: 1.2 * 1024 ** 3,
totalBytes: 2.4 * 1024 ** 3,
fallbackSize: '2.4 GB'
});
expect(formatDownloadTotal(display)).toBe('2.40 GB');
});
});
+5
View File
@@ -34,6 +34,11 @@ export const formatDownloadBytes = (bytes: number): string => {
return `${formatDownloadBytesInUnit(bytes, unitIndex)} ${BYTE_UNITS[unitIndex]}`;
};
export const formatDownloadTotal = (display: DownloadSizeDisplay): string =>
display.total && display.unit
? `${display.totalIsEstimate ? '~' : ''}${display.total} ${display.unit}`
: display.fallback;
export const resolveDownloadSizeDisplay = ({
downloadedBytes,
totalBytes,