summaryrefslogtreecommitdiff
path: root/web/src/reducers/preferences.js
diff options
context:
space:
mode:
authorTobias Urdin <tobias.urdin@binero.se>2023-03-15 23:36:45 +0000
committerTobias Urdin <tobias.urdin@binero.se>2023-04-21 11:23:56 +0000
commit59cd5de78baa31150958e6d0d6733407c0e95805 (patch)
treeed72bd938cc5d40a04de612e30547a78ea9c53cf /web/src/reducers/preferences.js
parentde9dfa2bc416d9b1bb6159ed39a014fbba267db5 (diff)
downloadzuul-59cd5de78baa31150958e6d0d6733407c0e95805.tar.gz
web: add dark mode and theme selection
This adds a theme selection in the preferences in the config modal and adds a new dark theme. Removes the line.png image and instead uses CSS linear-gradient that is available in all browsers since around 2018, also fixes the 15 pixels spacing issue that is there today. You can select between three different themes. Auto will use your system preference to choose either the light or dark theme, changes dynamically based on your system preference. Light is the current theme. Dark is the theme added by this patch series. The UX this changes is that if somebody has their system preferences set to dark, for example in Mac OS X that is in System Settings -> Appearance -> Dark the user will get the Zuul web UI in dark by default and same for the opposite. This uses a poor man's dark mode for swagger-ui as per the comment in [1]. [1] https://github.com/swagger-api/swagger-ui/issues/5327#issuecomment-742375520 Change-Id: I01cf32f3decdb885307a76eb79d644667bbbf9a3
Diffstat (limited to 'web/src/reducers/preferences.js')
-rw-r--r--web/src/reducers/preferences.js23
1 files changed, 13 insertions, 10 deletions
diff --git a/web/src/reducers/preferences.js b/web/src/reducers/preferences.js
index 1fba8eacf..0a2755257 100644
--- a/web/src/reducers/preferences.js
+++ b/web/src/reducers/preferences.js
@@ -15,13 +15,14 @@
import {
PREFERENCE_SET,
} from '../actions/preferences'
-
+import { resolveDarkMode, setDarkMode } from '../Misc'
const stored_prefs = localStorage.getItem('preferences')
let default_prefs
if (stored_prefs === null) {
default_prefs = {
- autoReload: true
+ autoReload: true,
+ theme: 'Auto'
}
} else {
default_prefs = JSON.parse(stored_prefs)
@@ -30,13 +31,15 @@ if (stored_prefs === null) {
export default (state = {
...default_prefs
}, action) => {
- let newstate
- switch (action.type) {
- case PREFERENCE_SET:
- newstate = { ...state, [action.key]: action.value }
- localStorage.setItem('preferences', JSON.stringify(newstate))
- return newstate
- default:
- return state
+ if (action.type === PREFERENCE_SET) {
+ let newstate = { ...state, [action.key]: action.value }
+ delete newstate.darkMode
+ localStorage.setItem('preferences', JSON.stringify(newstate))
+ let darkMode = resolveDarkMode(newstate.theme)
+ setDarkMode(darkMode)
+ return { ...newstate, darkMode: darkMode }
}
+ let darkMode = resolveDarkMode(state.theme)
+ setDarkMode(darkMode)
+ return { ...state, darkMode: darkMode }
}