fix null claim on reactions selector

This commit is contained in:
zeppi 2021-06-25 16:25:27 -04:00 committed by jessopb
parent b17acc0028
commit eed4793799

View file

@ -2,24 +2,23 @@ import * as REACTION_TYPES from 'constants/reactions';
import { createSelector } from 'reselect';
import { makeSelectClaimForUri } from 'lbry-redux';
const selectState = state => state.reactions || {};
const selectState = (state) => state.reactions || {};
export const selectReactionsById = createSelector(selectState, state => state.reactionsById);
export const selectReactionsById = createSelector(selectState, (state) => state.reactionsById);
export const selectFetchingReactions = createSelector(selectState, state => state.fetchingReactions);
export const selectFetchingReactions = createSelector(selectState, (state) => state.fetchingReactions);
export const makeSelectReactionsForUri = uri =>
export const makeSelectReactionsForUri = (uri) =>
createSelector(makeSelectClaimForUri(uri), selectReactionsById, (claim, reactionsById) => {
return claim ? reactionsById[claim.claim_id] : {};
});
export const makeSelectMyReactionForUri = uri =>
export const makeSelectMyReactionForUri = (uri) =>
createSelector(makeSelectClaimForUri(uri), makeSelectReactionsForUri(uri), (claim, reactions) => {
const claimId = claim.claim_id;
if (!reactions || reactions.my_reactions === null) {
if (!claim || !reactions || reactions.my_reactions === null) {
return undefined;
}
const claimId = claim.claim_id;
const myReactions = reactions.my_reactions[claimId];
if (myReactions[REACTION_TYPES.LIKE]) {
@ -32,13 +31,12 @@ export const makeSelectMyReactionForUri = uri =>
}
});
export const makeSelectLikeCountForUri = uri =>
export const makeSelectLikeCountForUri = (uri) =>
createSelector(makeSelectClaimForUri(uri), makeSelectReactionsForUri(uri), (claim, reactions) => {
const claimId = claim.claim_id;
if (!reactions || reactions.my_reactions === null || reactions.others_reactions === null) {
if (!claim || !reactions || reactions.my_reactions === null || reactions.others_reactions === null) {
return 0;
}
const claimId = claim.claim_id;
let count = 0;
if (reactions.others_reactions) {
@ -54,7 +52,7 @@ export const makeSelectLikeCountForUri = uri =>
return count;
});
export const makeSelectDislikeCountForUri = uri =>
export const makeSelectDislikeCountForUri = (uri) =>
createSelector(makeSelectClaimForUri(uri), makeSelectReactionsForUri(uri), (claim, reactions) => {
const claimId = claim.claim_id;