Refactor preset state (#822)

* refactor preset state

* remove unnecessary constant
main
Michael Fix 5 years ago committed by repo-ranger[bot]
parent 1cdaa6f13a
commit ddc611a6f9

@ -25,7 +25,6 @@ import {
DEFAULT_CODE,
DEFAULT_SETTINGS,
DEFAULT_LANGUAGE,
DEFAULT_PRESET_ID,
DEFAULT_THEME,
FONTS
} from '../lib/constants'
@ -46,7 +45,6 @@ class Editor extends React.Component {
super(props)
this.state = {
...DEFAULT_SETTINGS,
preset: DEFAULT_PRESET_ID,
loading: true
}
@ -221,7 +219,7 @@ class Editor extends React.Component {
updateSetting(key, value) {
this.updateState({ [key]: value })
if (Object.prototype.hasOwnProperty.call(DEFAULT_SETTINGS, key)) {
if (Object.prototype.hasOwnProperty.call(DEFAULT_SETTINGS, key) && key !== 'preset') {
this.updateState({ preset: null })
}
}
@ -246,7 +244,7 @@ class Editor extends React.Component {
}
resetDefaultSettings() {
this.updateState({ ...DEFAULT_SETTINGS, preset: DEFAULT_PRESET_ID })
this.updateState(DEFAULT_SETTINGS)
this.props.onReset()
}

@ -1017,16 +1017,15 @@ export const DEFAULT_SETTINGS = {
lineNumbers: false,
exportSize: '2x',
watermark: false,
squaredImage: false
squaredImage: false,
preset: 'preset:4'
}
export const DEFAULT_PRESET_ID = 'preset:4'
export const DEFAULT_PRESETS = [
{
...DEFAULT_SETTINGS,
icon: '/static/presets/4.png',
id: DEFAULT_PRESET_ID
id: 'preset:4'
},
{
...DEFAULT_SETTINGS,

Loading…
Cancel
Save