mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-11 03:59:09 +00:00
22 lines
676 B
TypeScript
22 lines
676 B
TypeScript
import type { DownloadItem } from '../bindings/DownloadItem';
|
|
import { isActiveDownloadStatus } from './downloads';
|
|
|
|
export type SchedulerCompletionState = 'active' | 'completed' | 'incomplete';
|
|
|
|
export const schedulerCompletionState = (
|
|
downloads: DownloadItem[],
|
|
schedulerActiveDownloadIds: string[],
|
|
): SchedulerCompletionState => {
|
|
const scheduledItems = schedulerActiveDownloadIds.map(id =>
|
|
downloads.find(download => download.id === id)
|
|
);
|
|
|
|
if (scheduledItems.some(item => item && isActiveDownloadStatus(item.status))) {
|
|
return 'active';
|
|
}
|
|
|
|
return scheduledItems.every(item => item?.status === 'completed')
|
|
? 'completed'
|
|
: 'incomplete';
|
|
};
|