diff --git a/src/components/main/HomePageFilters.tsx b/src/components/main/HomePageFilters.tsx index 01d471c4a..2bdb0d2cf 100644 --- a/src/components/main/HomePageFilters.tsx +++ b/src/components/main/HomePageFilters.tsx @@ -31,6 +31,7 @@ const commonFilterOption = [{ label: 'Latest', value: 'latest' }] export const postFilterOpt = [ { label: 'Featured Posts', value: 'suggested' }, { label: 'All Posts', value: 'latest' }, + { label: 'Hot Posts', value: 'hot' }, // removed most liked and commented // ...offchainPostFilterOpt, ] diff --git a/src/components/main/types.ts b/src/components/main/types.ts index 194f743f6..971499734 100644 --- a/src/components/main/types.ts +++ b/src/components/main/types.ts @@ -4,7 +4,7 @@ import { Dispatch } from 'react' import { AccountId } from 'src/types' import { PostKind } from '../../types/graphql-global-types' -export type PostFilterType = 'latest' | 'suggested' +export type PostFilterType = 'latest' | 'suggested' | 'hot' // | 'liked' | 'commented' // removed most liked and commented export type SpaceFilterType = 'suggested' | 'creators' diff --git a/src/components/main/utils.ts b/src/components/main/utils.ts index 341d24334..e1f2ba92e 100644 --- a/src/components/main/utils.ts +++ b/src/components/main/utils.ts @@ -37,6 +37,12 @@ const getPostsByFilter: GetEntityFilter = { month: q.GET_LATEST_POST_IDS, allTime: q.GET_LATEST_POST_IDS, }, + hot: { + day: q.GET_LATEST_POST_IDS, + week: q.GET_LATEST_POST_IDS, + month: q.GET_LATEST_POST_IDS, + allTime: q.GET_LATEST_POST_IDS, + }, // removed most liked and commented // liked: { // day: q.GET_MOST_LIKED_POST_IDS_IN_DATE_RANGE, diff --git a/src/components/posts/LatestPostsPage.tsx b/src/components/posts/LatestPostsPage.tsx index 485ddc455..b248500cc 100644 --- a/src/components/posts/LatestPostsPage.tsx +++ b/src/components/posts/LatestPostsPage.tsx @@ -2,6 +2,7 @@ import { FC, useCallback, useEffect, useState } from 'react' import { useDispatch } from 'react-redux' import { useSubsocialApi } from 'src/components/substrate/SubstrateContext' import config from 'src/config' +import { DEFAULT_PAGE_SIZE } from 'src/config/ListData.config' import { useDfApolloClient } from 'src/graphql/ApolloProvider' import { GetLatestPostIds } from 'src/graphql/__generated__/GetLatestPostIds' import { fetchPosts } from 'src/rtk/features/posts/postsSlice' @@ -13,6 +14,7 @@ import { InnerLoadMoreFn } from '../lists' import { InfinitePageList } from '../lists/InfiniteList' import { DateFilterType, LoadMoreValues, PostFilterType } from '../main/types' import { isSuggested, loadPostsByQuery } from '../main/utils' +import { getHotPosts } from '../utils/datahub/posts' import { getSuggestedPostIdsByPage, loadSuggestedPostIds } from './loadSuggestedPostIdsFromEnv' import { PublicPostPreviewById } from './PublicPostPreview' @@ -44,10 +46,15 @@ export const loadMorePostsFn = async (loadMoreValues: LoadMoreValues value.id) + } else if (filter.type === 'hot') { + console.log('hot fetchingg...') + const posts = await getHotPosts({ offset, limit: DEFAULT_PAGE_SIZE }) + postIds = posts.data.map(value => value.persistentPostId) } else { const allSuggestedPotsIds = await loadSuggestedPostIds({ subsocial, client }) postIds = getSuggestedPostIdsByPage(allSuggestedPotsIds, size, page) @@ -76,15 +83,15 @@ const InfiniteListOfPublicPosts = (props: Props) => { useSubsocialEffect( ({ subsocial }) => { - if (config.enableSquidDataSource || !isSuggested(filter)) return - loadSuggestedPostIds({ subsocial }).then(ids => setTotalCount(ids.length)) + if (!config.enableSquidDataSource && isSuggested(filter)) + loadSuggestedPostIds({ subsocial }).then(ids => setTotalCount(ids.length)) }, [filter], ) useEffect(() => { - if (!config.enableSquidDataSource || !isSuggested(filter)) return - loadSuggestedPostIds({ client }).then(ids => setTotalCount(ids.length)) + if (config.enableSquidDataSource && isSuggested(filter)) + loadSuggestedPostIds({ client }).then(ids => setTotalCount(ids.length)) }, [filter]) const entity = kind === PostKind.RegularPost ? 'posts' : 'comments'