From 4ba3d8c6a22479d8f45a7b5a0967eae0bff974fe Mon Sep 17 00:00:00 2001 From: bluecloud <96812901+pitb2022@users.noreply.github.com> Date: Thu, 30 May 2024 21:27:08 +0800 Subject: [PATCH 01/11] fix(ArticleDetail): fix quote scope error & add data tracker ref: https://matterslab.slack.com/archives/GA0R09FHN/p1717072050897659 https://matterslab.slack.com/archives/CH8BLCMTN/p1717074260052259?thread_ts=1717068906.284559&cid=CH8BLCMTN --- src/common/utils/analytics.ts | 1 + src/components/TextSelectionPopover/index.tsx | 7 ++++++- src/views/ArticleDetail/Content/index.tsx | 6 +++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/common/utils/analytics.ts b/src/common/utils/analytics.ts index af211cde71..f6372f4934 100644 --- a/src/common/utils/analytics.ts +++ b/src/common/utils/analytics.ts @@ -85,6 +85,7 @@ export interface ClickButtonProp { | 'edit' | 'edited' | 'appreciate' + | 'article_content_quote' | 'comment_open' | 'comment_close' | 'comment_placeholder' diff --git a/src/components/TextSelectionPopover/index.tsx b/src/components/TextSelectionPopover/index.tsx index 48349fcc4d..4c95bcbcf8 100644 --- a/src/components/TextSelectionPopover/index.tsx +++ b/src/components/TextSelectionPopover/index.tsx @@ -4,6 +4,7 @@ import { useEffect, useRef, useState } from 'react' import { ReactComponent as IconComment } from '@/public/static/icons/24px/comment.svg' import { OPEN_COMMENT_LIST_DRAWER } from '~/common/enums' import { isElementInViewport } from '~/common/utils' +import { analytics } from '~/common/utils' import { Icon, useCommentEditorContext } from '~/components' import styles from './styles.module.css' @@ -60,7 +61,7 @@ export const TextSelectionPopover = ({ const [quote, setQuote] = useState(null) useEffect(() => { - const editor = getCurrentEditor() + const editor = getCurrentEditor?.() if (!editor || !quote) { return } @@ -150,6 +151,10 @@ export const TextSelectionPopover = ({ if (!selection) { return } + analytics.trackEvent('click_button', { + type: 'article_content_quote', + pageType: 'article_detail', + }) window.dispatchEvent(new CustomEvent(OPEN_COMMENT_LIST_DRAWER)) setQuote(`
${selection}
`) diff --git a/src/views/ArticleDetail/Content/index.tsx b/src/views/ArticleDetail/Content/index.tsx index 940e6cc9e5..ded7e15a1e 100644 --- a/src/views/ArticleDetail/Content/index.tsx +++ b/src/views/ArticleDetail/Content/index.tsx @@ -9,6 +9,7 @@ import { Media, TextSelectionPopover, useMutation, + useRoute, ViewerContext, } from '~/components' import { ReadArticleMutation } from '~/gql/graphql' @@ -39,6 +40,9 @@ const Content = ({ const contentContainer = useRef(null) + const { isInPath } = useRoute() + const isInArticleDetailHistory = isInPath('ARTICLE_DETAIL_HISTORY') + // idle timer const [lastScroll, setScrollTime] = useState(0) @@ -127,7 +131,7 @@ const Content = ({ data-test-id={TEST_ID.ARTICLE_CONTENT} /> - {contentContainer.current && ( + {!isInArticleDetailHistory && contentContainer.current && ( From 7b8625e784f33ef922c4e02d90b406426c5a397c Mon Sep 17 00:00:00 2001 From: robertu <4065233+robertu7@users.noreply.github.com> Date: Thu, 6 Jun 2024 17:12:49 +0800 Subject: [PATCH 02/11] fix(billboard): fix responsive issue --- src/components/Billboard/index.tsx | 74 ++++++++++------------ src/components/Billboard/styles.module.css | 24 +++++-- 2 files changed, 54 insertions(+), 44 deletions(-) diff --git a/src/components/Billboard/index.tsx b/src/components/Billboard/index.tsx index e91b95a3a5..3f36121ef6 100644 --- a/src/components/Billboard/index.tsx +++ b/src/components/Billboard/index.tsx @@ -7,7 +7,6 @@ import { BillboardDialog, BillboardExposureTracker, Icon, - Spinner, TextIcon, } from '~/components' @@ -34,7 +33,7 @@ export const Billboard = ({ tokenId, type }: BillboardProps) => { cacheTime: 60_000, }) - if (!id || isError || !data || !data.contentURI) { + if (!id || isError || isLoading || !data || !data.contentURI) { return null } @@ -43,43 +42,40 @@ export const Billboard = ({ tokenId, type }: BillboardProps) => { {({ openDialog: openBillboardDialog }) => { return (
- {isLoading && } - {!isLoading && ( - <> - - analytics.trackEvent('click_billboard', { - id, - type, - target: data.redirectURI, - }) - } - > - ad - - - - - )} + + analytics.trackEvent('click_billboard', { + id, + type, + target: data.redirectURI, + }) + } + > + ad + + + + +
) }} diff --git a/src/components/Billboard/styles.module.css b/src/components/Billboard/styles.module.css index d81e91d866..69a2447310 100644 --- a/src/components/Billboard/styles.module.css +++ b/src/components/Billboard/styles.module.css @@ -1,20 +1,34 @@ .billboard { - display: block; - max-width: 21.4375rem; + max-width: 100%; + + @media (--sm-up) { + max-width: 50%; + } + + @media (--md-up) { + max-width: 100%; + } & a { @mixin flex-center-all; - line-height: 0; + position: relative; + + &::after { + display: block; + padding-bottom: 56.06%; + content: ''; + } & img { - width: 100%; - max-height: 10.5rem; + @mixin object-fit-cover; + border-radius: 1.25rem; } } & .button { + margin-top: var(--sp8); color: var(--color-grey); } } From fe26dd872619e0d1ea215cc85f6794cca1497f4e Mon Sep 17 00:00:00 2001 From: robertu <4065233+robertu7@users.noreply.github.com> Date: Thu, 6 Jun 2024 17:16:40 +0800 Subject: [PATCH 03/11] feat(home): revise sidebar authors & tags page size to 4 --- src/views/Home/Sidebar/Authors/index.tsx | 2 +- src/views/Home/Sidebar/Tags/index.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/Home/Sidebar/Authors/index.tsx b/src/views/Home/Sidebar/Authors/index.tsx index 2be017d1c7..be0e85eecf 100644 --- a/src/views/Home/Sidebar/Authors/index.tsx +++ b/src/views/Home/Sidebar/Authors/index.tsx @@ -31,7 +31,7 @@ const Authors = () => { /** * Data Fetching */ - const perPage = 5 + const perPage = 4 const randomMaxSize = 50 const { data, loading, error, refetch } = usePublicQuery( SIDEBAR_AUTHORS, diff --git a/src/views/Home/Sidebar/Tags/index.tsx b/src/views/Home/Sidebar/Tags/index.tsx index 955cd6ab8a..948fa3605b 100644 --- a/src/views/Home/Sidebar/Tags/index.tsx +++ b/src/views/Home/Sidebar/Tags/index.tsx @@ -52,7 +52,7 @@ const Tags = () => { { variables: { id: 'local' } } ) const lastRandom = lastFetchRandom?.lastFetchRandom.sidebarTags // last Random - const perPage = 6 + const perPage = 4 const randomMaxSize = 50 const { data, loading, error, refetch } = usePublicQuery( From 56d6470724ae4a8f8b8e086565ede28f71842d45 Mon Sep 17 00:00:00 2001 From: robertu <4065233+robertu7@users.noreply.github.com> Date: Thu, 6 Jun 2024 16:23:16 +0800 Subject: [PATCH 04/11] fix(history): useQuery instead usePublicQuery to fetch comment history --- src/views/Me/History/Comments/index.tsx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/views/Me/History/Comments/index.tsx b/src/views/Me/History/Comments/index.tsx index 84493f8ddf..9deacd1586 100644 --- a/src/views/Me/History/Comments/index.tsx +++ b/src/views/Me/History/Comments/index.tsx @@ -1,3 +1,4 @@ +import { useQuery } from '@apollo/react-hooks' import _flatten from 'lodash/flatten' import { useContext } from 'react' import { useIntl } from 'react-intl' @@ -17,7 +18,6 @@ import { List, QueryError, SpinnerBlock, - usePublicQuery, ViewerContext, } from '~/components' import { MeCommentsQuery } from '~/gql/graphql' @@ -48,12 +48,9 @@ const Comments = () => { /** * Data Fetching */ - // public data - const { data, loading, error, fetchMore } = usePublicQuery( + const { data, loading, error, fetchMore } = useQuery( ME_COMMENTS, - { - variables: { id: viewer?.id }, - } + { variables: { id: viewer?.id } } ) // pagination From aef7908d8734e10e0fc80fd6434bcedb9261c99f Mon Sep 17 00:00:00 2001 From: robertu <4065233+robertu7@users.noreply.github.com> Date: Fri, 14 Jun 2024 10:19:36 +0800 Subject: [PATCH 05/11] feat(article): lazy load sidebar related articles & collection --- .../AuthorSidebar/Collection/index.tsx | 4 ++- .../AuthorSidebar/RelatedArticles/index.tsx | 30 +++++++++++++++++-- src/views/ArticleDetail/AuthorSidebar/gql.ts | 6 ++++ .../ArticleDetail/AuthorSidebar/index.tsx | 20 +++++++++---- src/views/ArticleDetail/gql.ts | 6 ---- 5 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/views/ArticleDetail/AuthorSidebar/Collection/index.tsx b/src/views/ArticleDetail/AuthorSidebar/Collection/index.tsx index 5e789ccbfa..c7a0e857c0 100644 --- a/src/views/ArticleDetail/AuthorSidebar/Collection/index.tsx +++ b/src/views/ArticleDetail/AuthorSidebar/Collection/index.tsx @@ -27,7 +27,7 @@ type CollectionProps = { article: ArticleDetailPublicQuery['article'] } -export const Collection = ({ article, collectionId }: CollectionProps) => { +const Collection = ({ article, collectionId }: CollectionProps) => { /** * Data Fetching */ @@ -132,3 +132,5 @@ export const Collection = ({ article, collectionId }: CollectionProps) => { ) } + +export default Collection diff --git a/src/views/ArticleDetail/AuthorSidebar/RelatedArticles/index.tsx b/src/views/ArticleDetail/AuthorSidebar/RelatedArticles/index.tsx index 2deaf86e38..7a75ca5c36 100644 --- a/src/views/ArticleDetail/AuthorSidebar/RelatedArticles/index.tsx +++ b/src/views/ArticleDetail/AuthorSidebar/RelatedArticles/index.tsx @@ -5,8 +5,13 @@ import { ArticleDigestAuthorSidebar, ArticleDigestSidebar, List, + SpinnerBlock, + usePublicQuery, } from '~/components' -import { ArticleDetailPublicQuery } from '~/gql/graphql' +import { + ArticleDetailPublicQuery, + AuthorSidebarRelatedArticlesQuery, +} from '~/gql/graphql' type RelatedArticlesProps = { article: NonNullable @@ -30,8 +35,29 @@ const fragments = { `, } +const RELATED_ARTICLES = gql` + query AuthorSidebarRelatedArticles($shortHash: String) { + article(input: { shortHash: $shortHash }) { + id + ...AuthorSidebarRelatedArticles + } + } + ${fragments.article} +` + export const RelatedArticles = ({ article }: RelatedArticlesProps) => { - const edges = article.relatedArticles.edges + const { data, loading } = usePublicQuery( + RELATED_ARTICLES, + { + variables: { shortHash: article.shortHash }, + } + ) + + const edges = data?.article?.relatedArticles.edges + + if (loading) { + return + } if (!edges || edges.length <= 0) { return null diff --git a/src/views/ArticleDetail/AuthorSidebar/gql.ts b/src/views/ArticleDetail/AuthorSidebar/gql.ts index 7adc085560..f6d530b281 100644 --- a/src/views/ArticleDetail/AuthorSidebar/gql.ts +++ b/src/views/ArticleDetail/AuthorSidebar/gql.ts @@ -1,13 +1,19 @@ import gql from 'graphql-tag' import Author from './Author' +import { FromAuthor } from './FromAuthor' export const fragments = { article: gql` fragment AuthorSidebarArticle on Article { id + relatedArticles(input: { first: 0 }) { + totalCount + } ...AuthorSidebarAuthorArticle + ...AuthorSidebarFromAuthor } ${Author.fragments.article} + ${FromAuthor.fragments.article} `, } diff --git a/src/views/ArticleDetail/AuthorSidebar/index.tsx b/src/views/ArticleDetail/AuthorSidebar/index.tsx index 34986e0c69..1de0fe8165 100644 --- a/src/views/ArticleDetail/AuthorSidebar/index.tsx +++ b/src/views/ArticleDetail/AuthorSidebar/index.tsx @@ -1,10 +1,10 @@ +import dynamic from 'next/dynamic' import { useState } from 'react' -import { useRoute } from '~/components' +import { SpinnerBlock, useRoute } from '~/components' import { ArticleDetailPublicQuery } from '~/gql/graphql' import Author from './Author' -import { Collection } from './Collection' import { FromAuthor } from './FromAuthor' import { fragments } from './gql' import { Placeholder } from './Placeholder' @@ -16,16 +16,21 @@ type AuthorSidebarProps = { article: NonNullable } +const DynamicCollection = dynamic(() => import('./Collection'), { + ssr: false, + loading: () => , +}) + export const AuthorSidebar = ({ article }: AuthorSidebarProps) => { const { getQuery } = useRoute() - const cid = getQuery('collection') + const collectionId = getQuery('collection') const latestWorks = article.author?.latestWorks.filter((work) => { return work.id !== article.id }) const hasFromAuthor = latestWorks && latestWorks.length > 0 const hasRecommendation = article.relatedArticles?.totalCount > 0 const [tab, setTab] = useState( - !!cid + !!collectionId ? 'Collection' : hasFromAuthor ? 'Author' @@ -41,8 +46,11 @@ export const AuthorSidebar = ({ article }: AuthorSidebarProps) => { <>
- {!!cid && tab === 'Collection' && ( - + {!!collectionId && tab === 'Collection' && ( + )} {tab === 'Author' && } {tab === 'Recommendation' && } diff --git a/src/views/ArticleDetail/gql.ts b/src/views/ArticleDetail/gql.ts index 7499870807..94d4861ddf 100644 --- a/src/views/ArticleDetail/gql.ts +++ b/src/views/ArticleDetail/gql.ts @@ -3,8 +3,6 @@ import gql from 'graphql-tag' import { UserDigest } from '~/components/UserDigest' import { AuthorSidebar } from './AuthorSidebar' -import { FromAuthor } from './AuthorSidebar/FromAuthor' -import { RelatedArticles } from './AuthorSidebar/RelatedArticles' import MetaInfo from './MetaInfo' import StickyTopBanner from './StickyTopBanner' import { fragments as supportWidgetFragments } from './Support/SupportWidget/gql' @@ -68,8 +66,6 @@ const articlePublicFragment = gql` ...AuthorSidebarArticle ...MetaInfoArticle ...TagListArticle - ...AuthorSidebarRelatedArticles - ...AuthorSidebarFromAuthor ...StateArticle ...ToolbarArticlePublic ...ToolbarArticlePrivate @@ -79,8 +75,6 @@ const articlePublicFragment = gql` ${AuthorSidebar.fragments.article} ${MetaInfo.fragments.article} ${TagList.fragments.article} - ${RelatedArticles.fragments.article} - ${FromAuthor.fragments.article} ${StickyTopBanner.fragments.article} ${UserDigest.Rich.fragments.user.public} ${UserDigest.Rich.fragments.user.private} From 70b2ff736b7731a987d51e875f7808f747a35d19 Mon Sep 17 00:00:00 2001 From: robertu <4065233+robertu7@users.noreply.github.com> Date: Fri, 14 Jun 2024 11:23:48 +0800 Subject: [PATCH 06/11] feat(article): revise loading comp of related articles --- .../ArticleDetail/AuthorSidebar/RelatedArticles/index.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/views/ArticleDetail/AuthorSidebar/RelatedArticles/index.tsx b/src/views/ArticleDetail/AuthorSidebar/RelatedArticles/index.tsx index 7a75ca5c36..b3d27910aa 100644 --- a/src/views/ArticleDetail/AuthorSidebar/RelatedArticles/index.tsx +++ b/src/views/ArticleDetail/AuthorSidebar/RelatedArticles/index.tsx @@ -5,7 +5,6 @@ import { ArticleDigestAuthorSidebar, ArticleDigestSidebar, List, - SpinnerBlock, usePublicQuery, } from '~/components' import { @@ -13,6 +12,8 @@ import { AuthorSidebarRelatedArticlesQuery, } from '~/gql/graphql' +import { FeedPlaceholder } from '../Placeholder' + type RelatedArticlesProps = { article: NonNullable } @@ -56,7 +57,7 @@ export const RelatedArticles = ({ article }: RelatedArticlesProps) => { const edges = data?.article?.relatedArticles.edges if (loading) { - return + return } if (!edges || edges.length <= 0) { From 6a15117e1e0149900abdd3b1256097961f6bec32 Mon Sep 17 00:00:00 2001 From: robertu <4065233+robertu7@users.noreply.github.com> Date: Fri, 14 Jun 2024 12:06:19 +0800 Subject: [PATCH 07/11] chore(release): v5.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e2129faa14..3e34a1917b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "matters-web", - "version": "5.1.1", + "version": "5.1.2", "description": "codebase of Matters' website", "author": "Matters ", "engines": { From a7d9fb5db8d6d239395acfc12bc86ee2634893a4 Mon Sep 17 00:00:00 2001 From: bluecloud <96812901+pitb2022@users.noreply.github.com> Date: Fri, 14 Jun 2024 16:04:17 +0800 Subject: [PATCH 08/11] fix(Expandable): fix fractional issue --- src/components/Expandable/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Expandable/index.tsx b/src/components/Expandable/index.tsx index 0bbc6c7e0b..61e94b80d8 100644 --- a/src/components/Expandable/index.tsx +++ b/src/components/Expandable/index.tsx @@ -47,7 +47,7 @@ const calculateCommentContentHeight = (element: HTMLElement): number => { if (contentNode) { contentNode.childNodes.forEach((child) => { const e = child as HTMLElement - height += e.clientHeight + height += e.getBoundingClientRect().height }) } return height From 348348a14bc240cdc660f88641d231e95de7d382 Mon Sep 17 00:00:00 2001 From: bluecloud <96812901+pitb2022@users.noreply.github.com> Date: Fri, 14 Jun 2024 16:36:58 +0800 Subject: [PATCH 09/11] fix(Expandable): fix unit test --- src/components/Expandable/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/Expandable/index.tsx b/src/components/Expandable/index.tsx index 61e94b80d8..1e475e9324 100644 --- a/src/components/Expandable/index.tsx +++ b/src/components/Expandable/index.tsx @@ -47,7 +47,9 @@ const calculateCommentContentHeight = (element: HTMLElement): number => { if (contentNode) { contentNode.childNodes.forEach((child) => { const e = child as HTMLElement - height += e.getBoundingClientRect().height + if (e.getBoundingClientRect) { + height += e.getBoundingClientRect().height + } }) } return height From 54ac45e0f55d84803fbb04802886e826aeaaf13b Mon Sep 17 00:00:00 2001 From: bluecloud <96812901+pitb2022@users.noreply.github.com> Date: Mon, 17 Jun 2024 14:35:56 +0800 Subject: [PATCH 10/11] fix(CommentDetail): fetch network only --- src/views/ArticleDetail/Comments/CommentDetail/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/views/ArticleDetail/Comments/CommentDetail/index.tsx b/src/views/ArticleDetail/Comments/CommentDetail/index.tsx index bb4a9cc916..3e49b6827b 100644 --- a/src/views/ArticleDetail/Comments/CommentDetail/index.tsx +++ b/src/views/ArticleDetail/Comments/CommentDetail/index.tsx @@ -46,6 +46,7 @@ const CommentDetail = () => { variables: { id: parentId, }, + fetchPolicy: 'network-only', } ) From ee5577d81f2e7c077e90396c66ab00877c245094 Mon Sep 17 00:00:00 2001 From: j <13580441+gary02@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:37:13 +0800 Subject: [PATCH 11/11] chore: bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index faa2bf158a..adce68b632 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "matters-web", - "version": "5.1.1", + "version": "5.1.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "matters-web", - "version": "5.1.1", + "version": "5.1.3", "license": "Apache-2.0", "dependencies": { "@apollo/react-common": "^3.1.3", diff --git a/package.json b/package.json index fd4c397ed0..449ca19401 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "matters-web", - "version": "5.1.2", + "version": "5.1.3", "description": "codebase of Matters' website", "author": "Matters ", "engines": {