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 ( ) })