mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-09 10:49:29 +00:00
fix(ui): refine page transitions and bulk actions
This commit is contained in:
@@ -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+');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user