// Copyright 2025 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React from 'react'; import { PlaintextExportErrors, PlaintextExportSteps, } from '../types/Backups.std.js'; import { AxoDialog } from '../axo/AxoDialog.dom.js'; import { AxoAlertDialog } from '../axo/AxoAlertDialog.dom.js'; import type { PlaintextExportWorkflowType } from '../types/Backups.std.js'; import type { LocalizerType } from '../types/I18N.std.js'; import { AxoCheckbox } from '../axo/AxoCheckbox.dom.js'; import { formatFileSize } from '../util/formatFileSize.std.js'; import { ProgressBar } from './ProgressBar.dom.js'; import { missingCaseError } from '../util/missingCaseError.std.js'; import { tw } from '../axo/tw.dom.js'; import { I18n } from './I18n.dom.js'; export type PropsType = { cancelWorkflow: () => unknown; clearWorkflow: () => unknown; i18n: LocalizerType; openFileInFolder: (path: string) => unknown; osName: 'linux' | 'macos' | 'windows' | undefined; verifyWithOSForExport: (includeMedia: boolean) => unknown; workflow: PlaintextExportWorkflowType; }; function Bold(parts: Array) { return {parts}; } function Secondary(parts: Array) { return {parts}; } export function PlaintextExportWorkflow({ cancelWorkflow, clearWorkflow, i18n, openFileInFolder, osName, verifyWithOSForExport, workflow, }: PropsType): JSX.Element { const [includeMedia, setIncludeMedia] = React.useState(true); const { step } = workflow; if ( step === PlaintextExportSteps.ConfirmingExport || step === PlaintextExportSteps.ConfirmingWithOS || step === PlaintextExportSteps.ChoosingLocation ) { const shouldShowSpinner = step !== PlaintextExportSteps.ConfirmingExport; return (
{i18n('icu:PlaintextExport--Confirmation--Header')}
{i18n('icu:cancel')} verifyWithOSForExport(includeMedia)} > {i18n('icu:PlaintextExport--Confirmation--ContinueButton')}
); } if ( step === PlaintextExportSteps.ExportingMessages || step === PlaintextExportSteps.ExportingAttachments ) { const progress = step === PlaintextExportSteps.ExportingAttachments ? workflow.progress : undefined; let progressElements; if (progress) { const fractionComplete = progress.totalBytes > 0 ? progress.currentBytes / progress.totalBytes : 0; progressElements = ( <>
{i18n('icu:PlaintextExport--ProgressDialog--Progress', { currentBytes: formatFileSize(progress.currentBytes), totalBytes: formatFileSize(progress.totalBytes), percentage: fractionComplete, })}
); } else { progressElements = (
); } return (
{i18n('icu:PlaintextExport--ProgressDialog--Header')}
{progressElements}
{i18n('icu:PlaintextExport--ProgressDialog--TimeWarning')}
{i18n('icu:cancel')}
); } if (step === PlaintextExportSteps.Complete) { let showInFolderText = i18n( 'icu:PlaintextExport--CompleteDialog--ShowFiles--Windows' ); if (osName === 'macos') { showInFolderText = i18n( 'icu:PlaintextExport--CompleteDialog--ShowFiles--Mac' ); } else if (osName === 'linux') { showInFolderText = i18n( 'icu:PlaintextExport--CompleteDialog--ShowFiles--Linux' ); } return ( {i18n('icu:PlaintextExport--CompleteDialog--Header')} { openFileInFolder(workflow.exportPath); clearWorkflow(); }} > {showInFolderText} {i18n('icu:ok')} ); } if (step === PlaintextExportSteps.Error) { const { type } = workflow.errorDetails; let title; let detail; if (type === PlaintextExportErrors.General) { title = i18n('icu:PlaintextExport--Error--General--Title'); detail = i18n('icu:PlaintextExport--Error--General--Description'); } else if (type === PlaintextExportErrors.NotEnoughStorage) { title = i18n('icu:PlaintextExport--Error--NotEnoughStorage--Title'); detail = i18n('icu:PlaintextExport--Error--NotEnoughStorage--Detail', { bytes: formatFileSize(workflow.errorDetails.bytesNeeded), }); } else if (type === PlaintextExportErrors.RanOutOfStorage) { title = i18n('icu:PlaintextExport--Error--RanOutOfStorage--Title'); detail = i18n('icu:PlaintextExport--Error--RanOutOfStorage--Detail', { bytes: formatFileSize(workflow.errorDetails.bytesNeeded), }); } else if (type === PlaintextExportErrors.StoragePermissions) { title = i18n('icu:PlaintextExport--Error--DiskPermssions--Title'); detail = i18n('icu:PlaintextExport--Error--DiskPermssions--Detail'); } else { throw missingCaseError(type); } return ( {title} {detail} {i18n('icu:ok')} ); } throw missingCaseError(step); }