Skip to content

Commit

Permalink
Fix: 4485, 4484: added posts fields for ForumThread Query to reduce q…
Browse files Browse the repository at this point in the history
…ueries in ForumCategory page
  • Loading branch information
goldstarhigher committed Aug 30, 2023
1 parent ce70204 commit 9b1d6f1
Show file tree
Hide file tree
Showing 11 changed files with 347 additions and 14 deletions.
6 changes: 0 additions & 6 deletions packages/ui/src/app/pages/Forum/ForumCategory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import { PageTitle } from '@/common/components/page/PageTitle'
import { PreviousPage } from '@/common/components/page/PreviousPage'
import { Label, TextMedium } from '@/common/components/typography'
import { useModal } from '@/common/hooks/useModal'
import { useRefetchQueries } from '@/common/hooks/useRefetchQueries'
import { useSort } from '@/common/hooks/useSort'
import { MILLISECONDS_PER_BLOCK } from '@/common/model/formatters'
import { ForumCategoryList } from '@/forum/components/category/ForumCategoryList'
import { ForumPageHeader } from '@/forum/components/ForumPageHeader'
import { ThreadFilters } from '@/forum/components/threads/ThreadFilters'
Expand Down Expand Up @@ -48,10 +46,6 @@ export const ForumCategory = () => {
},
{ perPage: THREADS_PER_PAGE, page }
)
useRefetchQueries({
interval: MILLISECONDS_PER_BLOCK,
include: ['GetForumThreads', 'GetForumThreadsCount'],
})

const { showModal } = useModal()

Expand Down
24 changes: 24 additions & 0 deletions packages/ui/src/forum/components/ThreadCard/ThreadCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,30 @@ const forumThread: ForumThreadWithDetails = {
tags: [],
visiblePostsCount: 5,
status: { __typename: 'ThreadStatusActive' },
posts: [{
id: "1",
createdAt: "2023-06-28T19:14:00.000Z",
text: "Test text",
status: "PostStatusActive",
threadId: "459",
categoryId: "2",
author: {
id: "4129",
handle: "Codefikeyz",
rootAccount: "j4TZJCACAWao9bnh5k86qeRW2QhNVNkf9eEw1Vz4V8ZeqD4u4",
controllerAccount: "j4TZJCACAWao9bnh5k86qeRW2QhNVNkf9eEw1Vz4V8ZeqD4u4",
isCouncilMember: false,
isFoundingMember: true,
inviteCount: 1,
roles: [],
boundAccounts: [
"j4TZJCACAWao9bnh5k86qeRW2QhNVNkf9eEw1Vz4V8ZeqD4u4",
"j4WJoUb8xxQucAUFtmF18r41gzb1AG22nzypW1PT4LMLJqzU5"
],
isVerified: true,
createdAt:"2023-06-28T19:14:00.000Z",
}
}]
}

const Template: Story = (args) => <ThreadCard thread={{ ...forumThread, ...args }} />
Expand Down
7 changes: 4 additions & 3 deletions packages/ui/src/forum/components/threads/LatestActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { Loading } from '@/common/components/Loading'
import { RowGapBlock } from '@/common/components/page/PageContent'
import { TextInlineExtraSmall } from '@/common/components/typography'
import { relativeTime } from '@/common/model/relativeTime'
import { useThreadLatestPost } from '@/forum/hooks/useThreadLatestPost'
import { ForumPost } from '@/forum/types'
import { MemberInfo } from '@/memberships/components'

export interface LatestActivitydProps {
threadId: string
posts: ForumPost[]
}
export const LatestActivity = memo(({ threadId }: LatestActivitydProps) => {
const { post } = useThreadLatestPost(threadId)
export const LatestActivity = memo(({ /*threadId,*/ posts }: LatestActivitydProps) => {
const post = posts[0] // const { post } = useThreadLatestPost(threadId)

if (!post) return <Loading withoutMargin />

Expand Down
24 changes: 24 additions & 0 deletions packages/ui/src/forum/components/threads/ThreadList.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@ const forumThread: ForumThreadWithDetails = {
tags: [],
visiblePostsCount: 5,
status: { __typename: 'ThreadStatusActive' },
posts: [{
id: "1",
createdAt: "2023-06-28T19:14:00.000Z",
text: "Test text",
status: "PostStatusActive",
threadId: "459",
categoryId: "2",
author: {
id: "4129",
handle: "Codefikeyz",
rootAccount: "j4TZJCACAWao9bnh5k86qeRW2QhNVNkf9eEw1Vz4V8ZeqD4u4",
controllerAccount: "j4TZJCACAWao9bnh5k86qeRW2QhNVNkf9eEw1Vz4V8ZeqD4u4",
isCouncilMember: false,
isFoundingMember: true,
inviteCount: 1,
roles: [],
boundAccounts: [
"j4TZJCACAWao9bnh5k86qeRW2QhNVNkf9eEw1Vz4V8ZeqD4u4",
"j4WJoUb8xxQucAUFtmF18r41gzb1AG22nzypW1PT4LMLJqzU5"
],
isVerified: true,
createdAt:"2023-06-28T19:14:00.000Z",
}
}]
}

const Template: Story = ({ isArchive, type, initialPostText, categoryTitle, title }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const ThreadListItem = ({ thread, isArchive }: ThreadListItemProps) => {

<TextMedium bold>{thread.visiblePostsCount > 0 ? thread.visiblePostsCount - 1 : 0}</TextMedium>

<LatestActivity threadId={thread.id} />
<LatestActivity threadId={thread.id} posts={thread.posts} />

<MemberInfo member={thread.author} size="s" memberSize="s" hideGroup />

Expand Down
9 changes: 6 additions & 3 deletions packages/ui/src/forum/hooks/useForumCategoryThreads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Reducer, useEffect, useMemo, useReducer } from 'react'

import { ForumThreadOrderByInput } from '@/common/api/queries'
import { SortOrder, toQueryOrderByInput } from '@/common/hooks/useSort'
import { MILLISECONDS_PER_BLOCK } from '@/common/model/formatters'
import { merge } from '@/common/utils'
import { ThreadEmptyFilters, ThreadFiltersState } from '@/forum/components/threads/ThreadFilters'
import { useGetForumThreadsCountQuery, useGetForumThreadsQuery } from '@/forum/queries'
Expand Down Expand Up @@ -31,7 +32,7 @@ export const useForumCategoryThreads = (

const [{ filters, categoryId, isArchive }, refresh] = useReducer(threadOptionReducer, initialOptions)

const { loading: loadingThreads, data: threadsData } = useGetForumThreadsQuery({
const { data: threadsData } = useGetForumThreadsQuery({
variables: {
where: where(filters, categoryId, isArchive),
orderBy: [ForumThreadOrderByInput.IsStickyDesc, toQueryOrderByInput<ForumThreadOrderByInput>(options.order)],
Expand All @@ -42,15 +43,17 @@ export const useForumCategoryThreads = (
offset: (pagination.page - 1) * pagination.perPage,
}),
},
pollInterval: isArchive === false ? MILLISECONDS_PER_BLOCK : 0,
})

const { loading: loadingCount, data: countData } = useGetForumThreadsCountQuery({
const { data: countData } = useGetForumThreadsCountQuery({
variables: { where: where(filters, categoryId, isArchive) },
pollInterval: isArchive === false ? MILLISECONDS_PER_BLOCK : 0,
})
const totalCount = countData?.forumThreadsConnection.totalCount

return {
isLoading: loadingThreads || loadingCount,
isLoading: !threadsData || !countData,
threads: threadsData?.forumThreads.map((thread) => asForumThread(thread)) ?? [],
threadCount: totalCount,
refresh,
Expand Down
216 changes: 216 additions & 0 deletions packages/ui/src/forum/queries/__generated__/forum.generated.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9b1d6f1

Please sign in to comment.