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

52 lines
1.3 KiB
React
Raw Normal View History

import Telescope from "meteor/nova:lib";
import React, { PropTypes, Component } from "react";
// import { Button } from "react-bootstrap";
import moment from "moment";
import { FormattedMessage } from "react-intl";
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}><FormattedMessage id="posts.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;