1 import { useEffect } from 'react';
3 import { c } from 'ttag';
5 import type { NotificationType } from '@proton/components';
6 import { useNotifications } from '@proton/components';
12 isTransferPausedByConnection,
13 } from '../../../utils/transfer';
14 import type { Download } from '../../TransferManager/transfer';
16 export function useDownloadNotifications(downloads: Download[]) {
17 const { createNotification, hideNotification } = useNotifications();
19 let type: NotificationType = 'info';
20 let text: string | undefined;
21 let expiration: number | undefined = -1;
22 let showCloseButton = false;
24 if (downloads.some(isTransferPausedByConnection)) {
26 text = c('Info').t`Download paused due to connection issue; it will resume automatically`;
29 if (downloads.some(isTransferDone)) {
30 text = c('Info').t`Download finished`;
31 expiration = undefined;
32 showCloseButton = true;
35 if (downloads.some(isTransferFailed)) {
37 const error = downloads[0].error;
39 text = c('Info').t`Download failed due to ${error}`;
41 text = c('Info').t`Download failed`;
43 showCloseButton = true;
46 if (downloads.some(isTransferCanceled)) {
48 text = c('Info').t`Download canceled`;
50 showCloseButton = true;
58 const notificationId = createNotification({
65 hideNotification(notificationId);