Skip to content

Instantly share code, notes, and snippets.

@firrae
Last active November 2, 2015 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save firrae/5f439a55d4d604a96a73 to your computer and use it in GitHub Desktop.
Save firrae/5f439a55d4d604a96a73 to your computer and use it in GitHub Desktop.
Dashboard = React.createClass({
mixins: [ ReactMeteorData ],
getMeteorData() {
let subscription = Meteor.subscribe( 'newsFeed' );
let page = new ReactiveVar();
page.set(0);
return {
isLoading: !subscription.ready(),
news: News.find({}, {limit: 3, skip: (page.get() * 3), sort: {createdDate: 1}}).fetch(),
page: page,
totalCount: Counts.get( 'newsCounter' )
};
},
componentDidMount() {
},
newer() {
this.data.page.set(this.data.page.get() + 1);
console.log(this.data.page.get());
},
older() {
if(this.data.page.get() > 0)
this.data.page.set(this.data.page.get() - 1);
console.log(this.data.page.get());
},
render() {
if ( this.data.isLoading ) {
return <Loading />;
} else {
return (
<div>
<NewsList news={this.data.news} />
<ul className="pager">
<li className={this.data.page.get() <= 0 ? 'previous disabled' : 'previous' } onClick={this.older}><a href="#">← Older</a></li>
<li className="next" onClick={this.newer}><a href="#">Newer →</a></li>
</ul>
</div>
);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment