Skip to content
Snippets Groups Projects
search-multiple.reducer.ts 1.69 KiB
import * as actions from './search-multiple.action';
import { Dataset } from "../../metamodel/model";
import { SearchMultipleQueryParams } from "./model";

export interface State {
    currentStep: string;
    positionStepChecked: boolean;
    datasetsStepChecked: boolean;
    resultStepChecked: boolean;
    queryParams: SearchMultipleQueryParams;
    datasetList: Dataset[];
}

export const initialState: State = {
    currentStep: null,
    positionStepChecked: false,
    datasetsStepChecked: false,
    resultStepChecked: false,
    queryParams: null,
    datasetList: []
};

export function reducer(state: State = initialState, action: actions.Actions): State {
    switch (action.type) {
        case actions.CHANGE_STEP:
            const currentStep: string = action.payload;
            return {
                ...state,
                currentStep
            };

        case actions.POSITION_CHECKED:
            return {
                ...state,
                positionStepChecked: true
            };

        case actions.ADD_DATASET:
            const dataset: Dataset = action.payload;
            return {
                ...state,
                datasetList: [...state.datasetList, dataset]
            };

        default:
            return state;
    }
}

export const getCurrentStep = (state: State) => state.currentStep;
export const getPositionStepChecked = (state: State) => state.positionStepChecked;
export const getDatasetsStepChecked = (state: State) => state.datasetsStepChecked;
export const getResultStepChecked = (state: State) => state.resultStepChecked;
export const getQueryParams = (state: State) => state.queryParams;
export const getDatasetList = (state: State) => state.datasetList;