mirror of
https://github.com/pawelmalak/flame.git
synced 2025-08-06 11:25:16 +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;
|
Loading…
Add table
Add a link
Reference in a new issue