From 06021c5f866fa90597d27bdf99c722d426f2001a Mon Sep 17 00:00:00 2001 From: Yuki Ishii <37304826+komura-c@users.noreply.github.com> Date: Mon, 4 Nov 2024 03:39:27 +0900 Subject: [PATCH] fix: getMyArticles (#330) --- src/app/services/article.service.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/app/services/article.service.ts b/src/app/services/article.service.ts index f5ebb52d..5bcaa7f2 100644 --- a/src/app/services/article.service.ts +++ b/src/app/services/article.service.ts @@ -16,6 +16,7 @@ import { limit, orderBy, query, + QueryConstraint, setDoc, startAfter, Timestamp, @@ -163,13 +164,15 @@ export class ArticleService { articles: Article[]; lastArticle: Article; }> { - const articlesQuery = query( - this.articlesCollection, + const queryOperator: QueryConstraint[] = [ where('uid', '==', uid), - lastArticle ? startAfter(lastArticle.updatedAt) : null, orderBy('updatedAt', 'desc'), - limit(20) - ); + limit(20), + ]; + if (lastArticle) { + queryOperator.push(startAfter(lastArticle.updatedAt)); + } + const articlesQuery = query(this.articlesCollection, ...queryOperator); const articles$ = collectionData
(articlesQuery); return articles$.pipe( map((articles) => {