// Copyright 2024 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React, { useState, useCallback } from 'react'; import type { LocalizerType } from '../../types/Util'; import { formatFileSize } from '../../util/formatFileSize'; import { TitlebarDragArea } from '../TitlebarDragArea'; import { ProgressBar } from '../ProgressBar'; import { ConfirmationDialog } from '../ConfirmationDialog'; import { InstallScreenSignalLogo } from './InstallScreenSignalLogo'; import { roundFractionForProgressBar } from '../../util/numbers'; // We can't always use destructuring assignment because of the complexity of this props // type. export type PropsType = Readonly<{ i18n: LocalizerType; currentBytes?: number; totalBytes?: number; onCancel: () => void; }>; export function InstallScreenBackupImportStep({ i18n, currentBytes, totalBytes, onCancel, }: PropsType): JSX.Element { const [isConfirmingCancel, setIsConfirmingCancel] = useState(false); const confirmCancel = useCallback(() => { setIsConfirmingCancel(true); }, []); const abortCancel = useCallback(() => { setIsConfirmingCancel(false); }, []); const onCancelWrap = useCallback(() => { onCancel(); setIsConfirmingCancel(false); }, [onCancel]); let progress: JSX.Element; let isCancelPossible = true; if (currentBytes != null && totalBytes != null) { isCancelPossible = currentBytes !== totalBytes; const fractionComplete = roundFractionForProgressBar( currentBytes / totalBytes ); progress = ( <>
{i18n('icu:BackupImportScreen__progressbar-hint', { currentSize: formatFileSize(currentBytes), totalSize: formatFileSize(totalBytes), fractionComplete, })}
); } else { progress = ( <>
{i18n('icu:BackupImportScreen__progressbar-hint--preparing')}
); } return (

{i18n('icu:BackupImportScreen__title')}

{progress}
{i18n('icu:BackupImportScreen__description')}
{isCancelPossible && ( )} {isConfirmingCancel && ( {i18n('icu:BackupImportScreen__cancel-confirmation__body')} )}
); }