-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
206 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.