-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load and display version number in development (#34)
- Loading branch information
Showing
6 changed files
with
98 additions
and
12 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"version": "Mock API 1.23-RC4", | ||
"version": "1.23-RC4", | ||
"development": true | ||
} |
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,4 @@ | ||
// api call GET /version | ||
export const LOAD_VERSION_START = "header/LOAD_VERSION_START"; | ||
export const LOAD_VERSION_SUCCESS = "header/LOAD_VERSION_SUCCESS"; | ||
export const LOAD_VERSION_ERROR = "header/LOAD_VERSION_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { type Dispatch } from 'redux-thunk'; | ||
|
||
import api from '../api'; | ||
import { | ||
defaultError, | ||
defaultSuccess | ||
} from "../common/actions"; | ||
import { | ||
LOAD_VERSION_START, | ||
LOAD_VERSION_SUCCESS, | ||
LOAD_VERSION_ERROR | ||
} from './actionTypes'; | ||
|
||
export const loadVersionStart = () => ({ type: LOAD_VERSION_START }); | ||
export const loadVersionError = (err: any) => defaultError(LOAD_VERSION_ERROR, err); | ||
export const loadVersionSuccess = (res: any) => defaultSuccess(LOAD_VERSION_SUCCESS, res); | ||
|
||
export const loadVersion = () => { | ||
return (dispatch: Dispatch) => { | ||
dispatch(loadVersionStart()); | ||
|
||
return api.getVersion() | ||
.then( | ||
r => { | ||
dispatch(loadVersionSuccess(r)); | ||
}, | ||
e => dispatch(loadVersionError(e))) | ||
} | ||
}; |
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,31 @@ | ||
import { | ||
LOAD_VERSION_START, | ||
LOAD_VERSION_SUCCESS, | ||
LOAD_VERSION_ERROR | ||
} from './actionTypes' | ||
|
||
export type StateType = { | ||
loading: boolean, | ||
development: boolean, | ||
version: string | ||
}; | ||
|
||
const initialState: StateType = {}; | ||
|
||
export const version = (state: StateType = initialState, action: Object): StateType => { | ||
switch (action.type) { | ||
case LOAD_VERSION_START: | ||
return { ...state, loading: true }; | ||
case LOAD_VERSION_SUCCESS: | ||
return { | ||
...state, | ||
loading: false, | ||
development: action.payload.data.development, | ||
version: action.payload.data.version | ||
}; | ||
case LOAD_VERSION_ERROR: | ||
return { ...state, loading: false, error: action.payload.message }; | ||
default: | ||
return state; | ||
} | ||
}; |