From b4a7b547f0f9fd1476bae2729a60c1bc44300be6 Mon Sep 17 00:00:00 2001 From: Paul Rosset Date: Fri, 1 Dec 2017 15:23:23 +0000 Subject: [PATCH 1/7] Add notification when not saved --- .../modals/PreferencesModal/ConfigTab.styl | 4 +-- .../main/modals/PreferencesModal/HotkeyTab.js | 17 +++++++++++- .../PreferencesModal/PreferencesModal.styl | 8 ++++++ browser/main/modals/PreferencesModal/UiTab.js | 26 ++++++++++++++++--- browser/main/modals/PreferencesModal/index.js | 14 +++++++--- 5 files changed, 59 insertions(+), 10 deletions(-) diff --git a/browser/main/modals/PreferencesModal/ConfigTab.styl b/browser/main/modals/PreferencesModal/ConfigTab.styl index f9115c62..a488c4b3 100644 --- a/browser/main/modals/PreferencesModal/ConfigTab.styl +++ b/browser/main/modals/PreferencesModal/ConfigTab.styl @@ -76,8 +76,8 @@ color #1EC38B .error color red - - + .warning + color #FFA500 .group-control-leftButton colorDefaultButton() diff --git a/browser/main/modals/PreferencesModal/HotkeyTab.js b/browser/main/modals/PreferencesModal/HotkeyTab.js index 9a15e79f..cfd45d96 100644 --- a/browser/main/modals/PreferencesModal/HotkeyTab.js +++ b/browser/main/modals/PreferencesModal/HotkeyTab.js @@ -32,6 +32,10 @@ class HotkeyTab extends React.Component { message: err.message != null ? err.message : 'Error occurs!' }}) } + if (JSON.parse(localStorage.getItem('config'))) { + const {hotkey} = JSON.parse(localStorage.getItem('config')) + this.hotkey = hotkey + } ipc.addListener('APP_SETTING_DONE', this.handleSettingDone) ipc.addListener('APP_SETTING_ERROR', this.handleSettingError) } @@ -53,6 +57,7 @@ class HotkeyTab extends React.Component { config: newConfig }) this.clearMessage() + this.props.haveToSave(null) } handleHintToggleButtonClick (e) { @@ -70,6 +75,15 @@ class HotkeyTab extends React.Component { this.setState({ config }) + if (JSON.stringify(this.hotkey) === JSON.stringify(config.hotkey)) { + this.props.haveToSave(null) + } else { + this.props.haveToSave({ + tab: "Hotkey", + type: 'warning', + message: 'You have to save!' + }) + } } clearMessage () { @@ -161,7 +175,8 @@ class HotkeyTab extends React.Component { } HotkeyTab.propTypes = { - dispatch: PropTypes.func + dispatch: PropTypes.func, + haveToSave: PropTypes.func } export default CSSModules(HotkeyTab, styles) diff --git a/browser/main/modals/PreferencesModal/PreferencesModal.styl b/browser/main/modals/PreferencesModal/PreferencesModal.styl index b0d89312..6c1ad2d9 100644 --- a/browser/main/modals/PreferencesModal/PreferencesModal.styl +++ b/browser/main/modals/PreferencesModal/PreferencesModal.styl @@ -42,6 +42,10 @@ top-bar--height = 50px background-color transparent color $ui-text-color font-size 16px + .saving--warning + color #FFA500 + font-size 10px + margin-top 3px .nav-button--active @extend .nav-button @@ -49,6 +53,10 @@ top-bar--height = 50px background-color $ui-button--active-backgroundColor &:hover color $ui-text-color + .saving--warning + color #FFA500 + font-size 10px + margin-top 3px .nav-button-icon display block diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js index eebb2e0c..79314608 100644 --- a/browser/main/modals/PreferencesModal/UiTab.js +++ b/browser/main/modals/PreferencesModal/UiTab.js @@ -20,7 +20,8 @@ class UiTab extends React.Component { super(props) this.state = { config: props.config, - codemirrorTheme: props.config.editor.theme + codemirrorTheme: props.config.editor.theme, + haveToSave: null } } @@ -37,12 +38,16 @@ class UiTab extends React.Component { message: err.message != null ? err.message : 'Error occurs!' }}) } + if (JSON.parse(localStorage.getItem('config'))) { + const {ui, editor, preview} = JSON.parse(localStorage.getItem('config')) + this.currentConfig = {ui, editor, preview} + } ipc.addListener('APP_SETTING_DONE', this.handleSettingDone) ipc.addListener('APP_SETTING_ERROR', this.handleSettingError) } componentWillMount () { - CodeMirror.autoLoadMode(ReactCodeMirror, 'javascript') + CodeMirror.autoLoadMode(ReactCodeMirror, 'javascript') } componentWillUnmount () { @@ -92,7 +97,18 @@ class UiTab extends React.Component { checkHighLight.setAttribute('href', `../node_modules/codemirror/theme/${newCodemirrorTheme.split(' ')[0]}.css`) } - this.setState({ config: newConfig, codemirrorTheme: newCodemirrorTheme }) + this.setState({ config: newConfig, codemirrorTheme: newCodemirrorTheme }, + () => { + if (JSON.stringify(this.currentConfig) === JSON.stringify(this.state.config)) { + this.props.haveToSave(null) + } else { + this.props.haveToSave({ + tab: "UI", + type: 'warning', + message: 'You have to save!' + }) + } + }) } handleSaveUIClick (e) { @@ -109,6 +125,7 @@ class UiTab extends React.Component { config: newConfig }) this.clearMessage() + this.props.haveToSave(null) } clearMessage () { @@ -346,7 +363,8 @@ UiTab.propTypes = { user: PropTypes.shape({ name: PropTypes.string }), - dispatch: PropTypes.func + dispatch: PropTypes.func, + haveToSave: PropTypes.func } export default CSSModules(UiTab, styles) diff --git a/browser/main/modals/PreferencesModal/index.js b/browser/main/modals/PreferencesModal/index.js index 2fff0364..f478f913 100644 --- a/browser/main/modals/PreferencesModal/index.js +++ b/browser/main/modals/PreferencesModal/index.js @@ -17,7 +17,9 @@ class Preferences extends React.Component { super(props) this.state = { - currentTab: 'STORAGES' + currentTab: 'STORAGES', + UI: null, + Hotkey: null } } @@ -58,6 +60,7 @@ class Preferences extends React.Component { this.setState({Hotkey: msg})} /> ) case 'UI': @@ -65,6 +68,7 @@ class Preferences extends React.Component { this.setState({UI: msg})} /> ) case 'CROWDFUNDING': @@ -99,14 +103,15 @@ class Preferences extends React.Component { const tabs = [ {target: 'STORAGES', label: 'Storages'}, - {target: 'HOTKEY', label: 'Hotkey'}, - {target: 'UI', label: 'UI'}, + {target: 'HOTKEY', label: 'Hotkey', Hotkey: this.state.Hotkey}, + {target: 'UI', label: 'UI', UI: this.state.UI}, {target: 'INFO', label: 'Community / Info'}, {target: 'CROWDFUNDING', label: 'Crowdfunding'} ] const navButtons = tabs.map((tab) => { const isActive = this.state.currentTab === tab.target + const isOk = typeof tab[tab.label] !== "undefined" && tab[tab.label] !== null return ( ) }) From d1e5781c24276618c13588352964d0b440060460 Mon Sep 17 00:00:00 2001 From: Paul Rosset Date: Fri, 1 Dec 2017 19:03:04 +0000 Subject: [PATCH 2/7] Correction UiTab --- browser/main/StatusBar/index.js | 2 +- .../main/modals/PreferencesModal/HotkeyTab.js | 6 +++--- browser/main/modals/PreferencesModal/UiTab.js | 16 +++++++--------- browser/main/modals/PreferencesModal/index.js | 6 ++---- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/browser/main/StatusBar/index.js b/browser/main/StatusBar/index.js index 2106a230..49c1b40c 100644 --- a/browser/main/StatusBar/index.js +++ b/browser/main/StatusBar/index.js @@ -63,7 +63,7 @@ class StatusBar extends React.Component { {status.updateReady ? + : null } diff --git a/browser/main/modals/PreferencesModal/HotkeyTab.js b/browser/main/modals/PreferencesModal/HotkeyTab.js index cfd45d96..586faf04 100644 --- a/browser/main/modals/PreferencesModal/HotkeyTab.js +++ b/browser/main/modals/PreferencesModal/HotkeyTab.js @@ -79,9 +79,9 @@ class HotkeyTab extends React.Component { this.props.haveToSave(null) } else { this.props.haveToSave({ - tab: "Hotkey", - type: 'warning', - message: 'You have to save!' + tab: 'Hotkey', + type: 'warning', + message: 'You have to save!' }) } } diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js index 79314608..dcb9f6bc 100644 --- a/browser/main/modals/PreferencesModal/UiTab.js +++ b/browser/main/modals/PreferencesModal/UiTab.js @@ -38,16 +38,12 @@ class UiTab extends React.Component { message: err.message != null ? err.message : 'Error occurs!' }}) } - if (JSON.parse(localStorage.getItem('config'))) { - const {ui, editor, preview} = JSON.parse(localStorage.getItem('config')) - this.currentConfig = {ui, editor, preview} - } ipc.addListener('APP_SETTING_DONE', this.handleSettingDone) ipc.addListener('APP_SETTING_ERROR', this.handleSettingError) } componentWillMount () { - CodeMirror.autoLoadMode(ReactCodeMirror, 'javascript') + CodeMirror.autoLoadMode(ReactCodeMirror, 'javascript') } componentWillUnmount () { @@ -96,18 +92,20 @@ class UiTab extends React.Component { if (newCodemirrorTheme !== codemirrorTheme) { checkHighLight.setAttribute('href', `../node_modules/codemirror/theme/${newCodemirrorTheme.split(' ')[0]}.css`) } - - this.setState({ config: newConfig, codemirrorTheme: newCodemirrorTheme }, - () => { + this.setState({ config: newConfig, codemirrorTheme: newCodemirrorTheme }, () => { + if (JSON.parse(localStorage.getItem('config'))) { + const {ui, editor, preview} = JSON.parse(localStorage.getItem('config')) + this.currentConfig = {ui, editor, preview} if (JSON.stringify(this.currentConfig) === JSON.stringify(this.state.config)) { this.props.haveToSave(null) } else { this.props.haveToSave({ - tab: "UI", + tab: 'UI', type: 'warning', message: 'You have to save!' }) } + } }) } diff --git a/browser/main/modals/PreferencesModal/index.js b/browser/main/modals/PreferencesModal/index.js index f478f913..adf1e0d4 100644 --- a/browser/main/modals/PreferencesModal/index.js +++ b/browser/main/modals/PreferencesModal/index.js @@ -111,7 +111,7 @@ class Preferences extends React.Component { const navButtons = tabs.map((tab) => { const isActive = this.state.currentTab === tab.target - const isOk = typeof tab[tab.label] !== "undefined" && tab[tab.label] !== null + const isOk = typeof tab[tab.label] !== 'undefined' && tab[tab.label] !== null return ( ) }) From f4fd131100bac3561e044a9e4fe1904f29354e7d Mon Sep 17 00:00:00 2001 From: Paul Rosset Date: Tue, 5 Dec 2017 18:16:42 +0000 Subject: [PATCH 3/7] Requested Review --- .../main/modals/PreferencesModal/HotkeyTab.js | 11 +++----- .../PreferencesModal/PreferencesModal.styl | 8 ++---- browser/main/modals/PreferencesModal/Tab.styl | 5 ++++ browser/main/modals/PreferencesModal/UiTab.js | 27 +++++++++---------- browser/main/modals/PreferencesModal/index.js | 22 +++++++++------ 5 files changed, 37 insertions(+), 36 deletions(-) diff --git a/browser/main/modals/PreferencesModal/HotkeyTab.js b/browser/main/modals/PreferencesModal/HotkeyTab.js index 586faf04..93d2993c 100644 --- a/browser/main/modals/PreferencesModal/HotkeyTab.js +++ b/browser/main/modals/PreferencesModal/HotkeyTab.js @@ -32,10 +32,7 @@ class HotkeyTab extends React.Component { message: err.message != null ? err.message : 'Error occurs!' }}) } - if (JSON.parse(localStorage.getItem('config'))) { - const {hotkey} = JSON.parse(localStorage.getItem('config')) - this.hotkey = hotkey - } + this.oldHotkey = this.state.config.hotkey ipc.addListener('APP_SETTING_DONE', this.handleSettingDone) ipc.addListener('APP_SETTING_ERROR', this.handleSettingError) } @@ -57,7 +54,7 @@ class HotkeyTab extends React.Component { config: newConfig }) this.clearMessage() - this.props.haveToSave(null) + this.props.haveToSave() } handleHintToggleButtonClick (e) { @@ -75,8 +72,8 @@ class HotkeyTab extends React.Component { this.setState({ config }) - if (JSON.stringify(this.hotkey) === JSON.stringify(config.hotkey)) { - this.props.haveToSave(null) + if (JSON.stringify(this.oldHotkey) === JSON.stringify(config.hotkey)) { + this.props.haveToSave() } else { this.props.haveToSave({ tab: 'Hotkey', diff --git a/browser/main/modals/PreferencesModal/PreferencesModal.styl b/browser/main/modals/PreferencesModal/PreferencesModal.styl index 6c1ad2d9..697fb50d 100644 --- a/browser/main/modals/PreferencesModal/PreferencesModal.styl +++ b/browser/main/modals/PreferencesModal/PreferencesModal.styl @@ -43,9 +43,7 @@ top-bar--height = 50px color $ui-text-color font-size 16px .saving--warning - color #FFA500 - font-size 10px - margin-top 3px + haveToSave() .nav-button--active @extend .nav-button @@ -54,9 +52,7 @@ top-bar--height = 50px &:hover color $ui-text-color .saving--warning - color #FFA500 - font-size 10px - margin-top 3px + haveToSave() .nav-button-icon display block diff --git a/browser/main/modals/PreferencesModal/Tab.styl b/browser/main/modals/PreferencesModal/Tab.styl index e5fc48da..a316f3eb 100644 --- a/browser/main/modals/PreferencesModal/Tab.styl +++ b/browser/main/modals/PreferencesModal/Tab.styl @@ -20,3 +20,8 @@ $tab--dark-text-color = #E5E5E5 body[data-theme="dark"] .header color $tab--dark-text-color + +haveToSave() + color #FFA500 + font-size 10px + margin-top 3px \ No newline at end of file diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js index dcb9f6bc..73ec68da 100644 --- a/browser/main/modals/PreferencesModal/UiTab.js +++ b/browser/main/modals/PreferencesModal/UiTab.js @@ -20,8 +20,7 @@ class UiTab extends React.Component { super(props) this.state = { config: props.config, - codemirrorTheme: props.config.editor.theme, - haveToSave: null + codemirrorTheme: props.config.editor.theme } } @@ -93,18 +92,16 @@ class UiTab extends React.Component { checkHighLight.setAttribute('href', `../node_modules/codemirror/theme/${newCodemirrorTheme.split(' ')[0]}.css`) } this.setState({ config: newConfig, codemirrorTheme: newCodemirrorTheme }, () => { - if (JSON.parse(localStorage.getItem('config'))) { - const {ui, editor, preview} = JSON.parse(localStorage.getItem('config')) - this.currentConfig = {ui, editor, preview} - if (JSON.stringify(this.currentConfig) === JSON.stringify(this.state.config)) { - this.props.haveToSave(null) - } else { - this.props.haveToSave({ - tab: 'UI', - type: 'warning', - message: 'You have to save!' - }) - } + const {ui, editor, preview} = this.props.config + this.currentConfig = {ui, editor, preview} + if (JSON.stringify(this.currentConfig) === JSON.stringify(this.state.config)) { + this.props.haveToSave() + } else { + this.props.haveToSave({ + tab: 'UI', + type: 'warning', + message: 'You have to save!' + }) } }) } @@ -123,7 +120,7 @@ class UiTab extends React.Component { config: newConfig }) this.clearMessage() - this.props.haveToSave(null) + this.props.haveToSave() } clearMessage () { diff --git a/browser/main/modals/PreferencesModal/index.js b/browser/main/modals/PreferencesModal/index.js index adf1e0d4..bf330e78 100644 --- a/browser/main/modals/PreferencesModal/index.js +++ b/browser/main/modals/PreferencesModal/index.js @@ -18,8 +18,8 @@ class Preferences extends React.Component { this.state = { currentTab: 'STORAGES', - UI: null, - Hotkey: null + UIAlert: '', + HotkeyAlert: '' } } @@ -60,7 +60,7 @@ class Preferences extends React.Component { this.setState({Hotkey: msg})} + haveToSave={msg => this.setState({HotkeyAlert: msg})} /> ) case 'UI': @@ -68,7 +68,7 @@ class Preferences extends React.Component { this.setState({UI: msg})} + haveToSave={msg => this.setState({UIAlert: msg})} /> ) case 'CROWDFUNDING': @@ -97,21 +97,27 @@ class Preferences extends React.Component { const node = ReactDOM.findDOMNode(this.refs.content) return node.getBoundingClientRect() } + + haveToSaveNotif (tab) { + return ( +

{tab[tab.label].message}

+ ) + } render () { const content = this.renderContent() const tabs = [ {target: 'STORAGES', label: 'Storages'}, - {target: 'HOTKEY', label: 'Hotkey', Hotkey: this.state.Hotkey}, - {target: 'UI', label: 'UI', UI: this.state.UI}, + {target: 'HOTKEY', label: 'Hotkey', Hotkey: this.state.HotkeyAlert}, + {target: 'UI', label: 'UI', UI: this.state.UIAlert}, {target: 'INFO', label: 'Community / Info'}, {target: 'CROWDFUNDING', label: 'Crowdfunding'} ] const navButtons = tabs.map((tab) => { const isActive = this.state.currentTab === tab.target - const isOk = typeof tab[tab.label] !== 'undefined' && tab[tab.label] !== null + const isUiHotkeyTab = _.isObject(tab[tab.label]) && tab.label === tab[tab.label].tab return ( ) }) From 83910b55d2a3784967188a3bc2be342fa49d709c Mon Sep 17 00:00:00 2001 From: Paul Rosset Date: Tue, 5 Dec 2017 18:18:12 +0000 Subject: [PATCH 4/7] Correction eslint code format --- browser/main/modals/PreferencesModal/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/main/modals/PreferencesModal/index.js b/browser/main/modals/PreferencesModal/index.js index bf330e78..d7542821 100644 --- a/browser/main/modals/PreferencesModal/index.js +++ b/browser/main/modals/PreferencesModal/index.js @@ -97,7 +97,7 @@ class Preferences extends React.Component { const node = ReactDOM.findDOMNode(this.refs.content) return node.getBoundingClientRect() } - + haveToSaveNotif (tab) { return (

{tab[tab.label].message}

From 125a49340071103e5a2a8ad1270bd536189ec002 Mon Sep 17 00:00:00 2001 From: Paul Rosset Date: Tue, 5 Dec 2017 18:24:30 +0000 Subject: [PATCH 5/7] Change name for state --- browser/main/modals/PreferencesModal/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/browser/main/modals/PreferencesModal/index.js b/browser/main/modals/PreferencesModal/index.js index d7542821..882428b5 100644 --- a/browser/main/modals/PreferencesModal/index.js +++ b/browser/main/modals/PreferencesModal/index.js @@ -60,7 +60,7 @@ class Preferences extends React.Component { this.setState({HotkeyAlert: msg})} + haveToSave={alert => this.setState({HotkeyAlert: alert})} /> ) case 'UI': @@ -68,7 +68,7 @@ class Preferences extends React.Component { this.setState({UIAlert: msg})} + haveToSave={alert => this.setState({UIAlert: alert})} /> ) case 'CROWDFUNDING': From cb59458c79d7409effb235f8307c10938ce308c4 Mon Sep 17 00:00:00 2001 From: Paul Rosset Date: Tue, 5 Dec 2017 18:28:59 +0000 Subject: [PATCH 6/7] refactor --- browser/main/modals/PreferencesModal/UiTab.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js index 73ec68da..9f9ee73f 100644 --- a/browser/main/modals/PreferencesModal/UiTab.js +++ b/browser/main/modals/PreferencesModal/UiTab.js @@ -7,11 +7,10 @@ import store from 'browser/main/store' import consts from 'browser/lib/consts' import ReactCodeMirror from 'react-codemirror' import CodeMirror from 'codemirror' +import _ from 'lodash' const OSX = global.process.platform === 'darwin' -import _ from 'lodash' - const electron = require('electron') const ipc = electron.ipcRenderer From 795fe8ae1da7debfecd9e47cace59abfc189edf2 Mon Sep 17 00:00:00 2001 From: Paul Rosset Date: Thu, 14 Dec 2017 12:26:05 +0000 Subject: [PATCH 7/7] Add isEqual and changing haveToSaveNotif method --- browser/main/modals/PreferencesModal/HotkeyTab.js | 2 +- browser/main/modals/PreferencesModal/UiTab.js | 2 +- browser/main/modals/PreferencesModal/index.js | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/browser/main/modals/PreferencesModal/HotkeyTab.js b/browser/main/modals/PreferencesModal/HotkeyTab.js index 93d2993c..4b4a3060 100644 --- a/browser/main/modals/PreferencesModal/HotkeyTab.js +++ b/browser/main/modals/PreferencesModal/HotkeyTab.js @@ -72,7 +72,7 @@ class HotkeyTab extends React.Component { this.setState({ config }) - if (JSON.stringify(this.oldHotkey) === JSON.stringify(config.hotkey)) { + if (_.isEqual(this.oldHotkey, config.hotkey)) { this.props.haveToSave() } else { this.props.haveToSave({ diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js index 9f9ee73f..d5d54b75 100644 --- a/browser/main/modals/PreferencesModal/UiTab.js +++ b/browser/main/modals/PreferencesModal/UiTab.js @@ -93,7 +93,7 @@ class UiTab extends React.Component { this.setState({ config: newConfig, codemirrorTheme: newCodemirrorTheme }, () => { const {ui, editor, preview} = this.props.config this.currentConfig = {ui, editor, preview} - if (JSON.stringify(this.currentConfig) === JSON.stringify(this.state.config)) { + if (_.isEqual(this.currentConfig, this.state.config)) { this.props.haveToSave() } else { this.props.haveToSave({ diff --git a/browser/main/modals/PreferencesModal/index.js b/browser/main/modals/PreferencesModal/index.js index 882428b5..09885e1c 100644 --- a/browser/main/modals/PreferencesModal/index.js +++ b/browser/main/modals/PreferencesModal/index.js @@ -98,9 +98,9 @@ class Preferences extends React.Component { return node.getBoundingClientRect() } - haveToSaveNotif (tab) { + haveToSaveNotif (type, message) { return ( -

{tab[tab.label].message}

+

{message}

) } @@ -129,7 +129,7 @@ class Preferences extends React.Component { {tab.label} - {isUiHotkeyTab ? this.haveToSaveNotif(tab) : null} + {isUiHotkeyTab ? this.haveToSaveNotif(tab[tab.label].type, tab[tab.label].message) : null} ) })