Fix total comment count selector

- Move away from `makeSelect*`. This selector doesn't need caching since there is no transformation.
This commit is contained in:
infinite-persistence 2022-03-11 12:11:01 +08:00
parent 6b77cb2bfa
commit f7b598a6e0
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
4 changed files with 19 additions and 17 deletions

View file

@ -1,5 +1,6 @@
import { connect } from 'react-redux';
import { selectClaimForUri,
import {
selectClaimForUri,
selectClaimIsMine,
selectFetchingMyChannels,
selectClaimsByUri,
@ -10,7 +11,7 @@ import {
selectIsFetchingComments,
selectIsFetchingCommentsById,
selectIsFetchingReacts,
makeSelectTotalCommentsCountForUri,
selectTotalCommentsCountForUri,
selectOthersReacts,
selectMyReacts,
selectCommentIdsForUri,
@ -34,7 +35,7 @@ const select = (state, props) => {
allCommentIds: selectCommentIdsForUri(state, uri),
pinnedComments: selectPinnedCommentsForUri(state, uri),
topLevelTotalPages: makeSelectTopLevelTotalPagesForUri(uri)(state),
totalComments: makeSelectTotalCommentsCountForUri(uri)(state),
totalComments: selectTotalCommentsCountForUri(state, uri),
claimId: claim && claim.claim_id,
channelId: getChannelIdFromClaim(claim),
claimIsMine: selectClaimIsMine(state, claim),

View file

@ -14,7 +14,7 @@ import * as SETTINGS from 'constants/settings';
import { selectCostInfoForUri, doFetchCostInfoForUri } from 'lbryinc';
import { selectShowMatureContent, selectClientSetting } from 'redux/selectors/settings';
import { makeSelectFileRenderModeForUri, makeSelectContentPositionForUri } from 'redux/selectors/content';
import { makeSelectCommentsListTitleForUri, selectSettingsByChannelId } from 'redux/selectors/comments';
import { selectCommentsListTitleForUri, selectSettingsByChannelId } from 'redux/selectors/comments';
import { DISABLE_COMMENTS_TAG } from 'constants/tags';
import { getChannelIdFromClaim } from 'util/claim';
@ -43,7 +43,7 @@ const select = (state, props) => {
hasCollectionById: Boolean(makeSelectCollectionForId(collectionId)(state)),
collectionId,
position: makeSelectContentPositionForUri(uri)(state),
commentsListTitle: makeSelectCommentsListTitleForUri(uri)(state),
commentsListTitle: selectCommentsListTitleForUri(state, uri),
};
};

View file

@ -4,7 +4,7 @@ import { selectActiveChannelClaim } from 'redux/selectors/app';
import {
selectIsFetchingComments,
selectCommentsForUri,
makeSelectTotalCommentsCountForUri,
selectTotalCommentsCountForUri,
makeSelectTopLevelTotalPagesForUri,
} from 'redux/selectors/comments';
import { selectClaimsById } from 'redux/selectors/claims';
@ -18,7 +18,7 @@ const select = (state) => {
return {
activeChannelClaim,
allComments: selectCommentsForUri(state, uri),
totalComments: makeSelectTotalCommentsCountForUri(uri)(state),
totalComments: selectTotalCommentsCountForUri(state, uri),
topLevelTotalPages: makeSelectTopLevelTotalPagesForUri(uri)(state),
isFetchingComments: selectIsFetchingComments(state),
claimsById: selectClaimsById(state),

View file

@ -24,6 +24,7 @@ export const selectCommentsById = (state: State) => selectState(state).commentBy
export const selectCommentIdsByClaimId = (state: State) => selectState(state).byId;
export const selectIsFetchingComments = (state: State) => selectState(state).isLoading;
export const selectIsFetchingCommentsById = (state: State) => selectState(state).isLoadingById;
const selectTotalCommentsById = (state: State) => selectState(state).totalCommentsById;
export const selectIsFetchingReacts = (state: State) => selectState(state).isFetchingReacts;
export const selectMyReacts = (state: State) => state.comments.myReactsByCommentId;
@ -338,17 +339,17 @@ export const makeSelectTotalReplyPagesForParentId = (parentId: string) =>
return state.repliesTotalPagesByParentId[parentId] || 0;
});
export const makeSelectTotalCommentsCountForUri = (uri: string) =>
createSelector(selectState, selectCommentsByUri, (state, byUri) => {
const claimId = byUri[uri];
export const selectTotalCommentsCountForUri = (state: State, uri: string) => {
const commentIdsByUri = selectCommentsByUri(state);
const totalCommentsById = selectTotalCommentsById(state);
const claimId = commentIdsByUri[uri];
return totalCommentsById[claimId] || 0;
};
return state.totalCommentsById[claimId] || 0;
});
export const makeSelectCommentsListTitleForUri = (uri: string) =>
createSelector(makeSelectTotalCommentsCountForUri(uri), (totalComments) => {
export const selectCommentsListTitleForUri = (state: State, uri: string) => {
const totalComments = selectTotalCommentsCountForUri(state, uri);
return getCommentsListTitle(totalComments);
});
};
// Personal list
export const makeSelectChannelIsBlocked = (uri: string) =>