Browse Source

add new translation key for manager page

master
Valentin D. Pinkman 7 years ago
parent
commit
20e7601c82
No known key found for this signature in database GPG Key ID: E7D110669FFB8D3E
  1. 7
      src/commands/installOsuFirmware.js
  2. 9
      src/components/ManagerPage/EnsureDashboard.js
  3. 9
      src/components/ManagerPage/EnsureDevice.js
  4. 9
      src/components/ManagerPage/EnsureGenuine.js
  5. 31
      src/components/ManagerPage/FirmwareUpdate.js
  6. 25
      src/components/ManagerPage/index.js
  7. 2
      src/helpers/firmware/installOsuFirmware.js
  8. 6
      static/i18n/en/manager.yml

7
src/commands/installOsuFirmware.js

@ -11,12 +11,7 @@ type Input = {
firmware: Object, firmware: Object,
} }
type Result = { type Result = *
targetId: number | string,
version: string,
final: boolean,
mcu: boolean,
}
const cmd: Command<Input, Result> = createCommand( const cmd: Command<Input, Result> = createCommand(
'installOsuFirmware', 'installOsuFirmware',

9
src/components/ManagerPage/EnsureDashboard.js

@ -3,8 +3,7 @@ import React, { PureComponent, Fragment } from 'react'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
import isEqual from 'lodash/isEqual' import isEqual from 'lodash/isEqual'
// import type { Device, T } from 'types/common' import type { Device, T } from 'types/common'
import type { Device } from 'types/common'
import getDeviceInfo from 'commands/getDeviceInfo' import getDeviceInfo from 'commands/getDeviceInfo'
@ -16,7 +15,7 @@ type DeviceInfo = {
} }
type Props = { type Props = {
// t: T, t: T,
device: Device, device: Device,
children: Function, children: Function,
} }
@ -75,7 +74,7 @@ class EnsureDashboard extends PureComponent<Props, State> {
render() { render() {
const { deviceInfo, error } = this.state const { deviceInfo, error } = this.state
const { children } = this.props const { children, t } = this.props
if (deviceInfo) { if (deviceInfo) {
return children(deviceInfo) return children(deviceInfo)
@ -84,7 +83,7 @@ class EnsureDashboard extends PureComponent<Props, State> {
return error ? ( return error ? (
<Fragment> <Fragment>
<span>{error.message}</span> <span>{error.message}</span>
<span>Please make sure your device is on the dashboard screen</span> <span>{t('manager:erros:noDashboard')}</span>
</Fragment> </Fragment>
) : null ) : null
} }

9
src/components/ManagerPage/EnsureDevice.js

@ -4,8 +4,7 @@ import { connect } from 'react-redux'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
import { compose } from 'redux' import { compose } from 'redux'
// import type { Device, T } from 'types/common' import type { Device, T } from 'types/common'
import type { Device } from 'types/common'
import { getCurrentDevice, getDevices } from 'reducers/devices' import { getCurrentDevice, getDevices } from 'reducers/devices'
@ -15,7 +14,7 @@ const mapStateToProps = state => ({
}) })
type Props = { type Props = {
// t: T, t: T,
device: ?Device, device: ?Device,
nbDevices: number, nbDevices: number,
children: Function, children: Function,
@ -29,8 +28,8 @@ class EnsureDevice extends PureComponent<Props, State> {
} }
render() { render() {
const { device, nbDevices, children } = this.props const { device, nbDevices, children, t } = this.props
return device ? children(device, nbDevices) : <span>Please connect your device</span> return device ? children(device, nbDevices) : <span>{t('manager:errors.noDevice')}</span>
} }
} }

9
src/components/ManagerPage/EnsureGenuine.js

@ -4,13 +4,12 @@ import { translate } from 'react-i18next'
import isEqual from 'lodash/isEqual' import isEqual from 'lodash/isEqual'
import type { Node } from 'react' import type { Node } from 'react'
// import type { Device, T } from 'types/common' import type { Device, T } from 'types/common'
import type { Device } from 'types/common'
import getIsGenuine from 'commands/getIsGenuine' import getIsGenuine from 'commands/getIsGenuine'
type Props = { type Props = {
// t: T, t: T,
device: Device, device: Device,
children: Node, children: Node,
} }
@ -69,7 +68,7 @@ class EnsureGenuine extends PureComponent<Props, State> {
render() { render() {
const { error, genuine } = this.state const { error, genuine } = this.state
const { children } = this.props const { children, t } = this.props
if (genuine) { if (genuine) {
return children return children
@ -78,7 +77,7 @@ class EnsureGenuine extends PureComponent<Props, State> {
return error ? ( return error ? (
<Fragment> <Fragment>
<span>{error.message}</span> <span>{error.message}</span>
<span>You did not approve request on your device or your device is not genuine</span> <span>{t('manager:errors.noGenuine')}</span>
</Fragment> </Fragment>
) : null ) : null
} }

31
src/components/ManagerPage/FirmwareUpdate.js

@ -7,11 +7,12 @@ import isEmpty from 'lodash/isEmpty'
import type { Device, T } from 'types/common' import type { Device, T } from 'types/common'
import getLatestFirmwareForDevice from 'commands/getLatestFirmwareForDevice' import getLatestFirmwareForDevice from 'commands/getLatestFirmwareForDevice'
import installOsuFirmware from 'commands/installOsuFirmware'
import Box, { Card } from 'components/base/Box' import Box, { Card } from 'components/base/Box'
import Button from 'components/base/Button' import Button from 'components/base/Button'
// let CACHED_LATEST_FIRMWARE = null let CACHED_LATEST_FIRMWARE = null
type FirmwareInfos = { type FirmwareInfos = {
name: string, name: string,
@ -19,7 +20,7 @@ type FirmwareInfos = {
} }
type DeviceInfos = { type DeviceInfos = {
targetId: number, targetId: number | string,
version: string, version: string,
} }
@ -43,7 +44,7 @@ class FirmwareUpdate extends PureComponent<Props, State> {
} }
componentDidUpdate() { componentDidUpdate() {
if (/* !CACHED_LATEST_FIRMWARE || */ isEmpty(this.state.latestFirmware)) { if (!CACHED_LATEST_FIRMWARE || isEmpty(this.state.latestFirmware)) {
this.fetchLatestFirmware() this.fetchLatestFirmware()
} }
} }
@ -57,23 +58,29 @@ class FirmwareUpdate extends PureComponent<Props, State> {
fetchLatestFirmware = async () => { fetchLatestFirmware = async () => {
const { infos } = this.props const { infos } = this.props
const latestFirmware = const latestFirmware =
// CACHED_LATEST_FIRMWARE || CACHED_LATEST_FIRMWARE ||
await getLatestFirmwareForDevice (await getLatestFirmwareForDevice
.send({ targetId: infos.targetId, version: infos.version }) .send({ targetId: infos.targetId, version: infos.version })
.toPromise() .toPromise())
if ( if (
!isEmpty(latestFirmware) && !isEmpty(latestFirmware) &&
!isEqual(this.state.latestFirmware, latestFirmware) && !isEqual(this.state.latestFirmware, latestFirmware) &&
!this._unmounting !this._unmounting
) { ) {
// CACHED_LATEST_FIRMWARE = latestFirmware CACHED_LATEST_FIRMWARE = latestFirmware
this.setState({ latestFirmware }) this.setState({ latestFirmware })
} }
} }
installFirmware = async () => { installFirmware = (firmware: FirmwareInfos) => async () => {
try { try {
// TODO const {
device: { path: devicePath },
} = this.props
const { success } = await installOsuFirmware.send({ devicePath, firmware }).toPromise()
if (success) {
this.fetchLatestFirmware()
}
} catch (err) { } catch (err) {
console.log(err) console.log(err)
} }
@ -94,9 +101,9 @@ class FirmwareUpdate extends PureComponent<Props, State> {
</Box> </Box>
<Card flow={2} {...props}> <Card flow={2} {...props}>
<Box horizontal align="center" flow={2}> <Box horizontal align="center" flow={2}>
<Box ff="Museo Sans">{`Latest firmware: ${latestFirmware.name}`}</Box> <Box ff="Museo Sans">{`${t('manager:latestFirmware')}: ${latestFirmware.name}`}</Box>
<Button outline onClick={this.installFirmware}> <Button outline onClick={this.installFirmware(latestFirmware)}>
{'Install'} {t('manager:install')}
</Button> </Button>
</Box> </Box>
<Box <Box

25
src/components/ManagerPage/index.js

@ -4,15 +4,22 @@ import React, { Fragment } from 'react'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
import type { Node } from 'react' import type { Node } from 'react'
import type { T } from 'types/common' import type { T, Device } from 'types/common'
import AppsList from './AppsList' import AppsList from './AppsList'
// import DeviceInfos from './DeviceInfos' // import DeviceInfos from './DeviceInfos'
// import FirmwareUpdate from './FirmwareUpdate' import FirmwareUpdate from './FirmwareUpdate'
import EnsureDevice from './EnsureDevice' import EnsureDevice from './EnsureDevice'
import EnsureDashboard from './EnsureDashboard' import EnsureDashboard from './EnsureDashboard'
import EnsureGenuine from './EnsureGenuine' import EnsureGenuine from './EnsureGenuine'
type DeviceInfo = {
targetId: number | string,
version: string,
final: boolean,
mcu: boolean,
}
type Props = { type Props = {
t: T, t: T,
} }
@ -20,24 +27,23 @@ type Props = {
const ManagerPage = ({ t }: Props): Node => ( const ManagerPage = ({ t }: Props): Node => (
<Fragment> <Fragment>
<EnsureDevice> <EnsureDevice>
{device => ( {(device: Device) => (
<EnsureDashboard device={device}> <EnsureDashboard device={device}>
{deviceInfo => ( {(deviceInfo: DeviceInfo) => (
<Fragment> <Fragment>
{deviceInfo.mcu && <span>bootloader mode</span>} {deviceInfo.mcu && <span> bootloader mode </span>}
{deviceInfo.final && <span>osu mode</span>} {deviceInfo.final && <span> osu mode </span>}
{!deviceInfo.mcu && {!deviceInfo.mcu &&
!deviceInfo.final && ( !deviceInfo.final && (
<EnsureGenuine device={device} t={t}> <EnsureGenuine device={device} t={t}>
{/* <FirmwareUpdate <FirmwareUpdate
infos={{ infos={{
targetId: deviceInfo.targetId, targetId: deviceInfo.targetId,
version: deviceInfo.version, version: deviceInfo.version,
}} }}
device={device} device={device}
t={t} t={t}
/> */} />
<AppsList device={device} targetId={deviceInfo.targetId} /> <AppsList device={device} targetId={deviceInfo.targetId} />
</EnsureGenuine> </EnsureGenuine>
)} )}
@ -48,4 +54,5 @@ const ManagerPage = ({ t }: Props): Node => (
</EnsureDevice> </EnsureDevice>
</Fragment> </Fragment>
) )
export default translate()(ManagerPage) export default translate()(ManagerPage)

2
src/helpers/firmware/installOsuFirmware.js

@ -9,7 +9,7 @@ type Input = {
firmware: Object, firmware: Object,
} }
type Result = * type Result = Promise<{ success: boolean, error?: any }>
const buildOsuParams = buildParamsFromFirmware('osu') const buildOsuParams = buildParamsFromFirmware('osu')

6
static/i18n/en/manager.yml

@ -3,7 +3,13 @@ tabs:
device: My device device: My device
install: Install install: Install
allApps: All apps allApps: All apps
firmwareUpdate: Firmware update
latestFirmware: Latest firmware
plugYourDevice: plugYourDevice:
title: Plug your device title: Plug your device
desc: Lorem Ipsum is simply dummy text of the printing and typesetting industry’s standard dummy text desc: Lorem Ipsum is simply dummy text of the printing and typesetting industry’s standard dummy text
cta: Plug my device cta: Plug my device
errors:
noDevice: Please make sur your device is connected
noDashboard: Please make sure your device is on the dashboard screen
noGenuine: You did not approve request on your device or your device is not genuine
Loading…
Cancel
Save