diff --git a/src/commands/installOsuFirmware.js b/src/commands/installOsuFirmware.js index 7b397a55..416badf0 100644 --- a/src/commands/installOsuFirmware.js +++ b/src/commands/installOsuFirmware.js @@ -11,12 +11,7 @@ type Input = { firmware: Object, } -type Result = { - targetId: number | string, - version: string, - final: boolean, - mcu: boolean, -} +type Result = * const cmd: Command = createCommand( 'installOsuFirmware', diff --git a/src/components/ManagerPage/EnsureDashboard.js b/src/components/ManagerPage/EnsureDashboard.js index 6bc84ce9..51e6ff86 100644 --- a/src/components/ManagerPage/EnsureDashboard.js +++ b/src/components/ManagerPage/EnsureDashboard.js @@ -3,8 +3,7 @@ import React, { PureComponent, Fragment } from 'react' import { translate } from 'react-i18next' import isEqual from 'lodash/isEqual' -// import type { Device, T } from 'types/common' -import type { Device } from 'types/common' +import type { Device, T } from 'types/common' import getDeviceInfo from 'commands/getDeviceInfo' @@ -16,7 +15,7 @@ type DeviceInfo = { } type Props = { - // t: T, + t: T, device: Device, children: Function, } @@ -75,7 +74,7 @@ class EnsureDashboard extends PureComponent { render() { const { deviceInfo, error } = this.state - const { children } = this.props + const { children, t } = this.props if (deviceInfo) { return children(deviceInfo) @@ -84,7 +83,7 @@ class EnsureDashboard extends PureComponent { return error ? ( {error.message} - Please make sure your device is on the dashboard screen + {t('manager:erros:noDashboard')} ) : null } diff --git a/src/components/ManagerPage/EnsureDevice.js b/src/components/ManagerPage/EnsureDevice.js index ffffde02..02007e83 100644 --- a/src/components/ManagerPage/EnsureDevice.js +++ b/src/components/ManagerPage/EnsureDevice.js @@ -4,8 +4,7 @@ import { connect } from 'react-redux' import { translate } from 'react-i18next' import { compose } from 'redux' -// import type { Device, T } from 'types/common' -import type { Device } from 'types/common' +import type { Device, T } from 'types/common' import { getCurrentDevice, getDevices } from 'reducers/devices' @@ -15,7 +14,7 @@ const mapStateToProps = state => ({ }) type Props = { - // t: T, + t: T, device: ?Device, nbDevices: number, children: Function, @@ -29,8 +28,8 @@ class EnsureDevice extends PureComponent { } render() { - const { device, nbDevices, children } = this.props - return device ? children(device, nbDevices) : Please connect your device + const { device, nbDevices, children, t } = this.props + return device ? children(device, nbDevices) : {t('manager:errors.noDevice')} } } diff --git a/src/components/ManagerPage/EnsureGenuine.js b/src/components/ManagerPage/EnsureGenuine.js index c4665a0d..a08c6876 100644 --- a/src/components/ManagerPage/EnsureGenuine.js +++ b/src/components/ManagerPage/EnsureGenuine.js @@ -4,13 +4,12 @@ import { translate } from 'react-i18next' import isEqual from 'lodash/isEqual' import type { Node } from 'react' -// import type { Device, T } from 'types/common' -import type { Device } from 'types/common' +import type { Device, T } from 'types/common' import getIsGenuine from 'commands/getIsGenuine' type Props = { - // t: T, + t: T, device: Device, children: Node, } @@ -69,7 +68,7 @@ class EnsureGenuine extends PureComponent { render() { const { error, genuine } = this.state - const { children } = this.props + const { children, t } = this.props if (genuine) { return children @@ -78,7 +77,7 @@ class EnsureGenuine extends PureComponent { return error ? ( {error.message} - You did not approve request on your device or your device is not genuine + {t('manager:errors.noGenuine')} ) : null } diff --git a/src/components/ManagerPage/FirmwareUpdate.js b/src/components/ManagerPage/FirmwareUpdate.js index 0391e283..df2c619a 100644 --- a/src/components/ManagerPage/FirmwareUpdate.js +++ b/src/components/ManagerPage/FirmwareUpdate.js @@ -7,11 +7,12 @@ import isEmpty from 'lodash/isEmpty' import type { Device, T } from 'types/common' import getLatestFirmwareForDevice from 'commands/getLatestFirmwareForDevice' +import installOsuFirmware from 'commands/installOsuFirmware' import Box, { Card } from 'components/base/Box' import Button from 'components/base/Button' -// let CACHED_LATEST_FIRMWARE = null +let CACHED_LATEST_FIRMWARE = null type FirmwareInfos = { name: string, @@ -19,7 +20,7 @@ type FirmwareInfos = { } type DeviceInfos = { - targetId: number, + targetId: number | string, version: string, } @@ -43,7 +44,7 @@ class FirmwareUpdate extends PureComponent { } componentDidUpdate() { - if (/* !CACHED_LATEST_FIRMWARE || */ isEmpty(this.state.latestFirmware)) { + if (!CACHED_LATEST_FIRMWARE || isEmpty(this.state.latestFirmware)) { this.fetchLatestFirmware() } } @@ -57,23 +58,29 @@ class FirmwareUpdate extends PureComponent { fetchLatestFirmware = async () => { const { infos } = this.props const latestFirmware = - // CACHED_LATEST_FIRMWARE || - await getLatestFirmwareForDevice + CACHED_LATEST_FIRMWARE || + (await getLatestFirmwareForDevice .send({ targetId: infos.targetId, version: infos.version }) - .toPromise() + .toPromise()) if ( !isEmpty(latestFirmware) && !isEqual(this.state.latestFirmware, latestFirmware) && !this._unmounting ) { - // CACHED_LATEST_FIRMWARE = latestFirmware + CACHED_LATEST_FIRMWARE = latestFirmware this.setState({ latestFirmware }) } } - installFirmware = async () => { + installFirmware = (firmware: FirmwareInfos) => async () => { try { - // TODO + const { + device: { path: devicePath }, + } = this.props + const { success } = await installOsuFirmware.send({ devicePath, firmware }).toPromise() + if (success) { + this.fetchLatestFirmware() + } } catch (err) { console.log(err) } @@ -94,9 +101,9 @@ class FirmwareUpdate extends PureComponent { - {`Latest firmware: ${latestFirmware.name}`} - ( - {device => ( + {(device: Device) => ( - {deviceInfo => ( + {(deviceInfo: DeviceInfo) => ( - {deviceInfo.mcu && bootloader mode} - {deviceInfo.final && osu mode} - + {deviceInfo.mcu && bootloader mode } + {deviceInfo.final && osu mode } {!deviceInfo.mcu && !deviceInfo.final && ( - {/* */} + /> )} @@ -48,4 +54,5 @@ const ManagerPage = ({ t }: Props): Node => ( ) + export default translate()(ManagerPage) diff --git a/src/helpers/firmware/installOsuFirmware.js b/src/helpers/firmware/installOsuFirmware.js index 458cf2ab..fec012c5 100644 --- a/src/helpers/firmware/installOsuFirmware.js +++ b/src/helpers/firmware/installOsuFirmware.js @@ -9,7 +9,7 @@ type Input = { firmware: Object, } -type Result = * +type Result = Promise<{ success: boolean, error?: any }> const buildOsuParams = buildParamsFromFirmware('osu') diff --git a/static/i18n/en/manager.yml b/static/i18n/en/manager.yml index a01c4a6f..f882d5fb 100644 --- a/static/i18n/en/manager.yml +++ b/static/i18n/en/manager.yml @@ -3,7 +3,13 @@ tabs: device: My device install: Install allApps: All apps +firmwareUpdate: Firmware update +latestFirmware: Latest firmware plugYourDevice: title: Plug your device desc: Lorem Ipsum is simply dummy text of the printing and typesetting industry’s standard dummy text 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 \ No newline at end of file