From 69b0ac90d3f39201b016b818087c827dfc66260f Mon Sep 17 00:00:00 2001 From: MrOrz Date: Mon, 11 Jul 2022 14:39:06 +0800 Subject: [PATCH 1/3] [ProfilePage] add message count of filtered messages --- components/ProfilePage/ProfilePage.js | 7 +------ components/ProfilePage/RepliedArticleTab.js | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/components/ProfilePage/ProfilePage.js b/components/ProfilePage/ProfilePage.js index 7eff1b28..e1a3917b 100644 --- a/components/ProfilePage/ProfilePage.js +++ b/components/ProfilePage/ProfilePage.js @@ -162,12 +162,7 @@ function ProfilePage({ id, slug }) { router.push({ query: { tab } }); }} > - + {contentElem} diff --git a/components/ProfilePage/RepliedArticleTab.js b/components/ProfilePage/RepliedArticleTab.js index 98b3a732..15a97095 100644 --- a/components/ProfilePage/RepliedArticleTab.js +++ b/components/ProfilePage/RepliedArticleTab.js @@ -13,7 +13,7 @@ import { SortInput, LoadMore, } from 'components/ListPageControls'; -import { CardContent } from 'components/Card'; +import { CardHeader, CardContent } from 'components/Card'; import Infos from 'components/Infos'; import TimeInfo from 'components/Infos/TimeInfo'; import ExpandableText from 'components/ExpandableText'; @@ -78,6 +78,7 @@ const LOAD_REPLIED_ARTICLES_STAT = gql` $orderBy: [ListArticleOrderBy] ) { ListArticles(filter: $filter, orderBy: $orderBy) { + totalCount ...LoadMoreConnectionForStats } } @@ -223,6 +224,7 @@ function RepliedArticleTab({ userId }) { // List data const articleEdges = listArticlesData?.ListArticles?.edges || []; const statsData = listStatData?.ListArticles || {}; + const totalCount = statsData?.totalCount; if (!userId) { return null; @@ -238,14 +240,21 @@ function RepliedArticleTab({ userId }) { - {loading && !articleEdges.length ? ( + {loading && !totalCount ? ( {t`Loading...`} ) : listArticlesError ? ( {listArticlesError.toString()} - ) : articleEdges.length === 0 ? ( + ) : totalCount === 0 ? ( {t`No replied messages.`} ) : ( <> + + {ngettext( + msgid`${totalCount} message matching criteria`, + `${totalCount} messages matching criteria`, + totalCount + )} + {articleEdges.map(({ node: article }) => ( From bff7d37fbadf68bd561dcbd919d4b03dc4688cc4 Mon Sep 17 00:00:00 2001 From: MrOrz Date: Mon, 11 Jul 2022 16:18:34 +0800 Subject: [PATCH 2/3] [ProfilePage] Time filter and type filter should act on the users' article-reply rather than any article replies. Also, add a sort option that sorts by matching (user's) article reply. --- components/ProfilePage/RepliedArticleTab.js | 35 +++++++++++---------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/components/ProfilePage/RepliedArticleTab.js b/components/ProfilePage/RepliedArticleTab.js index 15a97095..1f5617ee 100644 --- a/components/ProfilePage/RepliedArticleTab.js +++ b/components/ProfilePage/RepliedArticleTab.js @@ -25,7 +25,11 @@ import ReplyInfo from 'components/ReplyInfo'; import { nl2br, linkify } from 'lib/text'; const REPLIES_ORDER = [ - { value: 'lastRepliedAt', label: t`Most recently replied` }, + { + value: 'lastMatchingArticleReplyCreatedAt', + label: t`Most recently replied`, + }, + { value: 'lastRepliedAt', label: t`Most recently replied by any users` }, { value: 'lastRequestedAt', label: t`Most recently asked` }, { value: 'replyRequestCount', label: t`Most asked` }, ]; @@ -159,12 +163,12 @@ function ArticleReply({ articleReply }) { /** * @param {object} urlQuery - URL query object and urserId + * @param {string} userId - The author ID of article reply to look for * @returns {object} ListArticleFilter */ -function urlQuery2Filter(query = {}) { +function urlQuery2Filter(query = {}, userId) { const filterObj = { - // Default filters - replyCount: { GTE: 1 }, + articleReply: { userId }, }; const selectedCategoryIds = CategoryFilter.getValues(query); @@ -173,19 +177,21 @@ function urlQuery2Filter(query = {}) { const [start, end] = TimeRange.getValues(query); if (start) { - filterObj.repliedAt = { ...filterObj.repliedAt, GTE: start }; + filterObj.articleReply.createdAt = { + ...filterObj.articleReply.createdAt, + GTE: start, + }; } if (end) { - filterObj.repliedAt = { ...filterObj.repliedAt, LTE: end }; + filterObj.articleReply.createdAt = { + ...filterObj.articleReply.createdAt, + LTE: end, + }; } const selectedReplyTypes = ReplyTypeFilter.getValues(query); - if (selectedReplyTypes.length) filterObj.replyTypes = selectedReplyTypes; - - // Return filterObj only when it is populated. - if (!Object.keys(filterObj).length) { - return undefined; - } + if (selectedReplyTypes.length) + filterObj.articleReply.replyTypes = selectedReplyTypes; return filterObj; } @@ -195,10 +201,7 @@ function RepliedArticleTab({ userId }) { const { query } = useRouter(); const listQueryVars = { - filter: { - ...urlQuery2Filter(query), - articleRepliesFrom: { userId, exists: true }, - }, + filter: urlQuery2Filter(query, userId), orderBy: [{ [SortInput.getValue(query) || DEFAULT_ORDER]: 'DESC' }], }; From 4ce1738566df82a686c5b601d13e0bde0bc56b76 Mon Sep 17 00:00:00 2001 From: MrOrz Date: Mon, 11 Jul 2022 16:40:55 +0800 Subject: [PATCH 3/3] [ProfilePage] grammer fix --- components/ProfilePage/RepliedArticleTab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/ProfilePage/RepliedArticleTab.js b/components/ProfilePage/RepliedArticleTab.js index 1f5617ee..8f5833e3 100644 --- a/components/ProfilePage/RepliedArticleTab.js +++ b/components/ProfilePage/RepliedArticleTab.js @@ -29,7 +29,7 @@ const REPLIES_ORDER = [ value: 'lastMatchingArticleReplyCreatedAt', label: t`Most recently replied`, }, - { value: 'lastRepliedAt', label: t`Most recently replied by any users` }, + { value: 'lastRepliedAt', label: t`Most recently replied by any user` }, { value: 'lastRequestedAt', label: t`Most recently asked` }, { value: 'replyRequestCount', label: t`Most asked` }, ];