|
|
@ -56,6 +56,7 @@ class Themes extends React.PureComponent {
|
|
|
|
dropdown = React.createRef()
|
|
|
|
dropdown = React.createRef()
|
|
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
componentDidMount() {
|
|
|
|
|
|
|
|
const { update, theme, highlights } = this.props
|
|
|
|
const storedThemes = getThemes(localStorage) || []
|
|
|
|
const storedThemes = getThemes(localStorage) || []
|
|
|
|
|
|
|
|
|
|
|
|
this.setState(({ themes }) => {
|
|
|
|
this.setState(({ themes }) => {
|
|
|
@ -63,10 +64,10 @@ class Themes extends React.PureComponent {
|
|
|
|
|
|
|
|
|
|
|
|
const name = getCustomName(newThemes)
|
|
|
|
const name = getCustomName(newThemes)
|
|
|
|
|
|
|
|
|
|
|
|
this.selectedTheme = newThemes.find(({ id }) => id === this.props.theme) || DEFAULT_THEME
|
|
|
|
this.selectedTheme = newThemes.find(({ id }) => id === theme) || DEFAULT_THEME
|
|
|
|
|
|
|
|
|
|
|
|
if (Object.keys(this.props.highlights).length === 0) {
|
|
|
|
if (Object.keys(highlights).length === 0) {
|
|
|
|
this.props.updateHighlights(this.selectedTheme.highlights)
|
|
|
|
update({ highlights: this.selectedTheme.highlights })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
@ -77,18 +78,18 @@ class Themes extends React.PureComponent {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
const { isVisible, theme, updateHighlights } = this.props
|
|
|
|
const { isVisible, theme, update } = this.props
|
|
|
|
const { themes } = this.state
|
|
|
|
const { themes } = this.state
|
|
|
|
|
|
|
|
|
|
|
|
if (prevProps.isVisible && !isVisible) {
|
|
|
|
if (prevProps.isVisible && !isVisible) {
|
|
|
|
this.setState({ name: getCustomName(themes) })
|
|
|
|
this.setState({ name: getCustomName(themes) })
|
|
|
|
updateHighlights(themes.find(({ id }) => id === theme).highlights)
|
|
|
|
update({ highlights: themes.find(({ id }) => id === theme).highlights })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
applyPreset = preset => {
|
|
|
|
applyPreset = preset => {
|
|
|
|
this.setState(({ themes }) => {
|
|
|
|
this.setState(({ themes }) => {
|
|
|
|
this.props.updateHighlights(themes.find(({ id }) => id === preset).highlights)
|
|
|
|
this.props.update({ highlights: themes.find(({ id }) => id === preset).highlights })
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
preset
|
|
|
|
preset
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -96,15 +97,14 @@ class Themes extends React.PureComponent {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
handleChange = ({ id }) => {
|
|
|
|
handleChange = ({ id }) => {
|
|
|
|
const { toggleVisibility, updateTheme, updateHighlights } = this.props
|
|
|
|
const { toggleVisibility, update } = this.props
|
|
|
|
const { themes } = this.state
|
|
|
|
const { themes } = this.state
|
|
|
|
|
|
|
|
|
|
|
|
if (id === 'create') {
|
|
|
|
if (id === 'create') {
|
|
|
|
toggleVisibility()
|
|
|
|
toggleVisibility()
|
|
|
|
this.dropdown.current.closeMenu()
|
|
|
|
this.dropdown.current.closeMenu()
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
updateTheme(id)
|
|
|
|
update({ theme: id, highlights: themes.find(theme => theme.id === id).highlights })
|
|
|
|
updateHighlights(themes.find(theme => theme.id === id).highlights)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -116,14 +116,16 @@ class Themes extends React.PureComponent {
|
|
|
|
}))
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
|
updateHighlight = ({ rgb }) =>
|
|
|
|
updateHighlight = ({ rgb }) =>
|
|
|
|
this.props.updateHighlights({
|
|
|
|
this.props.update({
|
|
|
|
...this.props.highlights,
|
|
|
|
highlights: {
|
|
|
|
[this.state.selected]: stringifyRGBA(rgb)
|
|
|
|
...this.props.highlights,
|
|
|
|
|
|
|
|
[this.state.selected]: stringifyRGBA(rgb)
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
removeTheme = id => event => {
|
|
|
|
removeTheme = id => event => {
|
|
|
|
const { themes } = this.state
|
|
|
|
const { themes } = this.state
|
|
|
|
const { theme, updateHighlights, updateTheme } = this.props
|
|
|
|
const { theme, update } = this.props
|
|
|
|
|
|
|
|
|
|
|
|
event.stopPropagation()
|
|
|
|
event.stopPropagation()
|
|
|
|
|
|
|
|
|
|
|
@ -132,15 +134,14 @@ class Themes extends React.PureComponent {
|
|
|
|
saveThemes(localStorage, newThemes.filter(({ custom }) => custom))
|
|
|
|
saveThemes(localStorage, newThemes.filter(({ custom }) => custom))
|
|
|
|
|
|
|
|
|
|
|
|
if (theme === id) {
|
|
|
|
if (theme === id) {
|
|
|
|
updateTheme(DEFAULT_THEME.id)
|
|
|
|
update({ theme: DEFAULT_THEME.id, highlights: DEFAULT_THEME.highlights })
|
|
|
|
updateHighlights(DEFAULT_THEME.highlights)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
this.setState({ themes: newThemes })
|
|
|
|
this.setState({ themes: newThemes })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
createTheme = () => {
|
|
|
|
createTheme = () => {
|
|
|
|
const { highlights, updateTheme } = this.props
|
|
|
|
const { highlights, update } = this.props
|
|
|
|
const { themes, name } = this.state
|
|
|
|
const { themes, name } = this.state
|
|
|
|
|
|
|
|
|
|
|
|
const id = `theme:${generateId()}`
|
|
|
|
const id = `theme:${generateId()}`
|
|
|
@ -156,7 +157,7 @@ class Themes extends React.PureComponent {
|
|
|
|
|
|
|
|
|
|
|
|
saveThemes(localStorage, customThemes)
|
|
|
|
saveThemes(localStorage, customThemes)
|
|
|
|
|
|
|
|
|
|
|
|
updateTheme(id)
|
|
|
|
update({ theme: id })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
itemWrapper = props => <ThemeItem {...props} onClick={this.removeTheme} />
|
|
|
|
itemWrapper = props => <ThemeItem {...props} onClick={this.removeTheme} />
|
|
|
|