1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-08-02 01:15:17 +02:00
flame/client/src/store/reducers/config.ts

51 lines
1 KiB
TypeScript
Raw Normal View History

import { ActionTypes, Action } from '../actions';
2021-10-06 14:15:05 +02:00
import { Config, Query } from '../../interfaces';
export interface State {
loading: boolean;
config: Config[];
2021-10-06 14:15:05 +02:00
customQueries: Query[];
}
const initialState: State = {
loading: true,
2021-10-06 14:15:05 +02:00
config: [],
customQueries: [],
};
const getConfig = (state: State, action: Action): State => {
return {
2021-10-06 14:15:05 +02:00
...state,
loading: false,
2021-10-06 14:15:05 +02:00
};
};
const updateConfig = (state: State, action: Action): State => {
return {
...state,
2021-10-06 14:15:05 +02:00
config: action.payload,
};
};
const fetchQueries = (state: State, action: Action): State => {
return {
...state,
customQueries: action.payload,
};
};
const configReducer = (state: State = initialState, action: Action) => {
2021-10-06 14:15:05 +02:00
switch (action.type) {
case ActionTypes.getConfig:
return getConfig(state, action);
case ActionTypes.updateConfig:
return updateConfig(state, action);
case ActionTypes.fetchQueries:
return fetchQueries(state, action);
default:
return state;
}
2021-10-06 14:15:05 +02:00
};
2021-10-06 14:15:05 +02:00
export default configReducer;