// 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; isPaused: boolean; handleCancel: VoidFunction; handleClose: VoidFunction; handleResume: VoidFunction; handlePause: VoidFunction; }>; export function BackupMediaDownloadProgress({ i18n, downloadedBytes, totalBytes, 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 ); let content: JSX.Element | undefined; let icon: JSX.Element | undefined; let actionButton: JSX.Element | undefined; if (fractionComplete === 1) { icon =
; content = ( <>
{i18n('icu:BackupMediaDownloadProgress__title-complete')}
{formatFileSize(downloadedBytes)}
); actionButton = ( ); } else { content = ( <>
{i18n('icu:BackupMediaDownloadProgress__title-in-progress')}
{i18n('icu:BackupMediaDownloadProgress__progressbar-hint', { currentSize: formatFileSize(downloadedBytes), totalSize: formatFileSize(totalBytes), })}
); } actionButton = ( {({ onClick }) => { return (