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