diff --git a/src/common/enums/article.ts b/src/common/enums/article.ts index 8d53ba3cb8..ea3aecc53b 100644 --- a/src/common/enums/article.ts +++ b/src/common/enums/article.ts @@ -2,3 +2,5 @@ export const COMMENTS_COUNT = 40 export const TOOLBAR_FIXEDTOOLBAR_ID = 'toolbar/fixedToolbar/id' export const COMMENT_FEED_ID_PREFIX = 'comment-feed-' export const SUPPORT_TAB_PREFERENCE_KEY = 'support-tab-preference-key' +export const ARTICLE_DIGEST_AUTHOR_SIDEBAR_ID_PREFIX = + 'article-digest-author-sidebar-' diff --git a/src/common/utils/connections.ts b/src/common/utils/connections.ts index 914c9a749e..6329412a57 100644 --- a/src/common/utils/connections.ts +++ b/src/common/utils/connections.ts @@ -54,7 +54,7 @@ export const unshiftConnections = ({ newData: any path: string }) => { - const { edges: oldEdges, pageInfo: oldPageInfo } = _get(oldData, path) + const { edges: oldEdges } = _get(oldData, path) const { edges: newEdges, pageInfo: newPageInfo, @@ -65,9 +65,7 @@ export const unshiftConnections = ({ ...rest, pageInfo: { ...newPageInfo, - endCursor: oldPageInfo.endCursor, - hasNextPage: oldPageInfo.hasNextPage, }, - edges: _uniqBy([...oldEdges, ...newEdges], (edge) => edge.node.id), + edges: _uniqBy([...newEdges, ...oldEdges], (edge) => edge.node.id), }) } diff --git a/src/common/utils/route.ts b/src/common/utils/route.ts index d815ab0930..c0fda146ff 100644 --- a/src/common/utils/route.ts +++ b/src/common/utils/route.ts @@ -117,7 +117,11 @@ type ToPathArgs = * (works on SSR & CSR) */ export const toPath = ( - args: ToPathArgs & { fragment?: string; search?: { [key: string]: string } } + args: ToPathArgs & { + cursor?: string + fragment?: string + search?: { [key: string]: string } + } ): { href: string } => { @@ -132,6 +136,10 @@ export const toPath = ( if (args.collectionId) { href = `${href}?collection=${args.collectionId}` + + if (args.cursor) { + href = `${href}&cursor=${args.cursor}` + } } break diff --git a/src/components/ArticleDigest/AuthorSidebar/index.tsx b/src/components/ArticleDigest/AuthorSidebar/index.tsx index 9221e2eeed..fe06ac3b23 100644 --- a/src/components/ArticleDigest/AuthorSidebar/index.tsx +++ b/src/components/ArticleDigest/AuthorSidebar/index.tsx @@ -1,7 +1,10 @@ import classNames from 'classnames' import gql from 'graphql-tag' -import { TEST_ID } from '~/common/enums' +import { + ARTICLE_DIGEST_AUTHOR_SIDEBAR_ID_PREFIX, + TEST_ID, +} from '~/common/enums' import { capitalizeFirstLetter, toPath } from '~/common/utils' import { LinkWrapper, ResponsiveImage } from '~/components' import { UserDigest } from '~/components/UserDigest' @@ -14,6 +17,7 @@ import styles from './styles.module.css' export type ArticleDigestAuthorSidebarProps = { article: ArticleDigestAuthorSidebarArticleFragment collectionId?: string + cursor?: string titleTextSize?: ArticleDigestTitleTextSize titleColor?: 'greyDarker' | 'black' showCover?: boolean @@ -46,7 +50,7 @@ const fragments = { export const ArticleDigestAuthorSidebar = ({ article, collectionId, - + cursor, titleTextSize = 15, titleColor = 'greyDarker', imageSize = 'sm', @@ -66,6 +70,7 @@ export const ArticleDigestAuthorSidebar = ({ page: 'articleDetail', article, collectionId, + cursor, }) const headerClasses = classNames({ @@ -79,6 +84,7 @@ export const ArticleDigestAuthorSidebar = ({
@@ -87,6 +93,7 @@ export const ArticleDigestAuthorSidebar = ({ article={article} textSize={titleTextSize} collectionId={collectionId} + cursor={cursor} textWeight="normal" is="h3" /> diff --git a/src/components/ArticleDigest/Feed/index.tsx b/src/components/ArticleDigest/Feed/index.tsx index bc23c634a4..6208f405c2 100644 --- a/src/components/ArticleDigest/Feed/index.tsx +++ b/src/components/ArticleDigest/Feed/index.tsx @@ -37,6 +37,7 @@ export type ArticleDigestFeedProps = { Partial header?: React.ReactNode collectionId?: string + cursor?: string excludesTimeStamp?: boolean // this is only for timestamp next to the profile } & ArticleDigestFeedControls & FooterActionsProps @@ -45,7 +46,7 @@ const BaseArticleDigestFeed = ({ article, header, collectionId, - + cursor, hasHeader = true, hasCircle = true, hasAuthor = true, @@ -125,6 +126,7 @@ const BaseArticleDigestFeed = ({ { hasSetTopCollection={true} hasSetBottomCollection={true} collectionId={id} + cursor={cursor} collectionArticleCount={articles.totalCount} onSetTopCollection={() => setHasReset(true)} onSetBottomCollection={() => setHasReset(true)} diff --git a/src/views/User/CollectionDetail/CollectionArticles/index.tsx b/src/views/User/CollectionDetail/CollectionArticles/index.tsx index 258cd488d7..863b57208b 100644 --- a/src/views/User/CollectionDetail/CollectionArticles/index.tsx +++ b/src/views/User/CollectionDetail/CollectionArticles/index.tsx @@ -159,11 +159,12 @@ const CollectionArticles = ({ collection }: CollectionArticlesProps) => { {articleEdges && - articleEdges.map(({ node }, i) => ( + articleEdges.map(({ node, cursor }, i) => (