mirror of
https://github.com/pawelmalak/flame.git
synced 2025-08-07 03:35:18 +02:00
Created config global state. Reworked WeatherSettings and WeatherWidget to use new config state.
This commit is contained in:
parent
a5504e6e80
commit
d257fbf9a3
15 changed files with 214 additions and 88 deletions
36
client/src/store/reducers/config.ts
Normal file
36
client/src/store/reducers/config.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
import { ActionTypes, Action } from '../actions';
|
||||
import { Config } from '../../interfaces';
|
||||
|
||||
export interface State {
|
||||
loading: boolean;
|
||||
config: Config[];
|
||||
}
|
||||
|
||||
const initialState: State = {
|
||||
loading: true,
|
||||
config: []
|
||||
}
|
||||
|
||||
const getConfig = (state: State, action: Action): State => {
|
||||
return {
|
||||
loading: false,
|
||||
config: action.payload
|
||||
}
|
||||
}
|
||||
|
||||
const updateConfig = (state: State, action: Action): State => {
|
||||
return {
|
||||
...state,
|
||||
config: action.payload
|
||||
}
|
||||
}
|
||||
|
||||
const configReducer = (state: State = initialState, action: Action) => {
|
||||
switch(action.type) {
|
||||
case ActionTypes.getConfig: return getConfig(state, action);
|
||||
case ActionTypes.updateConfig: return updateConfig(state, action);
|
||||
default: return state;
|
||||
}
|
||||
}
|
||||
|
||||
export default configReducer;
|
|
@ -6,12 +6,14 @@ import themeReducer from './theme';
|
|||
import appReducer from './app';
|
||||
import bookmarkReducer from './bookmark';
|
||||
import notificationReducer from './notification';
|
||||
import configReducer from './config';
|
||||
|
||||
const rootReducer = combineReducers<GlobalState>({
|
||||
theme: themeReducer,
|
||||
app: appReducer,
|
||||
bookmark: bookmarkReducer,
|
||||
notification: notificationReducer
|
||||
notification: notificationReducer,
|
||||
config: configReducer
|
||||
})
|
||||
|
||||
export default rootReducer;
|
Loading…
Add table
Add a link
Reference in a new issue