diff --git a/src/components/posts/LatestPostsPage.tsx b/src/components/posts/LatestPostsPage.tsx index 097cc60f8..1db82abf7 100644 --- a/src/components/posts/LatestPostsPage.tsx +++ b/src/components/posts/LatestPostsPage.tsx @@ -5,6 +5,7 @@ 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 { setPostScores } from 'src/rtk/features/posts/postScoreSlice' import { fetchPosts } from 'src/rtk/features/posts/postsSlice' import { DataSourceTypes, PostId } from 'src/types' import { PostKind } from 'src/types/graphql-global-types' @@ -48,6 +49,11 @@ export const loadMorePostsFn = async (loadMoreValues: LoadMoreValues value.persistentPostId) + dispatch( + setPostScores( + posts.data.map(({ persistentPostId, score }) => ({ id: persistentPostId, score })), + ), + ) } else if (!isSuggested(filter.type) && client) { const data = await loadPostsByQuery({ client, kind, offset, filter }) const { posts } = data as GetLatestPostIds diff --git a/src/components/posts/view-post/ViewRegularPreview.tsx b/src/components/posts/view-post/ViewRegularPreview.tsx index 5f28c8abf..7ab9e3a63 100644 --- a/src/components/posts/view-post/ViewRegularPreview.tsx +++ b/src/components/posts/view-post/ViewRegularPreview.tsx @@ -1,5 +1,7 @@ import { FC, useState } from 'react' import { CommentSection } from 'src/components/comments/CommentsSection' +import { useAppSelector } from 'src/rtk/app/store' +import { selectPostScore } from 'src/rtk/features/posts/postScoreSlice' import { SpaceData } from 'src/types' import { InfoPostPreview, PostActionsPanel, PostNotFound } from './helpers' import { PreviewProps } from './PostPreview' @@ -17,6 +19,8 @@ export const RegularPreview: ComponentType = props => { const { isSharedPost } = postDetails.post.struct + const score = useAppSelector(state => selectPostScore(state, postDetails.post.id)) + return !isSharedPost ? ( <> { withTags={withTags} withMarginForCardType={!withActions} /> + {score?.score} {withActions && ( diff --git a/src/rtk/features/posts/postScoreSlice.ts b/src/rtk/features/posts/postScoreSlice.ts new file mode 100644 index 000000000..2e779723e --- /dev/null +++ b/src/rtk/features/posts/postScoreSlice.ts @@ -0,0 +1,27 @@ +import { createEntityAdapter, createSlice } from '@reduxjs/toolkit' +import { RootState } from 'src/rtk/app/rootReducer' + +// TODO: remove this slice when score is not needed to be displayed anymore +export type PostScore = { + id: string + score: number +} + +const sliceName = 'postScore' + +const adapter = createEntityAdapter() +const selectors = adapter.getSelectors(state => state.postScores) + +export const selectPostScore = selectors.selectById + +const slice = createSlice({ + name: sliceName, + initialState: adapter.getInitialState(), + reducers: { + setPostScores: adapter.upsertMany, + }, +}) + +export const { setPostScores } = slice.actions + +export default slice.reducer