diff --git a/lib/gui/app/modules/progress-status.ts b/lib/gui/app/modules/progress-status.ts index 2250165d..5120c692 100644 --- a/lib/gui/app/modules/progress-status.ts +++ b/lib/gui/app/modules/progress-status.ts @@ -48,7 +48,7 @@ export function fromFlashState({ type, percentage, position, -}: FlashState): string { +}: Pick): string { if (type === undefined) { return 'Starting...'; } else if (type === 'decompressing') { diff --git a/lib/gui/app/pages/main/Flash.tsx b/lib/gui/app/pages/main/Flash.tsx index 398c453b..1c58431c 100644 --- a/lib/gui/app/pages/main/Flash.tsx +++ b/lib/gui/app/pages/main/Flash.tsx @@ -77,6 +77,7 @@ const getErrorMessageFromCode = (errorCode: string) => { }; async function flashImageToDrive( + isFlashing: boolean, goToSuccess: () => void, sourceOptions: SourceOptions, ): Promise { @@ -86,7 +87,7 @@ async function flashImageToDrive( return _.includes(devices, drive.device); }); - if (drives.length === 0 || flashState.isFlashing()) { + if (drives.length === 0 || isFlashing) { return ''; } @@ -132,11 +133,18 @@ async function flashImageToDrive( return ''; } -const getProgressButtonLabel = () => { - if (!flashState.isFlashing()) { +const getProgressButtonLabel = ( + isFlashing: boolean, + // TODO: factorize + type: 'decompressing' | 'flashing' | 'verifying', + position: number, + percentage?: number, +) => { + // TODO + if (!isFlashing) { return 'Flash!'; } - return progressStatus.fromFlashState(flashState.getFlashState()); + return progressStatus.fromFlashState({ type, position, percentage }); }; const formatSeconds = (totalSeconds: number) => { @@ -159,6 +167,14 @@ interface FlashStepProps { shouldFlashStepBeDisabled: boolean; goToSuccess: () => void; source: SourceOptions; + isFlashing: boolean; + // TODO: factorize + step: 'decompressing' | 'flashing' | 'verifying'; + percentage: number; + position: number; + failed: number; + speed?: number; + eta?: number; } interface FlashStepState { @@ -167,7 +183,10 @@ interface FlashStepState { showDriveSelectorModal: boolean; } -export class FlashStep extends React.Component { +export class FlashStep extends React.PureComponent< + FlashStepProps, + FlashStepState +> { constructor(props: FlashStepProps) { super(props); this.state = { @@ -185,6 +204,7 @@ export class FlashStep extends React.Component { } this.setState({ errorMessage: await flashImageToDrive( + this.props.isFlashing, this.props.goToSuccess, this.props.source, ), @@ -210,7 +230,7 @@ export class FlashStep extends React.Component { return _.includes(devices, drive.device); }, ); - if (drives.length === 0 || flashState.isFlashing()) { + if (drives.length === 0 || this.props.isFlashing) { return; } const hasDangerStatus = constraints.hasListDriveImageCompatibilityStatus( @@ -223,6 +243,7 @@ export class FlashStep extends React.Component { } this.setState({ errorMessage: await flashImageToDrive( + this.props.isFlashing, this.props.goToSuccess, this.props.source, ), @@ -230,9 +251,6 @@ export class FlashStep extends React.Component { } public render() { - const state = flashState.getFlashState(); - const isFlashing = flashState.isFlashing(); - const flashErrorCode = flashState.getLastFlashErrorCode(); return ( <>
@@ -246,49 +264,54 @@ export class FlashStep extends React.Component {
{ this.tryFlash(); }} /> - {isFlashing && ( + {this.props.isFlashing && ( } plain onClick={imageWriter.cancel} color="#fff" + hoverIndicator={{ dark: true }} /> )} - {!_.isNil(state.speed) && - state.percentage !== COMPLETED_PERCENTAGE && ( + {!_.isNil(this.props.speed) && + this.props.percentage !== COMPLETED_PERCENTAGE && (

- {Boolean(state.speed) && ( - {`${state.speed.toFixed( + {Boolean(this.props.speed) && ( + {`${this.props.speed.toFixed( SPEED_PRECISION, )} MB/s`} )} - {!_.isNil(state.eta) && ( - {`ETA: ${formatSeconds(state.eta)}`} + {!_.isNil(this.props.eta) && ( + {`ETA: ${formatSeconds(this.props.eta)}`} )}

)} - {Boolean(state.failed) && ( + {Boolean(this.props.failed) && (
- {state.failed} + + {this.props.failed} + - {messages.progress.failed(state.failed)}{' '} + {messages.progress.failed(this.props.failed)}{' '}
diff --git a/lib/gui/app/pages/main/MainPage.tsx b/lib/gui/app/pages/main/MainPage.tsx index 0326e30c..3eaf3342 100644 --- a/lib/gui/app/pages/main/MainPage.tsx +++ b/lib/gui/app/pages/main/MainPage.tsx @@ -131,6 +131,7 @@ export class MainPage extends React.Component< } private renderMain() { + const state = flashState.getFlashState(); const shouldDriveStepBeDisabled = !this.state.hasImage; const shouldFlashStepBeDisabled = !this.state.hasImage || !this.state.hasDrive; @@ -249,6 +250,13 @@ export class MainPage extends React.Component< goToSuccess={() => this.setState({ current: 'success' })} shouldFlashStepBeDisabled={shouldFlashStepBeDisabled} source={this.state.source} + isFlashing={flashState.isFlashing()} + step={state.type} + percentage={state.percentage} + position={state.position} + failed={state.failed} + speed={state.speed} + eta={state.eta} />