Add about CVAT (#1024)
parent
25164fe8b6
commit
3f22922818
@ -0,0 +1,55 @@
|
|||||||
|
import { AnyAction, Dispatch, ActionCreator } from 'redux';
|
||||||
|
import { ThunkAction } from 'redux-thunk';
|
||||||
|
|
||||||
|
import getCore from 'cvat-core';
|
||||||
|
|
||||||
|
const core = getCore();
|
||||||
|
|
||||||
|
export enum AboutActionTypes {
|
||||||
|
GET_ABOUT = 'GET_ABOUT',
|
||||||
|
GET_ABOUT_SUCCESS = 'GET_ABOUT_SUCCESS',
|
||||||
|
GET_ABOUT_FAILED = 'GET_ABOUT_FAILED',
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAbout(): AnyAction {
|
||||||
|
const action = {
|
||||||
|
type: AboutActionTypes.GET_ABOUT,
|
||||||
|
payload: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAboutSuccess(about: any): AnyAction {
|
||||||
|
const action = {
|
||||||
|
type: AboutActionTypes.GET_ABOUT_SUCCESS,
|
||||||
|
payload: { about },
|
||||||
|
};
|
||||||
|
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAboutFailed(error: any): AnyAction {
|
||||||
|
const action = {
|
||||||
|
type: AboutActionTypes.GET_ABOUT_FAILED,
|
||||||
|
payload: { error },
|
||||||
|
};
|
||||||
|
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAboutAsync():
|
||||||
|
ThunkAction<Promise<void>, {}, {}, AnyAction> {
|
||||||
|
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
|
||||||
|
dispatch(getAbout());
|
||||||
|
|
||||||
|
try {
|
||||||
|
const about = await core.server.about();
|
||||||
|
dispatch(
|
||||||
|
getAboutSuccess(about),
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
dispatch(getAboutFailed(error));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
import { AnyAction } from 'redux';
|
||||||
|
import { AboutState } from './interfaces';
|
||||||
|
|
||||||
|
import { AuthActionTypes } from '../actions/auth-actions';
|
||||||
|
import { AboutActionTypes } from '../actions/about-actions';
|
||||||
|
|
||||||
|
const defaultState: AboutState = {
|
||||||
|
about: {},
|
||||||
|
fetching: false,
|
||||||
|
initialized: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function (state: AboutState = defaultState, action: AnyAction): AboutState {
|
||||||
|
switch (action.type) {
|
||||||
|
case AboutActionTypes.GET_ABOUT: {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
fetching: true,
|
||||||
|
initialized: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case AboutActionTypes.GET_ABOUT_SUCCESS:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
fetching: false,
|
||||||
|
initialized: true,
|
||||||
|
about: action.payload.about,
|
||||||
|
};
|
||||||
|
case AboutActionTypes.GET_ABOUT_FAILED:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
fetching: false,
|
||||||
|
initialized: true,
|
||||||
|
};
|
||||||
|
case AuthActionTypes.LOGOUT_SUCCESS: {
|
||||||
|
return {
|
||||||
|
...defaultState,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue