fix null claim on reactions selector
This commit is contained in:
parent
b17acc0028
commit
eed4793799
1 changed files with 11 additions and 13 deletions
|
@ -2,24 +2,23 @@ import * as REACTION_TYPES from 'constants/reactions';
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
import { makeSelectClaimForUri } from 'lbry-redux';
|
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) => {
|
createSelector(makeSelectClaimForUri(uri), selectReactionsById, (claim, reactionsById) => {
|
||||||
return claim ? reactionsById[claim.claim_id] : {};
|
return claim ? reactionsById[claim.claim_id] : {};
|
||||||
});
|
});
|
||||||
|
|
||||||
export const makeSelectMyReactionForUri = uri =>
|
export const makeSelectMyReactionForUri = (uri) =>
|
||||||
createSelector(makeSelectClaimForUri(uri), makeSelectReactionsForUri(uri), (claim, reactions) => {
|
createSelector(makeSelectClaimForUri(uri), makeSelectReactionsForUri(uri), (claim, reactions) => {
|
||||||
const claimId = claim.claim_id;
|
if (!claim || !reactions || reactions.my_reactions === null) {
|
||||||
|
|
||||||
if (!reactions || reactions.my_reactions === null) {
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
const claimId = claim.claim_id;
|
||||||
|
|
||||||
const myReactions = reactions.my_reactions[claimId];
|
const myReactions = reactions.my_reactions[claimId];
|
||||||
if (myReactions[REACTION_TYPES.LIKE]) {
|
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) => {
|
createSelector(makeSelectClaimForUri(uri), makeSelectReactionsForUri(uri), (claim, reactions) => {
|
||||||
const claimId = claim.claim_id;
|
if (!claim || !reactions || reactions.my_reactions === null || reactions.others_reactions === null) {
|
||||||
|
|
||||||
if (!reactions || reactions.my_reactions === null || reactions.others_reactions === null) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
const claimId = claim.claim_id;
|
||||||
|
|
||||||
let count = 0;
|
let count = 0;
|
||||||
if (reactions.others_reactions) {
|
if (reactions.others_reactions) {
|
||||||
|
@ -54,7 +52,7 @@ export const makeSelectLikeCountForUri = uri =>
|
||||||
return count;
|
return count;
|
||||||
});
|
});
|
||||||
|
|
||||||
export const makeSelectDislikeCountForUri = uri =>
|
export const makeSelectDislikeCountForUri = (uri) =>
|
||||||
createSelector(makeSelectClaimForUri(uri), makeSelectReactionsForUri(uri), (claim, reactions) => {
|
createSelector(makeSelectClaimForUri(uri), makeSelectReactionsForUri(uri), (claim, reactions) => {
|
||||||
const claimId = claim.claim_id;
|
const claimId = claim.claim_id;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue