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_CODE,
DEFAULT_SETTINGS, DEFAULT_SETTINGS,
DEFAULT_LANGUAGE, DEFAULT_LANGUAGE,
DEFAULT_PRESET_ID,
DEFAULT_THEME, DEFAULT_THEME,
FONTS FONTS
} from '../lib/constants' } from '../lib/constants'
@ -46,7 +45,6 @@ class Editor extends React.Component {
super(props) super(props)
this.state = { this.state = {
...DEFAULT_SETTINGS, ...DEFAULT_SETTINGS,
preset: DEFAULT_PRESET_ID,
loading: true loading: true
} }
@ -221,7 +219,7 @@ class Editor extends React.Component {
updateSetting(key, value) { updateSetting(key, value) {
this.updateState({ [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 }) this.updateState({ preset: null })
} }
} }
@ -246,7 +244,7 @@ class Editor extends React.Component {
} }
resetDefaultSettings() { resetDefaultSettings() {
this.updateState({ ...DEFAULT_SETTINGS, preset: DEFAULT_PRESET_ID }) this.updateState(DEFAULT_SETTINGS)
this.props.onReset() this.props.onReset()
} }

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

Loading…
Cancel
Save