From 9dab1370833c3c7d12b8f5c736615453ab6a48cd Mon Sep 17 00:00:00 2001 From: Joshua Flores Date: Fri, 31 Dec 2021 10:55:14 -0600 Subject: [PATCH 1/3] use email as primary key for users --- app/serializers/user.js | 1 + app/services/session.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/serializers/user.js b/app/serializers/user.js index 0d8cc3f..362cca0 100644 --- a/app/serializers/user.js +++ b/app/serializers/user.js @@ -1,6 +1,7 @@ import ApplicationSerializer from './application'; export default class UserSerializer extends ApplicationSerializer { + primaryKey = 'email'; attrs = { token: { serialize: false, diff --git a/app/services/session.js b/app/services/session.js index 2d8e7b9..46d1b42 100644 --- a/app/services/session.js +++ b/app/services/session.js @@ -78,7 +78,7 @@ export default class SessionService extends Service { users: [userPayload.user], }); this.setToken(userPayload.user.token); - this.user = this.store.peekRecord('user', userPayload.user.id); + this.user = this.store.peekRecord('user', userPayload.user.email); return this.user; } } @@ -93,7 +93,7 @@ export default class SessionService extends Service { this.store.pushPayload({ users: [user], }); - this.user = this.store.peekRecord('user', user.id); + this.user = this.store.peekRecord('user', user.email); return this.user; } From 9be55315518dd7edb1c909f78e86883125fecb34 Mon Sep 17 00:00:00 2001 From: Joshua Flores Date: Fri, 31 Dec 2021 10:58:16 -0600 Subject: [PATCH 2/3] - ALTER pagination to show only if more than 1 page. - FIX: on logout redirect any /?feed=your to '/' - FIX: article query to work when tag param is null. --- app/components/article-list.hbs | 2 +- app/components/article-list.js | 22 ++++++++++++++++------ app/serializers/article.js | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) 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/serializers/article.js b/app/serializers/article.js index 4a5bf45..e307d64 100644 --- a/app/serializers/article.js +++ b/app/serializers/article.js @@ -5,6 +5,7 @@ export default class ArticleSerializer extends RESTSerializer.extend(EmbeddedRec attrs = { author: { embedded: 'always' }, + comments: { embedded: 'always' }, }; extractMeta(store, typeClass, payload) { From 2bf808eb203d68911b24517cda303c87b1aa73ed Mon Sep 17 00:00:00 2001 From: Joshua Flores Date: Fri, 31 Dec 2021 10:58:30 -0600 Subject: [PATCH 3/3] clean up --- app/components/favorite-article.hbs | 1 - 1 file changed, 1 deletion(-) 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}}