Extract settings reducer

This commit is contained in:
Thomas Nordquist
2019-01-21 09:40:04 +01:00
parent 61737fa97b
commit 4d21c63da9
10 changed files with 70 additions and 107 deletions

View File

@@ -5,22 +5,16 @@ import { Action, Reducer, combineReducers } from 'redux'
import { trackEvent } from '../tracking'
import { PublishState, publishReducer } from './Publish'
import { ConnectionState, connectionReducer } from './Connection'
import { SettingsState, settingsReducer } from './Settings'
export enum ActionTypes {
setAutoExpandLimit = 'SET_AUTO_EXPAND_LIMIT',
toggleSettingsVisibility = 'TOGGLE_SETTINGS_VISIBILITY',
setNodeOrder = 'SET_NODE_ORDER',
selectTopic = 'SELECT_TOPIC',
showUpdateNotification = 'SHOW_UPDATE_NOTIFICATION',
showUpdateDetails = 'SHOW_UPDATE_DETAILS',
}
export interface CustomAction extends Action {
type: ActionTypes,
autoExpandLimit?: number
nodeOrder?: NodeOrder
selectedTopic?: q.TreeNode
showUpdateNotification?: boolean
showUpdateDetails?: boolean
@@ -28,36 +22,18 @@ export interface CustomAction extends Action {
export interface AppState {
tooBigReducer: TooBigOfState
settings: SettingsState,
publish: PublishState
connection: ConnectionState
}
export interface TooBigOfState {
settings: SettingsState,
selectedTopic?: q.TreeNode
showUpdateNotification?: boolean
showUpdateDetails: boolean
}
export interface SettingsState {
autoExpandLimit: number
visible: boolean
nodeOrder: NodeOrder
}
export enum NodeOrder {
none = 'none',
messages = '#messages',
abc = 'abc',
topics = '#topics',
}
const initialBigState: TooBigOfState = {
settings: {
autoExpandLimit: 0,
nodeOrder: NodeOrder.none,
visible: false,
},
selectedTopic: undefined,
showUpdateDetails: false,
}
@@ -69,27 +45,6 @@ const tooBigReducer: Reducer<TooBigOfState | undefined, CustomAction> = (state =
trackEvent(action.type)
console.log(action, state)
switch (action.type) {
case ActionTypes.setAutoExpandLimit:
if (action.autoExpandLimit === undefined) {
return state
}
return {
...state,
settings: {
...state.settings,
autoExpandLimit: action.autoExpandLimit,
},
}
case ActionTypes.toggleSettingsVisibility:
return {
...state,
settings: {
...state.settings,
visible: !state.settings.visible,
},
}
case ActionTypes.selectTopic:
if (!action.selectedTopic) {
return state
@@ -99,15 +54,6 @@ const tooBigReducer: Reducer<TooBigOfState | undefined, CustomAction> = (state =
selectedTopic: action.selectedTopic,
}
case ActionTypes.setNodeOrder:
if (!action.nodeOrder) {
return state
}
return {
...state,
settings: { ...state.settings, nodeOrder: action.nodeOrder },
}
case ActionTypes.showUpdateNotification:
return {
...state,
@@ -132,6 +78,7 @@ const reducer = combineReducers({
tooBigReducer,
publish: publishReducer,
connection: connectionReducer,
settings: settingsReducer,
})
export default reducer