-
Notifications
You must be signed in to change notification settings - Fork 0
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
6 changed files
with
118 additions
and
3 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,20 @@ | ||
import Request from 'superagent' | ||
|
||
export const RECEIVE_STATS = 'RECEIVE_STATS' | ||
|
||
function receiveStats(res) { | ||
return { | ||
type: RECEIVE_STATS, | ||
res | ||
} | ||
} | ||
|
||
export function fetchStats() { | ||
return function(dispatch) { | ||
return Request | ||
.get(`/api/stats`) | ||
.end(function(err,res){ | ||
dispatch(receiveStats(res.body)) | ||
}) | ||
} | ||
} |
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,63 @@ | ||
import React, { Component } from 'react' | ||
|
||
import { | ||
Row, Col | ||
} from 'react-bootstrap' | ||
|
||
export default class Home extends Component{ | ||
componentWillMount() { | ||
this.props.fetchStats() | ||
} | ||
render() { | ||
if(this.props.stats.posts){ | ||
return( | ||
<div className="content"> | ||
<div className="box"> | ||
<div className="box-header"></div> | ||
<div className="box-body text-center"> | ||
<p>We will change the world.</p> | ||
<p><em>Innovation distinguishes between a leader and a follower.</em></p> | ||
<small> | ||
— Steve Jobs | ||
</small> | ||
</div> | ||
</div> | ||
<div className="box"> | ||
<div className="box-header"></div> | ||
<div className="box-body text-center"> | ||
<div className="row"> | ||
<div className="col-sm-3 col-xs-6"> | ||
<div className="description-block border-right"> | ||
<h5 className="description-header">{this.props.stats.posts}</h5> | ||
<span className="description-text">照片数</span> | ||
</div> | ||
</div> | ||
<div className="col-sm-3 col-xs-6"> | ||
<div className="description-block border-right"> | ||
<h5 className="description-header">{this.props.stats.users}</h5> | ||
<span className="description-text">用户数</span> | ||
</div> | ||
</div> | ||
<div className="col-sm-3 col-xs-6"> | ||
<div className="description-block border-right"> | ||
<h5 className="description-header">{this.props.stats.toys}</h5> | ||
<span className="description-text">玩具数</span> | ||
</div> | ||
</div> | ||
<div className="col-sm-3 col-xs-6"> | ||
<div className="description-block"> | ||
<h5 className="description-header">{this.props.stats.tags}</h5> | ||
<span className="description-text">标签数</span> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
|
||
}else { | ||
return(<div/>) | ||
} | ||
} | ||
} |
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,16 @@ | ||
import { connect } from 'react-redux' | ||
import Home from './Home' | ||
|
||
import { fetchStats } from '../../actions/statsAction' | ||
const mapActionCreators = { | ||
fetchStats | ||
} | ||
|
||
const mapStateToProps = (state) => { | ||
const { stats } = state.statsReducer.toJS() | ||
return { | ||
stats | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps, mapActionCreators)(Home) |
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,13 @@ | ||
import Immutable from 'immutable' | ||
import { RECEIVE_STATS } from '../actions/statsAction' | ||
|
||
export default (state = Immutable.Map({ stats: {} }),action)=>{ | ||
switch (action.type) { | ||
case RECEIVE_STATS: | ||
return state.mergeDeep({ | ||
stats: action.res | ||
}) | ||
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
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