Files
Desktop/ts/components/installScreen/InstallScreenBackupImportStep.dom.stories.tsx
T

139 lines
3.7 KiB
TypeScript

// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { useState, useEffect, type JSX } from 'react';
import type { Meta, StoryFn } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import {
InstallScreenBackupStep,
InstallScreenBackupError,
} from '../../types/InstallScreen.std.ts';
import { DialogType } from '../../types/Dialogs.std.ts';
import type { PropsType } from './InstallScreenBackupImportStep.dom.tsx';
import { InstallScreenBackupImportStep } from './InstallScreenBackupImportStep.dom.tsx';
const { i18n } = window.SignalContext;
const updates = {
dialogType: DialogType.None,
didSnooze: false,
isCheckingForUpdates: false,
showEventsCount: 0,
};
export default {
title: 'Components/InstallScreen/InstallScreenBackupImportStep',
} satisfies Meta<PropsType>;
const Template: StoryFn<PropsType> = (args: PropsType) => {
return (
<InstallScreenBackupImportStep
{...args}
i18n={i18n}
updates={updates}
currentVersion="v6.0.0"
OS="macOS"
startUpdate={action('startUpdate')}
forceCheck={action('forceCheck')}
onCancel={action('onCancel')}
onRetry={action('onRetry')}
/>
);
};
export function FullFlow(): JSX.Element {
const [backupStep, setBackupStep] = useState<InstallScreenBackupStep>(
InstallScreenBackupStep.WaitForBackup
);
const [currentBytes, setCurrentBytes] = useState<number>(0);
const [totalBytes, setTotalBytes] = useState<number>(0);
const TOTAL_BYTES = 1024 * 1024;
useEffect(() => {
setTimeout(() => {
setBackupStep(InstallScreenBackupStep.Download);
setCurrentBytes(0);
setTotalBytes(TOTAL_BYTES);
for (let i = 0; i < 4; i += 1) {
setTimeout(() => {
setCurrentBytes(TOTAL_BYTES / (4 - i));
}, i * 900);
}
}, 1000);
}, [TOTAL_BYTES]);
return (
<InstallScreenBackupImportStep
i18n={i18n}
updates={updates}
currentVersion="v6.0.0"
OS="macOS"
startUpdate={action('startUpdate')}
forceCheck={action('forceCheck')}
onCancel={action('onCancel')}
onRetry={action('onRetry')}
currentBytes={currentBytes}
totalBytes={totalBytes}
backupStep={backupStep}
/>
);
}
export const Waiting = Template.bind({});
Waiting.args = {
backupStep: InstallScreenBackupStep.WaitForBackup,
};
export const Bytes = Template.bind({});
Bytes.args = {
backupStep: InstallScreenBackupStep.Download,
currentBytes: 500 * 1024,
totalBytes: 1024 * 1024,
};
export const Full = Template.bind({});
Full.args = {
backupStep: InstallScreenBackupStep.Download,
currentBytes: 1024,
totalBytes: 1024,
};
export const Error = Template.bind({});
Error.args = {
backupStep: InstallScreenBackupStep.Download,
currentBytes: 500 * 1024,
totalBytes: 1024 * 1024,
error: InstallScreenBackupError.Retriable,
};
export const FatalError = Template.bind({});
FatalError.args = {
backupStep: InstallScreenBackupStep.Process,
currentBytes: 500 * 1024,
totalBytes: 1024 * 1024,
error: InstallScreenBackupError.Fatal,
};
export const Canceled = Template.bind({});
Canceled.args = {
backupStep: InstallScreenBackupStep.Process,
currentBytes: 500 * 1024,
totalBytes: 1024 * 1024,
error: InstallScreenBackupError.Canceled,
};
export const UnsupportedVersion = Template.bind({});
UnsupportedVersion.args = {
backupStep: InstallScreenBackupStep.Process,
currentBytes: 1,
totalBytes: 1024 * 1024,
error: InstallScreenBackupError.UnsupportedVersion,
};
export const Processing = Template.bind({});
Processing.args = {
backupStep: InstallScreenBackupStep.Process,
currentBytes: 500 * 1024,
totalBytes: 1024 * 1024,
};