From e842a8c107195501c62d092e94732d0ab2bcae87 Mon Sep 17 00:00:00 2001 From: mkbeefcake Date: Tue, 10 Oct 2023 15:37:07 +0000 Subject: [PATCH] Fix 4484 : only using FetchPolicy at this moment --- packages/ui/src/forum/hooks/useCategoryLatestPost.ts | 7 +++++-- packages/ui/src/forum/hooks/useForumCategoryThreadCount.ts | 1 + packages/ui/src/forum/hooks/useForumPopularThreads.ts | 1 + packages/ui/src/forum/hooks/useThreadLatestPost.ts | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/ui/src/forum/hooks/useCategoryLatestPost.ts b/packages/ui/src/forum/hooks/useCategoryLatestPost.ts index 01145b746c..22a0e7398c 100644 --- a/packages/ui/src/forum/hooks/useCategoryLatestPost.ts +++ b/packages/ui/src/forum/hooks/useCategoryLatestPost.ts @@ -1,7 +1,8 @@ +import * as Apollo from '@apollo/client' import { useEffect } from 'react' import { ForumPostOrderByInput, ForumThreadOrderByInput } from '@/common/api/queries' -import { useGetForumPostsLazyQuery, useGetForumThreadsQuery } from '@/forum/queries' +import { GetForumPostsDocument, useGetForumThreadsQuery } from '@/forum/queries' import { asForumPost, asForumThread } from '@/forum/types' export const useCategoryLatestPost = (category_eq: string) => { @@ -25,7 +26,9 @@ export const useCategoryLatestPost = (category_eq: string) => { }) }, [threadData]) - const [fetchPost, { data: postData, loading: loadingPosts }] = useGetForumPostsLazyQuery() + const [fetchPost, { data: postData, loading: loadingPosts }] = Apollo.useLazyQuery(GetForumPostsDocument, { + fetchPolicy: 'cache-first', + }) const rawPost = postData?.forumPosts[0] return { diff --git a/packages/ui/src/forum/hooks/useForumCategoryThreadCount.ts b/packages/ui/src/forum/hooks/useForumCategoryThreadCount.ts index 9fcb3d1a27..dfdb2ab1b2 100644 --- a/packages/ui/src/forum/hooks/useForumCategoryThreadCount.ts +++ b/packages/ui/src/forum/hooks/useForumCategoryThreadCount.ts @@ -11,6 +11,7 @@ export const useForumCategoryThreadCount = (category_eq: string, isArchive?: boo } const { data } = useGetForumThreadsCountQuery({ variables: { where: { category: { id_eq: category_eq }, status_json } }, + fetchPolicy: 'cache-first', }) return { threadCount: data?.forumThreadsConnection.totalCount } } diff --git a/packages/ui/src/forum/hooks/useForumPopularThreads.ts b/packages/ui/src/forum/hooks/useForumPopularThreads.ts index 3594e6116c..4b2f127014 100644 --- a/packages/ui/src/forum/hooks/useForumPopularThreads.ts +++ b/packages/ui/src/forum/hooks/useForumPopularThreads.ts @@ -21,6 +21,7 @@ export const useForumPopularThreads = ({ categoryId, page = 1, threadsPerPage = offset: (page - 1) * threadsPerPage, limit: threadsPerPage, }, + fetchPolicy: 'cache-first', }) return { diff --git a/packages/ui/src/forum/hooks/useThreadLatestPost.ts b/packages/ui/src/forum/hooks/useThreadLatestPost.ts index 7d0b089dbc..ce8379a4aa 100644 --- a/packages/ui/src/forum/hooks/useThreadLatestPost.ts +++ b/packages/ui/src/forum/hooks/useThreadLatestPost.ts @@ -8,7 +8,7 @@ const orderBy = [ForumPostOrderByInput.UpdatedAtDesc] export const useThreadLatestPost = (threadId: string) => { const where = useMemo((): ForumPostWhereInput => ({ thread: { id_eq: threadId }, isVisible_eq: true }), [threadId]) - const { data } = useGetForumPostsQuery({ variables: { where, orderBy, limit: 1 } }) + const { data } = useGetForumPostsQuery({ variables: { where, orderBy, limit: 1 }, fetchPolicy: 'cache-first' }) const rawPost = data?.forumPosts[0] return { post: rawPost && asForumPost(rawPost) } }