1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-29 15:49:37 +02:00
flame/client/src/store/reducers/config.ts

80 lines
1.7 KiB
TypeScript
Raw Normal View History

import { ActionTypes, Action } from '../actions';
2021-10-06 14:15:05 +02:00
import { Config, Query } from '../../interfaces';
import { configTemplate } from '../../utility';
export interface State {
loading: boolean;
config: Config;
2021-10-06 14:15:05 +02:00
customQueries: Query[];
}
const initialState: State = {
loading: true,
config: configTemplate,
2021-10-06 14:15:05 +02:00
customQueries: [],
};
const getConfig = (state: State, action: Action): State => {
return {
2021-10-06 14:15:05 +02:00
...state,
loading: false,
config: action.payload,
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 addQuery = (state: State, action: Action): State => {
return {
...state,
customQueries: [...state.customQueries, action.payload],
};
};
const deleteQuery = (state: State, action: Action): State => {
return {
...state,
customQueries: action.payload,
};
};
2021-10-11 13:55:53 +02:00
const updateQuery = (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);
case ActionTypes.addQuery:
return addQuery(state, action);
case ActionTypes.deleteQuery:
return deleteQuery(state, action);
2021-10-11 13:55:53 +02:00
case ActionTypes.updateQuery:
return updateQuery(state, action);
2021-10-06 14:15:05 +02:00
default:
return state;
}
2021-10-06 14:15:05 +02:00
};
2021-10-06 14:15:05 +02:00
export default configReducer;