Browse Source

Add <PreventDeviceChangeRecheck />

master
Gaëtan Renaudeau 7 years ago
parent
commit
1e156c6235
  1. 4
      src/components/ManagerPage/FirmwareUpdate.js
  2. 1
      src/components/ManagerPage/index.js
  3. 23
      src/components/Workflow/EnsureDevice.js

4
src/components/ManagerPage/FirmwareUpdate.js

@ -24,6 +24,7 @@ import Button from 'components/base/Button'
import NanoS from 'icons/device/NanoS'
import CheckFull from 'icons/CheckFull'
import { PreventDeviceChangeRecheck } from '../Workflow/EnsureDevice'
import UpdateFirmwareButton from './UpdateFirmwareButton'
let CACHED_LATEST_FIRMWARE = null
@ -150,7 +151,7 @@ class FirmwareUpdate extends PureComponent<Props, State> {
render() {
const { infos, t } = this.props
const { latestFirmware } = this.state
const { latestFirmware, modal } = this.state
return (
<Card p={4}>
@ -178,6 +179,7 @@ class FirmwareUpdate extends PureComponent<Props, State> {
installFirmware={this.handleInstallModal}
/>
</Box>
{modal !== 'closed' ? <PreventDeviceChangeRecheck /> : null}
{this.renderModal()}
</Card>
)

1
src/components/ManagerPage/index.js

@ -3,7 +3,6 @@
import React, { PureComponent } from 'react'
import type { Node } from 'react'
import type { Device } from 'types/common'
import Workflow from 'components/Workflow'

23
src/components/Workflow/EnsureDevice.js

@ -1,5 +1,7 @@
// @flow
import { PureComponent } from 'react'
/* eslint-disable react/no-multi-comp */
import { Component, PureComponent } from 'react'
import { connect } from 'react-redux'
import type { Node } from 'react'
@ -12,9 +14,24 @@ type Props = {
children: (device: Device) => Node,
}
type State = {}
let prevents = 0
export class PreventDeviceChangeRecheck extends PureComponent<{}> {
componentDidMount() {
prevents++
}
componentWillUnmount() {
prevents--
}
render() {
return null
}
}
class EnsureDevice extends PureComponent<Props, State> {
class EnsureDevice extends Component<Props> {
shouldComponentUpdate(nextProps) {
if (prevents > 0) return false
return nextProps.device !== this.props.device
}
render() {
const { device, children } = this.props
return children(device)

Loading…
Cancel
Save