Fix selectCommentIdsForUri

- memo not required.
- start to not use the confusing and wrongly-named 'selectCommentsByUri' (per comment from Sean);  use the existing 'selectClaimIdForUri' instead.  This works because currently we do fetch any comments without first visiting a claim/uri, so we'll always have fetched the required claim, and can be queried in 'selectClaimIdForUri'.
This commit is contained in:
infinite-persistence 2021-11-09 23:32:16 +08:00
parent 81d77da17e
commit d211450b5b
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
2 changed files with 10 additions and 9 deletions

View file

@ -15,7 +15,7 @@ import {
makeSelectTotalCommentsCountForUri, makeSelectTotalCommentsCountForUri,
selectOthersReacts, selectOthersReacts,
selectMyReacts, selectMyReacts,
makeSelectCommentIdsForUri, selectCommentIdsForUri,
selectSettingsByChannelId, selectSettingsByChannelId,
selectPinnedCommentsForUri, selectPinnedCommentsForUri,
} from 'redux/selectors/comments'; } from 'redux/selectors/comments';
@ -36,7 +36,7 @@ const select = (state, props) => {
topLevelComments, topLevelComments,
resolvedComments, resolvedComments,
myChannelIds: selectMyClaimIdsRaw(state), myChannelIds: selectMyClaimIdsRaw(state),
allCommentIds: makeSelectCommentIdsForUri(props.uri)(state), allCommentIds: selectCommentIdsForUri(state, props.uri),
pinnedComments: selectPinnedCommentsForUri(state, props.uri), pinnedComments: selectPinnedCommentsForUri(state, props.uri),
topLevelTotalPages: makeSelectTopLevelTotalPagesForUri(props.uri)(state), topLevelTotalPages: makeSelectTopLevelTotalPagesForUri(props.uri)(state),
totalComments: makeSelectTotalCommentsCountForUri(props.uri)(state), totalComments: makeSelectTotalCommentsCountForUri(props.uri)(state),

View file

@ -4,14 +4,15 @@ import { createCachedSelector } from 're-reselect';
import { selectMutedChannels } from 'redux/selectors/blocked'; import { selectMutedChannels } from 'redux/selectors/blocked';
import { selectShowMatureContent } from 'redux/selectors/settings'; import { selectShowMatureContent } from 'redux/selectors/settings';
import { selectBlacklistedOutpointMap, selectFilteredOutpointMap } from 'lbryinc'; import { selectBlacklistedOutpointMap, selectFilteredOutpointMap } from 'lbryinc';
import { selectClaimsById, selectMyClaimIdsRaw } from 'redux/selectors/claims'; import { selectClaimsById, selectMyClaimIdsRaw, selectClaimIdForUri } from 'redux/selectors/claims';
import { isClaimNsfw } from 'util/claim'; import { isClaimNsfw } from 'util/claim';
type State = { comments: CommentsState }; type State = { claims: any, comments: CommentsState };
const selectState = (state) => state.comments || {}; const selectState = (state) => state.comments || {};
export const selectCommentsById = (state: State) => selectState(state).commentById || {}; export const selectCommentsById = (state: State) => selectState(state).commentById || {};
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;
export const selectIsFetchingCommentsByParentId = (state: State) => selectState(state).isLoadingByParentId; export const selectIsFetchingCommentsByParentId = (state: State) => selectState(state).isLoadingByParentId;
@ -172,11 +173,11 @@ export const selectRepliesByParentId = createSelector(selectState, selectComment
export const selectLinkedCommentAncestors = (state: State) => selectState(state).linkedCommentAncestors; export const selectLinkedCommentAncestors = (state: State) => selectState(state).linkedCommentAncestors;
export const makeSelectCommentIdsForUri = (uri: string) => export const selectCommentIdsForUri = (state: State, uri: string) => {
createSelector(selectState, selectCommentsByUri, selectClaimsById, (state, byUri) => { const claimId = selectClaimIdForUri(state, uri);
const claimId = byUri[uri]; const commentIdsByClaimId = selectCommentIdsByClaimId(state);
return state.byId[claimId]; return commentIdsByClaimId[claimId];
}); };
const filterCommentsDepOnList = { const filterCommentsDepOnList = {
claimsById: selectClaimsById, claimsById: selectClaimsById,