Add theme toggle

This commit is contained in:
Thomas Nordquist
2019-04-03 01:55:57 +02:00
parent 84a92ad522
commit 6f86a8d471
6 changed files with 84 additions and 29 deletions

View File

@@ -6,11 +6,12 @@ import { settingsReducer, SettingsState } from './Settings'
import { trackEvent } from '../tracking'
import { treeReducer, TreeState } from './Tree'
export enum ActionTypes {
showUpdateNotification = 'SHOW_UPDATE_NOTIFICATION',
showUpdateDetails = 'SHOW_UPDATE_DETAILS',
showError = 'SHOW_ERROR',
setDarkTheme = 'GLOBAL_SET_DARK_THEME',
setLightTheme = 'GLOBAL_SET_LIGHT_THEME',
}
export interface CustomAction extends Action {
@@ -33,13 +34,15 @@ export interface GlobalState {
showUpdateNotification?: boolean
showUpdateDetails: boolean
error?: string
theme: 'light' | 'dark'
}
const initialBigState: GlobalState = {
const initialGlobalState: GlobalState = {
showUpdateDetails: false,
theme: 'dark',
}
const globalState: Reducer<GlobalState | undefined, CustomAction> = (state = initialBigState, action) => {
const globalState: Reducer<GlobalState | undefined, CustomAction> = (state = initialGlobalState, action) => {
if (!state) {
throw Error('No initial state')
}
@@ -58,6 +61,18 @@ const globalState: Reducer<GlobalState | undefined, CustomAction> = (state = ini
error: action.error,
}
case ActionTypes.setDarkTheme:
return {
...state,
theme: 'dark',
}
case ActionTypes.setLightTheme:
return {
...state,
theme: 'light',
}
case ActionTypes.showUpdateDetails:
if (action.showUpdateDetails === undefined) {
return state