Skip to content

Commit

Permalink
fix(ui): fix theme switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
ncarlier committed Apr 21, 2020
1 parent f350367 commit 9bd8ffc
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions ui/src/settings/preferences/ThemeBox.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useEffect } from 'react'
import React, { useContext, useCallback, useEffect } from 'react'
import { useFormState } from 'react-use-form-state'

import Box from '../../components/Box'
Expand All @@ -17,15 +17,23 @@ const ThemeSwitch = () => {
})

useEffect(() => {
if (formState.values.theme !== localConfiguration.theme) {
const { theme } = formState.values
updateLocalConfiguration({ ...localConfiguration, theme })
const { theme } = formState.values
if (localConfiguration.theme !== theme) {
formState.setField('theme', localConfiguration.theme)
}
}, [localConfiguration, formState, updateLocalConfiguration])

const handleThemeChange = useCallback(
(event: React.ChangeEvent<HTMLSelectElement>) => {
const theme = event.target.value as Theme
updateLocalConfiguration({ ...localConfiguration, theme })
},
[updateLocalConfiguration, localConfiguration]
)

return (
<form>
<FormSelectField label="Theme" {...select('theme')}>
<FormSelectField label="Theme" {...select({ name: 'theme', onChange: handleThemeChange })}>
<option value="light">light</option>
<option value="dark">dark</option>
<option value="auto">auto (your system will decide)</option>
Expand Down

0 comments on commit 9bd8ffc

Please sign in to comment.