From c326614cc8eeede9a26dc32bda835b2f603f0b87 Mon Sep 17 00:00:00 2001 From: bluecloud <96812901+pitb2022@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:29:08 +0800 Subject: [PATCH 1/6] fix(Writings): update fetch policy --- src/views/User/Writings/UserWritings.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/views/User/Writings/UserWritings.tsx b/src/views/User/Writings/UserWritings.tsx index cd4732b6d8..4c38fa3131 100644 --- a/src/views/User/Writings/UserWritings.tsx +++ b/src/views/User/Writings/UserWritings.tsx @@ -41,6 +41,7 @@ const UserWritings = () => { const { data, loading, error, fetchMore, client } = usePublicQuery(USER_WRITINGS_PUBLIC, { variables: { userName }, + fetchPolicy: 'network-only', }) // pagination From d969c3c7de77c5368271dd1643872bf691894acf Mon Sep 17 00:00:00 2001 From: bluecloud <96812901+pitb2022@users.noreply.github.com> Date: Thu, 22 Aug 2024 17:10:16 +0800 Subject: [PATCH 2/6] fix(Writings): Fetch the latest moment data --- src/views/User/Writings/UserWritings.tsx | 29 +++++++++++++++++++++--- src/views/User/Writings/gql.ts | 14 ++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/views/User/Writings/UserWritings.tsx b/src/views/User/Writings/UserWritings.tsx index 4c38fa3131..28b0fe5a84 100644 --- a/src/views/User/Writings/UserWritings.tsx +++ b/src/views/User/Writings/UserWritings.tsx @@ -23,7 +23,11 @@ import { import { UserWritingsPublicQuery } from '~/gql/graphql' import MomentForm from '../MomentForm' -import { USER_WRITINGS_PRIVATE, USER_WRITINGS_PUBLIC } from './gql' +import { + USER_MOMENTS, + USER_WRITINGS_PRIVATE, + USER_WRITINGS_PUBLIC, +} from './gql' import PinBoard from './PinBoard' import Placeholder from './Placeholder' @@ -41,7 +45,6 @@ const UserWritings = () => { const { data, loading, error, fetchMore, client } = usePublicQuery(USER_WRITINGS_PUBLIC, { variables: { userName }, - fetchPolicy: 'network-only', }) // pagination @@ -65,9 +68,29 @@ const UserWritings = () => { }) } - // fetch private data for first page + // fetch the latest moment data + const loadMomentData = (publicData?: UserWritingsPublicQuery) => { + if (!publicData || !user) { + return + } + + const publiceEdges = publicData.user?.writings?.edges || [] + const momentEdges = publiceEdges.filter( + ({ node }) => node.__typename === 'Moment' + ) + const publicIds = momentEdges.map(({ node }) => node.id) + + client.query({ + query: USER_MOMENTS, + fetchPolicy: 'network-only', + variables: { ids: publicIds }, + }) + } + + // fetch private and moment data for first page useEffect(() => { loadPrivate(data) + loadMomentData(data) }, [user?.id, viewer.id]) // load next page diff --git a/src/views/User/Writings/gql.ts b/src/views/User/Writings/gql.ts index f5c5993857..391246238c 100644 --- a/src/views/User/Writings/gql.ts +++ b/src/views/User/Writings/gql.ts @@ -90,3 +90,17 @@ export const USER_WRITINGS_PRIVATE = gql` ${ArticleDigestFeed.fragments.article.private} ${MomentDigestFeed.fragments.moment.private} ` + +export const USER_MOMENTS = gql` + query UserWritingsPrivate($ids: [ID!]!) { + nodes(input: { ids: $ids }) { + id + ... on Moment { + likeCount + commentCount + ...MomentDigestFeedMomentPrivate + } + } + } + ${MomentDigestFeed.fragments.moment.private} +` From 08813421ddb20ccec412052fe7ef93cdc9b7733e Mon Sep 17 00:00:00 2001 From: bluecloud <96812901+pitb2022@users.noreply.github.com> Date: Thu, 22 Aug 2024 17:15:15 +0800 Subject: [PATCH 3/6] Update gql.ts --- src/views/User/Writings/gql.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/User/Writings/gql.ts b/src/views/User/Writings/gql.ts index 391246238c..2e18392b17 100644 --- a/src/views/User/Writings/gql.ts +++ b/src/views/User/Writings/gql.ts @@ -92,7 +92,7 @@ export const USER_WRITINGS_PRIVATE = gql` ` export const USER_MOMENTS = gql` - query UserWritingsPrivate($ids: [ID!]!) { + query UserMoments($ids: [ID!]!) { nodes(input: { ids: $ids }) { id ... on Moment { From e9abd3b97055566f2b844a91a6e575240e2a9400 Mon Sep 17 00:00:00 2001 From: bluecloud <96812901+pitb2022@users.noreply.github.com> Date: Thu, 22 Aug 2024 17:20:33 +0800 Subject: [PATCH 4/6] fix(Writing): remove moment private data --- src/views/User/Writings/gql.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/views/User/Writings/gql.ts b/src/views/User/Writings/gql.ts index 2e18392b17..ff16406dd3 100644 --- a/src/views/User/Writings/gql.ts +++ b/src/views/User/Writings/gql.ts @@ -98,7 +98,6 @@ export const USER_MOMENTS = gql` ... on Moment { likeCount commentCount - ...MomentDigestFeedMomentPrivate } } } From c2a8f1a45ead834f1f92d66f438ce99a6cc7f6ab Mon Sep 17 00:00:00 2001 From: bluecloud <96812901+pitb2022@users.noreply.github.com> Date: Thu, 22 Aug 2024 17:24:44 +0800 Subject: [PATCH 5/6] Update gql.ts --- src/views/User/Writings/gql.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/views/User/Writings/gql.ts b/src/views/User/Writings/gql.ts index ff16406dd3..0c202a6c13 100644 --- a/src/views/User/Writings/gql.ts +++ b/src/views/User/Writings/gql.ts @@ -101,5 +101,4 @@ export const USER_MOMENTS = gql` } } } - ${MomentDigestFeed.fragments.moment.private} ` From 901a8aa4d997a46fa688377a7301d578a3a16137 Mon Sep 17 00:00:00 2001 From: bluecloud <96812901+pitb2022@users.noreply.github.com> Date: Fri, 23 Aug 2024 09:53:23 +0800 Subject: [PATCH 6/6] fix(Writings): update moment data fetching and reactive data query --- src/views/User/Writings/UserWritings.tsx | 8 ++++---- src/views/User/Writings/gql.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/views/User/Writings/UserWritings.tsx b/src/views/User/Writings/UserWritings.tsx index 28b0fe5a84..fbb7ff1987 100644 --- a/src/views/User/Writings/UserWritings.tsx +++ b/src/views/User/Writings/UserWritings.tsx @@ -24,7 +24,7 @@ import { UserWritingsPublicQuery } from '~/gql/graphql' import MomentForm from '../MomentForm' import { - USER_MOMENTS, + USER_MOMENTS_REACTIVE_DATA, USER_WRITINGS_PRIVATE, USER_WRITINGS_PUBLIC, } from './gql' @@ -69,7 +69,7 @@ const UserWritings = () => { } // fetch the latest moment data - const loadMomentData = (publicData?: UserWritingsPublicQuery) => { + const loadMomentReactiveData = (publicData?: UserWritingsPublicQuery) => { if (!publicData || !user) { return } @@ -81,7 +81,7 @@ const UserWritings = () => { const publicIds = momentEdges.map(({ node }) => node.id) client.query({ - query: USER_MOMENTS, + query: USER_MOMENTS_REACTIVE_DATA, fetchPolicy: 'network-only', variables: { ids: publicIds }, }) @@ -90,7 +90,7 @@ const UserWritings = () => { // fetch private and moment data for first page useEffect(() => { loadPrivate(data) - loadMomentData(data) + loadMomentReactiveData(data) }, [user?.id, viewer.id]) // load next page diff --git a/src/views/User/Writings/gql.ts b/src/views/User/Writings/gql.ts index 0c202a6c13..24c841a41a 100644 --- a/src/views/User/Writings/gql.ts +++ b/src/views/User/Writings/gql.ts @@ -91,8 +91,8 @@ export const USER_WRITINGS_PRIVATE = gql` ${MomentDigestFeed.fragments.moment.private} ` -export const USER_MOMENTS = gql` - query UserMoments($ids: [ID!]!) { +export const USER_MOMENTS_REACTIVE_DATA = gql` + query UserMomentsReactiveData($ids: [ID!]!) { nodes(input: { ids: $ids }) { id ... on Moment {