Vulcan/packages/nova-base-components/lib/posts/PostsDaily.jsx

49 lines
1.1 KiB
React
Raw Normal View History

2016-03-22 10:22:46 +09:00
import React, { PropTypes, Component } from 'react';
2016-03-28 11:43:42 +09:00
import { Button } from 'react-bootstrap';
2016-03-22 10:22:46 +09:00
2016-04-14 10:12:35 +09:00
class PostsDaily extends Component{
2016-03-22 10:22:46 +09:00
constructor(props) {
super(props);
this.loadMoreDays = this.loadMoreDays.bind(this);
this.state = {days: props.days};
}
// for a number of days "n" return dates object for the past n days
getLastNDates(n) {
return _.range(n).map(
i => moment().subtract(i, 'days').startOf('day').toDate()
);
}
2016-03-22 10:22:46 +09:00
loadMoreDays(e) {
e.preventDefault();
this.setState({
days: this.state.days + this.props.increment
2016-03-22 10:22:46 +09:00
});
}
render() {
return (
<div className="posts-daily">
<Telescope.components.PostsListHeader />
{this.getLastNDates(this.state.days).map((date, index) => <Telescope.components.PostsDay key={index} date={date} number={index}/>)}
<button className="posts-load-more" onClick={this.loadMoreDays}>Load More Days</button>
2016-03-22 10:22:46 +09:00
</div>
)
}
}
2016-04-14 10:12:35 +09:00
PostsDaily.propTypes = {
days: React.PropTypes.number,
increment: React.PropTypes.number
2016-03-22 10:22:46 +09:00
}
2016-04-14 10:12:35 +09:00
PostsDaily.defaultProps = {
days: 5,
increment: 5
2016-03-22 10:22:46 +09:00
}
2016-04-14 10:12:35 +09:00
module.exports = PostsDaily;
export default PostsDaily;