signal-desktop/ts/components/InstallScreen.tsx

66 lines
2.4 KiB
TypeScript
Raw Normal View History

2021-12-16 15:02:22 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { ComponentProps, ReactElement } from 'react';
import React from 'react';
import { missingCaseError } from '../util/missingCaseError';
2024-09-04 02:56:13 +00:00
import { InstallScreenStep } from '../types/InstallScreen';
2021-12-16 15:02:22 +00:00
import { InstallScreenErrorStep } from './installScreen/InstallScreenErrorStep';
import { InstallScreenChoosingDeviceNameStep } from './installScreen/InstallScreenChoosingDeviceNameStep';
import { InstallScreenLinkInProgressStep } from './installScreen/InstallScreenLinkInProgressStep';
import { InstallScreenQrCodeNotScannedStep } from './installScreen/InstallScreenQrCodeNotScannedStep';
2024-09-04 02:56:13 +00:00
import { InstallScreenBackupImportStep } from './installScreen/InstallScreenBackupImportStep';
2021-12-16 15:02:22 +00:00
// We can't always use destructuring assignment because of the complexity of this props
// type.
2022-11-18 00:45:19 +00:00
2021-12-16 15:02:22 +00:00
type PropsType =
| {
step: InstallScreenStep.QrCodeNotScanned;
screenSpecificProps: ComponentProps<
typeof InstallScreenQrCodeNotScannedStep
>;
}
| {
step: InstallScreenStep.ChoosingDeviceName;
screenSpecificProps: ComponentProps<
typeof InstallScreenChoosingDeviceNameStep
>;
}
| {
step: InstallScreenStep.LinkInProgress;
screenSpecificProps: ComponentProps<
typeof InstallScreenLinkInProgressStep
>;
2024-09-04 02:56:13 +00:00
}
| {
step: InstallScreenStep.BackupImport;
screenSpecificProps: ComponentProps<typeof InstallScreenBackupImportStep>;
}
| {
step: InstallScreenStep.Error;
screenSpecificProps: ComponentProps<typeof InstallScreenErrorStep>;
2021-12-16 15:02:22 +00:00
};
export function InstallScreen(props: Readonly<PropsType>): ReactElement {
switch (props.step) {
case InstallScreenStep.Error:
return <InstallScreenErrorStep {...props.screenSpecificProps} />;
case InstallScreenStep.QrCodeNotScanned:
return (
<InstallScreenQrCodeNotScannedStep {...props.screenSpecificProps} />
);
case InstallScreenStep.ChoosingDeviceName:
return (
<InstallScreenChoosingDeviceNameStep {...props.screenSpecificProps} />
);
case InstallScreenStep.LinkInProgress:
return <InstallScreenLinkInProgressStep {...props.screenSpecificProps} />;
2024-09-04 02:56:13 +00:00
case InstallScreenStep.BackupImport:
return <InstallScreenBackupImportStep {...props.screenSpecificProps} />;
2021-12-16 15:02:22 +00:00
default:
throw missingCaseError(props);
}
}