From f74ff74545e2c597f6ff1996144229ad8e2cbe86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=ABck=20V=C3=A9zien?= Date: Thu, 18 Jan 2018 11:09:36 +0100 Subject: [PATCH] Add lock application button --- src/components/AppRegionDrag.js | 1 + src/components/IsUnlocked/index.js | 2 ++ src/components/SettingsPage.js | 8 ++++- src/components/TopBar.js | 51 +++++++++++++++++++++++++++--- src/reducers/application.js | 6 ++-- src/reducers/settings.js | 4 +++ 6 files changed, 62 insertions(+), 10 deletions(-) diff --git a/src/components/AppRegionDrag.js b/src/components/AppRegionDrag.js index 37f0a504..0bd42763 100644 --- a/src/components/AppRegionDrag.js +++ b/src/components/AppRegionDrag.js @@ -9,4 +9,5 @@ export default styled.div` position: absolute; right: 0; top: 0; + z-index: -1; ` diff --git a/src/components/IsUnlocked/index.js b/src/components/IsUnlocked/index.js index f0230d36..036c591b 100644 --- a/src/components/IsUnlocked/index.js +++ b/src/components/IsUnlocked/index.js @@ -67,6 +67,8 @@ class IsUnlocked extends PureComponent { setEncryptionKey('accounts', inputValue.password) fetchAccounts() unlock() + + this.handleChangeInput('password')('') } } diff --git a/src/components/SettingsPage.js b/src/components/SettingsPage.js index 6bfb430a..78727998 100644 --- a/src/components/SettingsPage.js +++ b/src/components/SettingsPage.js @@ -14,6 +14,7 @@ import type { MapStateToProps } from 'react-redux' import type { Settings } from 'types/common' import { saveSettings } from 'actions/settings' +import { unlock } from 'reducers/application' import Box from 'components/base/Box' import Input from 'components/base/Input' @@ -29,6 +30,7 @@ type InputValue = Settings type Props = { settings: Settings, saveSettings: Function, + unlock: Function, } type State = { inputValue: InputValue, @@ -40,6 +42,7 @@ const mapStateToProps: MapStateToProps<*, *, *> = state => ({ const mapDispatchToProps = { saveSettings, + unlock, } class SettingsPage extends PureComponent { @@ -63,7 +66,7 @@ class SettingsPage extends PureComponent { handleSubmit = (e: SyntheticEvent) => { e.preventDefault() - const { saveSettings } = this.props + const { saveSettings, unlock } = this.props const { inputValue } = this.state const settings = { @@ -80,8 +83,11 @@ class SettingsPage extends PureComponent { settings.password.value = bcrypt.hashSync(password.value, 8) setEncryptionKey('accounts', password.value) + } else { + setEncryptionKey('accounts', undefined) } + unlock() saveSettings(settings) } diff --git a/src/components/TopBar.js b/src/components/TopBar.js index 581e86aa..29e03298 100644 --- a/src/components/TopBar.js +++ b/src/components/TopBar.js @@ -8,8 +8,9 @@ import type { Device, Devices } from 'types/common' import type { SetCurrentDevice } from 'actions/devices' import { getDevices, getCurrentDevice } from 'reducers/devices' - import { setCurrentDevice } from 'actions/devices' +import { lock } from 'reducers/application' +import { hasPassword } from 'reducers/settings' import Box from 'components/base/Box' import Overlay from 'components/base/Overlay' @@ -17,18 +18,21 @@ import Overlay from 'components/base/Overlay' const mapStateToProps: MapStateToProps<*, *, *> = state => ({ devices: getDevices(state), currentDevice: getCurrentDevice(state), + hasPassword: hasPassword(state), }) const mapDispatchToProps: MapDispatchToProps<*, *, *> = { setCurrentDevice, + lock, } type Props = { + setCurrentDevice: SetCurrentDevice, + lock: Function, + hasPassword: boolean, devices: Devices, currentDevice: Device, - setCurrentDevice: SetCurrentDevice, } - type State = { changeDevice: boolean, } @@ -68,8 +72,10 @@ class TopBar extends PureComponent { }) } + handleLock = () => this.props.lock() + render() { - const { devices } = this.props + const { devices, hasPassword } = this.props const { changeDevice } = this.state return ( @@ -88,7 +94,15 @@ class TopBar extends PureComponent { ))} )} - + + {hasPassword && } @@ -112,6 +126,20 @@ const CountDevices = ({ count, onChangeDevice } = { count: Number, onChangeDevic ) +const LockApplication = ({ onLock }: { onLock: Function }) => ( + + + +) + const DeviceIcon = props => ( ( ) +const LockIcon = props => ( + + + + +) + export default connect(mapStateToProps, mapDispatchToProps)(TopBar) diff --git a/src/reducers/application.js b/src/reducers/application.js index 8ee978cf..644d94e1 100644 --- a/src/reducers/application.js +++ b/src/reducers/application.js @@ -2,7 +2,7 @@ import { handleActions, createAction } from 'redux-actions' -import get from 'lodash/get' +import { hasPassword } from 'reducers/settings' export type ApplicationState = {} @@ -23,9 +23,7 @@ export const lock = createAction('APPLICATION_SET_DATA', () => ({ isLocked: true // Selectors export const isLocked = (state: Object) => - state.application.isLocked === undefined - ? get(state.settings, 'password.state', false) - : state.application.isLocked + state.application.isLocked === undefined ? hasPassword(state) : state.application.isLocked // Exporting reducer diff --git a/src/reducers/settings.js b/src/reducers/settings.js index a0e6d858..bdc6b21d 100644 --- a/src/reducers/settings.js +++ b/src/reducers/settings.js @@ -2,6 +2,8 @@ import { handleActions } from 'redux-actions' +import get from 'lodash/get' + import type { Settings } from 'types/common' export type SettingsState = Object @@ -13,4 +15,6 @@ const handlers: Object = { FETCH_SETTINGS: (state: SettingsState, { payload: settings }: { payload: Settings }) => settings, } +export const hasPassword = (state: Object) => get(state.settings, 'password.state', false) + export default handleActions(handlers, state)