Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion browser/main/StatusBar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class StatusBar extends React.Component {
{status.updateReady
? <button onClick={this.updateApp} styleName='update'>
<i styleName='update-icon' className='fa fa-cloud-download' /> Ready to Update!
</button>
</button>
: null
}
</div>
Expand Down
4 changes: 2 additions & 2 deletions browser/main/modals/PreferencesModal/ConfigTab.styl
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
color #1EC38B
.error
color red


.warning
color #FFA500

.group-control-leftButton
colorDefaultButton()
Expand Down
17 changes: 16 additions & 1 deletion browser/main/modals/PreferencesModal/HotkeyTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get hotkey from this.state.config

}
ipc.addListener('APP_SETTING_DONE', this.handleSettingDone)
ipc.addListener('APP_SETTING_ERROR', this.handleSettingError)
}
Expand All @@ -53,6 +57,7 @@ class HotkeyTab extends React.Component {
config: newConfig
})
this.clearMessage()
this.props.haveToSave(null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to pass null

}

handleHintToggleButtonClick (e) {
Expand All @@ -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 () {
Expand Down Expand Up @@ -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)
8 changes: 8 additions & 0 deletions browser/main/modals/PreferencesModal/PreferencesModal.styl
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,21 @@ 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
color $ui-text-color
background-color $ui-button--active-backgroundColor
&:hover
color $ui-text-color
.saving--warning
color #FFA500
font-size 10px
margin-top 3px
Copy link
Contributor

@sota1235 sota1235 Dec 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this style as mixin
It seems that styles are same


.nav-button-icon
display block
Expand Down
24 changes: 20 additions & 4 deletions browser/main/modals/PreferencesModal/UiTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this line (this.state.haveToSave is not used)

}
}

Expand Down Expand Up @@ -91,8 +92,21 @@ 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'))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please get config from this.props.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!'
})
}
}
})
}

handleSaveUIClick (e) {
Expand All @@ -109,6 +123,7 @@ class UiTab extends React.Component {
config: newConfig
})
this.clearMessage()
this.props.haveToSave(null)
}

clearMessage () {
Expand Down Expand Up @@ -346,7 +361,8 @@ UiTab.propTypes = {
user: PropTypes.shape({
name: PropTypes.string
}),
dispatch: PropTypes.func
dispatch: PropTypes.func,
haveToSave: PropTypes.func
}

export default CSSModules(UiTab, styles)
12 changes: 9 additions & 3 deletions browser/main/modals/PreferencesModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class Preferences extends React.Component {
super(props)

this.state = {
currentTab: 'STORAGES'
currentTab: 'STORAGES',
UI: null,
Hotkey: null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hotkey is a little bit ambiguous.
For example, how about HotkeyMessage?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I think setting default value '' is better than null

}
}

Expand Down Expand Up @@ -58,13 +60,15 @@ class Preferences extends React.Component {
<HotkeyTab
dispatch={dispatch}
config={config}
haveToSave={msg => this.setState({Hotkey: msg})}
/>
)
case 'UI':
return (
<UiTab
dispatch={dispatch}
config={config}
haveToSave={msg => this.setState({UI: msg})}
/>
)
case 'CROWDFUNDING':
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isOk is a little bit simple word. Plz specify more detail for variable name like isOkToSave or anything

return (
<button styleName={isActive
? 'nav-button--active'
Expand All @@ -118,6 +123,7 @@ class Preferences extends React.Component {
<span styleName='nav-button-label'>
{tab.label}
</span>
{isOk && tab.label === tab[tab.label].tab ? <p styleName={`saving--${tab[tab.label].type}`}>{tab[tab.label].message}</p> : null}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is little difficult to read.
Could you add class method to get Component?

</button>
)
})
Expand Down