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

View file

@ -14,7 +14,7 @@ import * as SETTINGS from 'constants/settings';
import { selectCostInfoForUri, doFetchCostInfoForUri } from 'lbryinc'; import { selectCostInfoForUri, doFetchCostInfoForUri } from 'lbryinc';
import { selectShowMatureContent, selectClientSetting } from 'redux/selectors/settings'; import { selectShowMatureContent, selectClientSetting } from 'redux/selectors/settings';
import { makeSelectFileRenderModeForUri, makeSelectContentPositionForUri } from 'redux/selectors/content'; 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 { DISABLE_COMMENTS_TAG } from 'constants/tags';
import { getChannelIdFromClaim } from 'util/claim'; import { getChannelIdFromClaim } from 'util/claim';
@ -43,7 +43,7 @@ const select = (state, props) => {
hasCollectionById: Boolean(makeSelectCollectionForId(collectionId)(state)), hasCollectionById: Boolean(makeSelectCollectionForId(collectionId)(state)),
collectionId, collectionId,
position: makeSelectContentPositionForUri(uri)(state), 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 { import {
selectIsFetchingComments, selectIsFetchingComments,
selectCommentsForUri, selectCommentsForUri,
makeSelectTotalCommentsCountForUri, selectTotalCommentsCountForUri,
makeSelectTopLevelTotalPagesForUri, makeSelectTopLevelTotalPagesForUri,
} from 'redux/selectors/comments'; } from 'redux/selectors/comments';
import { selectClaimsById } from 'redux/selectors/claims'; import { selectClaimsById } from 'redux/selectors/claims';
@ -18,7 +18,7 @@ const select = (state) => {
return { return {
activeChannelClaim, activeChannelClaim,
allComments: selectCommentsForUri(state, uri), allComments: selectCommentsForUri(state, uri),
totalComments: makeSelectTotalCommentsCountForUri(uri)(state), totalComments: selectTotalCommentsCountForUri(state, uri),
topLevelTotalPages: makeSelectTopLevelTotalPagesForUri(uri)(state), topLevelTotalPages: makeSelectTopLevelTotalPagesForUri(uri)(state),
isFetchingComments: selectIsFetchingComments(state), isFetchingComments: selectIsFetchingComments(state),
claimsById: selectClaimsById(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 selectCommentIdsByClaimId = (state: State) => selectState(state).byId;
export const selectIsFetchingComments = (state: State) => selectState(state).isLoading; export const selectIsFetchingComments = (state: State) => selectState(state).isLoading;
export const selectIsFetchingCommentsById = (state: State) => selectState(state).isLoadingById; 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 selectIsFetchingReacts = (state: State) => selectState(state).isFetchingReacts;
export const selectMyReacts = (state: State) => state.comments.myReactsByCommentId; export const selectMyReacts = (state: State) => state.comments.myReactsByCommentId;
@ -338,17 +339,17 @@ export const makeSelectTotalReplyPagesForParentId = (parentId: string) =>
return state.repliesTotalPagesByParentId[parentId] || 0; return state.repliesTotalPagesByParentId[parentId] || 0;
}); });
export const makeSelectTotalCommentsCountForUri = (uri: string) => export const selectTotalCommentsCountForUri = (state: State, uri: string) => {
createSelector(selectState, selectCommentsByUri, (state, byUri) => { const commentIdsByUri = selectCommentsByUri(state);
const claimId = byUri[uri]; const totalCommentsById = selectTotalCommentsById(state);
const claimId = commentIdsByUri[uri];
return totalCommentsById[claimId] || 0;
};
return state.totalCommentsById[claimId] || 0; export const selectCommentsListTitleForUri = (state: State, uri: string) => {
}); const totalComments = selectTotalCommentsCountForUri(state, uri);
return getCommentsListTitle(totalComments);
export const makeSelectCommentsListTitleForUri = (uri: string) => };
createSelector(makeSelectTotalCommentsCountForUri(uri), (totalComments) => {
return getCommentsListTitle(totalComments);
});
// Personal list // Personal list
export const makeSelectChannelIsBlocked = (uri: string) => export const makeSelectChannelIsBlocked = (uri: string) =>