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