Browse Source

Handle device null / disconnected on manager device tab

master
meriadec 7 years ago
parent
commit
480a181840
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 4
      src/components/ManagerPage/DeviceInfos.js
  2. 20
      src/components/ManagerPage/index.js

4
src/components/ManagerPage/DeviceInfos.js

@ -49,6 +49,10 @@ class DeviceInfos extends PureComponent<Props, State> {
const { device } = this.props const { device } = this.props
const { memoryInfos, isLoading } = this.state const { memoryInfos, isLoading } = this.state
if (!device) {
return <Box py={5}>{'You dont have any device connected'}</Box>
}
const title = ( const title = (
<Text> <Text>
{device.manufacturer} {device.manufacturer}

20
src/components/ManagerPage/index.js

@ -9,7 +9,6 @@ import type { Device, T } from 'types/common'
import { getCurrentDevice, getDevices } from 'reducers/devices' import { getCurrentDevice, getDevices } from 'reducers/devices'
import Box from 'components/base/Box'
import Pills from 'components/base/Pills' import Pills from 'components/base/Pills'
import AppsList from './AppsList' import AppsList from './AppsList'
@ -37,6 +36,14 @@ class ManagerPage extends PureComponent<Props, State> {
currentTab: 'apps', currentTab: 'apps',
} }
componentWillReceiveProps(nextProps) {
const { device } = this.props
const { currentTab } = this.state
if (device && !nextProps.device && currentTab === 'device') {
this.setState({ currentTab: 'apps' })
}
}
handleTabChange = t => this.setState({ currentTab: t.value }) handleTabChange = t => this.setState({ currentTab: t.value })
render() { render() {
@ -45,19 +52,18 @@ class ManagerPage extends PureComponent<Props, State> {
const tabs = TABS.map(i => { const tabs = TABS.map(i => {
let label = t(`manager:tabs.${i.key}`) let label = t(`manager:tabs.${i.key}`)
if (i.key === 'device') { if (i.key === 'device') {
if (!device) {
return null
}
label += ` (${nbDevices})` label += ` (${nbDevices})`
} }
return { ...i, label } return { ...i, label }
}) }).filter(Boolean)
return ( return (
<Fragment> <Fragment>
<Pills items={tabs} activeKey={currentTab} onChange={this.handleTabChange} mb={6} /> <Pills items={tabs} activeKey={currentTab} onChange={this.handleTabChange} mb={6} />
{currentTab === 'apps' && <AppsList device={device} />} {currentTab === 'apps' && <AppsList device={device} />}
{currentTab === 'device' && ( {currentTab === 'device' && <DeviceInfos device={device} />}
<Box flow={4}>
<DeviceInfos device={device} />
</Box>
)}
</Fragment> </Fragment>
) )
} }

Loading…
Cancel
Save