// Copyright 2024 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React, { useState } from 'react'; import type { LocalizerType } from '../types/Util'; import { formatFileSize } from '../util/formatFileSize'; import { roundFractionForProgressBar } from '../util/numbers'; import { ProgressCircle } from './ProgressCircle'; import { ContextMenu } from './ContextMenu'; import { BackupMediaDownloadCancelConfirmationDialog } from './BackupMediaDownloadCancelConfirmationDialog'; export type PropsType = Readonly<{ i18n: LocalizerType; downloadedBytes: number; totalBytes: number; isIdle: boolean; isPaused: boolean; handleCancel: VoidFunction; handleClose: VoidFunction; handleResume: VoidFunction; handlePause: VoidFunction; }>; export function BackupMediaDownloadProgress({ i18n, downloadedBytes, totalBytes, isIdle, isPaused, handleCancel: handleConfirmedCancel, handleClose, handleResume, handlePause, }: PropsType): JSX.Element | null { const [isShowingCancelConfirmation, setIsShowingCancelConfirmation] = useState(false); if (totalBytes <= 0) { return null; } function handleCancel() { setIsShowingCancelConfirmation(true); } const fractionComplete = roundFractionForProgressBar( downloadedBytes / totalBytes ); const closeButton = ( ); let content: JSX.Element | undefined; let icon: JSX.Element | undefined; let actionButton: JSX.Element | undefined; if (fractionComplete === 1) { icon = (
); content = ( <>