This repository was archived by the owner on Jul 3, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +65
-10
lines changed
Expand file tree Collapse file tree 5 files changed +65
-10
lines changed Original file line number Diff line number Diff line change 1- import { APP_LOAD } from '../constants/action-types' ;
1+ import { ACTION_TYPES } from '../constants/action-types' ;
2+ import ApiClient from '../shared/api-client' ;
23
34export function loadApp ( ) {
45 return {
5- type : APP_LOAD ,
6+ type : ACTION_TYPES . APP_LOAD ,
67 } ;
78}
89
9- export default { loadApp } ;
10+ function ApiSuccess ( status ) {
11+ return {
12+ type : ACTION_TYPES . STATUS_SUCCESS ,
13+ status
14+ }
15+ }
16+
17+ function ApiFailure ( err ) {
18+ return {
19+ type : ACTION_TYPES . STATUS_FAILURE ,
20+ err
21+ }
22+ }
23+
24+ const STATUS_URI = "/" ;
25+
26+ export function checkApiStatus ( ) {
27+ return function ( dispatch ) {
28+ return ApiClient . get ( STATUS_URI )
29+ . then ( ( response ) => {
30+ dispatch ( ApiSuccess ( response . body . status ) ) ;
31+ } ,
32+ ( error ) => {
33+ dispatch ( ApiFailure ( error ) ) ;
34+ } ) ;
35+ }
36+ }
Original file line number Diff line number Diff line change 1- export const APP_LOAD = 'APP_LOAD' ;
2-
3- export default { APP_LOAD } ;
1+ export const ACTION_TYPES = {
2+ APP_LOAD : 'APP_LOAD' ,
3+ STATUS_REQUEST : 'STATUS_REQUEST' ,
4+ STATUS_SUCCESS : 'STATUS_SUCCESS' ,
5+ STATUS_FAILURE : 'STATUS_FAILURE'
6+ } ;
Original file line number Diff line number Diff line change @@ -16,4 +16,16 @@ header {
1616
1717p {
1818 line-height : 1.5 ;
19+ }
20+
21+ .StatusPill {
22+ border-radius : 8px ;
23+ padding : 0.25rem 0.5rem ;
24+ width : 80px ;
25+ text-align : center;
26+ margin-left : 15px ;
27+ color : white;
28+ font-weight : bold;
29+ background : green;
30+ margin : auto 5px ;
1931}
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import { connect } from 'react-redux' ;
3- import { loadApp } from '../actions/app' ;
3+ import { loadApp , checkApiStatus } from '../actions/app' ;
44
55import styles from './app.css' ;
66
@@ -15,6 +15,7 @@ class App extends React.Component {
1515
1616 componentDidMount ( ) {
1717 this . props . dispatch ( loadApp ( ) ) ;
18+ this . props . dispatch ( checkApiStatus ( ) ) ;
1819 }
1920
2021 render ( ) {
@@ -34,6 +35,12 @@ class App extends React.Component {
3435 < p >
3536 With redux, thunk actions, redux action logging
3637 </ p >
38+
39+ < p > API Status:
40+ < span className = "StatusPill" >
41+ { this . props . apiStatus }
42+ </ span >
43+ </ p >
3744 </ header >
3845
3946 < main >
@@ -46,6 +53,7 @@ class App extends React.Component {
4653
4754export default connect ( ( store , props ) => {
4855 return {
49- loaded : store . app . loaded
56+ loaded : store . app . loaded ,
57+ apiStatus : store . app . apiStatus
5058 } ;
5159} ) ( App ) ;
Original file line number Diff line number Diff line change 1- import { APP_LOAD } from '../constants/action-types' ;
1+ import { ACTION_TYPES } from '../constants/action-types' ;
22
33const initialState = {
44 loaded : false ,
5+ apiStatus : undefined
56} ;
67
78export default function app ( state = initialState , action ) {
89 switch ( action . type ) {
9- case APP_LOAD :
10+ case ACTION_TYPES . APP_LOAD :
1011 return { ...state , loaded : true } ;
12+ case ACTION_TYPES . STATUS_SUCCESS :
13+ return { ...state , apiStatus : action . status }
14+ case ACTION_TYPES . STATUS_SUCCESS :
15+ return { ...state , apiStatus : "BAD" }
1116 default :
1217 return state ;
1318 }
You can’t perform that action at this time.
0 commit comments