fix(ui): refine page transitions and bulk actions

This commit is contained in:
NimBold
2026-07-28 22:39:00 +03:30
parent 62f8c83c57
commit 807663cf03
8 changed files with 175 additions and 28 deletions
+22
View File
@@ -3,6 +3,8 @@ import {
canPauseDownload,
canRedownload,
canStartDownload,
countDownloadActions,
formatDownloadActionCount,
getPauseResumeAction,
isIdentityLocked,
isTransferLocked,
@@ -48,4 +50,24 @@ describe('download action policy', () => {
expect(isIdentityLocked('completed')).toBe(true);
expect(isTransferLocked('completed')).toBe(false);
});
it('counts only eligible actions for a multi-selection', () => {
const counts = countDownloadActions([
{ status: 'queued' },
{ status: 'downloading' },
{ status: 'paused' },
{ status: 'ready' },
{ status: 'staged' },
{ status: 'failed' },
{ status: 'completed' },
]);
expect(counts).toEqual({ pause: 2, resume: 4 });
});
it('keeps large action badges compact without changing the accessible count', () => {
expect(formatDownloadActionCount(2)).toBe('2');
expect(formatDownloadActionCount(99)).toBe('99');
expect(formatDownloadActionCount(100)).toBe('99+');
});
});
+21
View File
@@ -26,6 +26,27 @@ export const canStartDownload = (status: DownloadStatus): boolean =>
export const canPauseDownload = (status: DownloadStatus): boolean =>
PAUSABLE_STATUSES.has(status);
export interface DownloadActionCounts {
pause: number;
resume: number;
}
/**
* Count the actions that a bulk pause/resume control can actually apply.
* Keep this derived from the same predicates used by the individual row
* buttons so a badge never promises to affect an ineligible item.
*/
export const countDownloadActions = (
downloads: ReadonlyArray<{ status: DownloadStatus }>
): DownloadActionCounts => downloads.reduce<DownloadActionCounts>((counts, download) => {
if (canPauseDownload(download.status)) counts.pause += 1;
if (canStartDownload(download.status)) counts.resume += 1;
return counts;
}, { pause: 0, resume: 0 });
export const formatDownloadActionCount = (count: number): string =>
count > 99 ? '99+' : String(count);
export type PauseResumeAction = 'pause' | 'resume';
export const getPauseResumeAction = (status: DownloadStatus): PauseResumeAction | null => {