diff --git a/app/components/article-list.hbs b/app/components/article-list.hbs
index 1c250b9..1178a69 100644
--- a/app/components/article-list.hbs
+++ b/app/components/article-list.hbs
@@ -7,7 +7,7 @@
{{else}}
No articles are here... yet.
{{/each}}
- {{#if this.articles}}
+ {{#if this.showPagination}}
{{/if}}
diff --git a/app/components/article-list.js b/app/components/article-list.js
index 0330e52..f9ca256 100644
--- a/app/components/article-list.js
+++ b/app/components/article-list.js
@@ -3,9 +3,12 @@ import { tracked } from '@glimmer/tracking';
import { task } from 'ember-concurrency-decorators';
import { inject as service } from '@ember/service';
+const NUMBER_OF_ARTICLES_PER_PAGE = 10;
+
export default class ArticleListComponent extends Component {
@service session;
@service store;
+ @service router;
@tracked articles = [];
constructor() {
@@ -15,16 +18,23 @@ export default class ArticleListComponent extends Component {
@task({ restartable: true })
*loadArticles() {
- let NUMBER_OF_ARTICLES = 10;
- let offset = (parseInt(this.args.page, 10) - 1) * NUMBER_OF_ARTICLES;
+ let offset = (parseInt(this.args.page, 10) - 1) * NUMBER_OF_ARTICLES_PER_PAGE;
if (this.args.feed === 'your') {
- this.articles = yield this.session.user.fetchFeed(this.args.page);
+ if (this.session.isLoggedIn) {
+ this.articles = yield this.session.user.fetchFeed(this.args.page);
+ } else {
+ this.router.transitionTo('index', { queryParams: { feed: null } });
+ }
} else {
this.articles = yield this.store.query('article', {
- limit: NUMBER_OF_ARTICLES,
- offset,
- tag: this.args.tag,
+ limit: NUMBER_OF_ARTICLES_PER_PAGE,
+ offset: offset,
+ tag: this.args.tag || undefined,
});
}
}
+
+ get showPagination() {
+ return this.articles && this.articles.length > NUMBER_OF_ARTICLES_PER_PAGE;
+ }
}
diff --git a/app/components/favorite-article.hbs b/app/components/favorite-article.hbs
index ac5b8dd..5c69cd6 100644
--- a/app/components/favorite-article.hbs
+++ b/app/components/favorite-article.hbs
@@ -1,4 +1,3 @@
-article favorited: {{@article.favorited}}