You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.4 KiB
TypeScript

// Copyright (C) 2020 Intel Corporation
//
// SPDX-License-Identifier: MIT
import { BoundariesActions, BoundariesActionTypes } from 'actions/boundaries-actions';
import { FormatsActionTypes, FormatsActions } from 'actions/formats-actions';
import { AuthActionTypes, AuthActions } from 'actions/auth-actions';
import { FormatsState } from './interfaces';
const defaultState: FormatsState = {
annotationFormats: null,
initialized: false,
fetching: false,
};
export default (
state: FormatsState = defaultState,
action: FormatsActions | AuthActions | BoundariesActions,
): FormatsState => {
switch (action.type) {
case FormatsActionTypes.GET_FORMATS: {
return {
...state,
fetching: true,
initialized: false,
};
}
case FormatsActionTypes.GET_FORMATS_SUCCESS:
return {
...state,
initialized: true,
fetching: false,
annotationFormats: action.payload.annotationFormats,
};
case FormatsActionTypes.GET_FORMATS_FAILED:
return {
...state,
initialized: true,
fetching: false,
};
case BoundariesActionTypes.RESET_AFTER_ERROR:
case AuthActionTypes.LOGOUT_SUCCESS: {
return { ...defaultState };
}
default:
return state;
}
};