|
|
@ -2,10 +2,6 @@ |
|
|
|
|
|
|
|
// eslint-disable import/prefer-default-export
|
|
|
|
|
|
|
|
import type { Dispatch } from 'redux' |
|
|
|
|
|
|
|
import { getDevices, getCurrentDevice } from 'reducers/devices' |
|
|
|
|
|
|
|
import type { Device, Devices } from 'types/common' |
|
|
|
|
|
|
|
export type deviceChooseType = (Device | null) => { type: string, payload: Device | null } |
|
|
@ -14,47 +10,20 @@ export const deviceChoose: deviceChooseType = payload => ({ |
|
|
|
payload, |
|
|
|
}) |
|
|
|
|
|
|
|
type deviceChooseFirstType = () => (Dispatch<any>, () => { devices: Devices }) => void |
|
|
|
export const deviceChooseFirst: deviceChooseFirstType = () => (dispatch, getState) => { |
|
|
|
const devices = getDevices(getState()) |
|
|
|
|
|
|
|
// If we detect only 1 device, we choose it
|
|
|
|
if (devices.length === 1) { |
|
|
|
dispatch(deviceChoose(devices[0])) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
type devicesAddType = Device => (Dispatch<any>) => void |
|
|
|
export const deviceAdd: devicesAddType = payload => dispatch => { |
|
|
|
dispatch({ |
|
|
|
type devicesAddType = Device => { type: string, payload: Device } |
|
|
|
export const deviceAdd: devicesAddType = payload => ({ |
|
|
|
type: 'DEVICE_ADD', |
|
|
|
payload, |
|
|
|
}) |
|
|
|
|
|
|
|
dispatch(deviceChooseFirst()) |
|
|
|
} |
|
|
|
|
|
|
|
type devicesRemoveType = Device => (Dispatch<any>, () => { devices: Devices }) => void |
|
|
|
export const deviceRemove: devicesRemoveType = payload => (dispatch, getState) => { |
|
|
|
dispatch({ |
|
|
|
type devicesRemoveType = Device => { type: string, payload: Device } |
|
|
|
export const deviceRemove: devicesRemoveType = payload => ({ |
|
|
|
type: 'DEVICE_REMOVE', |
|
|
|
payload, |
|
|
|
}) |
|
|
|
|
|
|
|
const currentDevice = getCurrentDevice(getState()) |
|
|
|
|
|
|
|
// If we disconnect the currentDevice we reset it
|
|
|
|
if (currentDevice.path === payload.path) { |
|
|
|
dispatch(deviceChoose(null)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
type devicesUpdateType = Devices => (Dispatch<any>) => void |
|
|
|
export const devicesUpdate: devicesUpdateType = payload => dispatch => { |
|
|
|
dispatch({ |
|
|
|
type devicesUpdateType = Devices => { type: string, payload: Devices } |
|
|
|
export const devicesUpdate: devicesUpdateType = payload => ({ |
|
|
|
type: 'DEVICES_UPDATE', |
|
|
|
payload, |
|
|
|
}) |
|
|
|
|
|
|
|
dispatch(deviceChooseFirst()) |
|
|
|
} |
|
|
|