ClaimPreviewTile: fix render violations and onHidden
logic
## Issues - Not safe to call the parent callback from the render function. It must be called from an effect or - `onHidden` is only called when blacklisted, but it can also be hidden from other circumstances. - While those other circumstances doesn't apply for FYP (the first client that relies on `onHidden`, it's incorrect from a code perspective, unless it is renamed to `onBlacklisted`. ## Change - Move the callback execution into an effect. - Ensure `onHidden` is for all situations that it is hidden.
This commit is contained in:
parent
cde0c0b2a8
commit
8c06dab10f
1 changed files with 18 additions and 8 deletions
|
@ -145,14 +145,18 @@ function ClaimPreviewTile(props: Props) {
|
|||
// Unfortunately needed until this is resolved
|
||||
// https://github.com/lbryio/lbry-sdk/issues/2785
|
||||
shouldHide = true;
|
||||
} else {
|
||||
}
|
||||
|
||||
if (!shouldHide && !placeholder) {
|
||||
shouldHide =
|
||||
!placeholder &&
|
||||
(banState.blacklisted ||
|
||||
banState.filtered ||
|
||||
(!showHiddenByUser && (banState.muted || banState.blocked)) ||
|
||||
(isAbandoned && !showUnresolvedClaims));
|
||||
if (onHidden && shouldHide) onHidden(props.uri);
|
||||
banState.blacklisted ||
|
||||
banState.filtered ||
|
||||
(!showHiddenByUser && (banState.muted || banState.blocked)) ||
|
||||
(isAbandoned && !showUnresolvedClaims);
|
||||
}
|
||||
|
||||
if (!shouldHide) {
|
||||
shouldHide = isLivestream && !showNoSourceClaims;
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
|
@ -173,10 +177,16 @@ function ClaimPreviewTile(props: Props) {
|
|||
}
|
||||
}, [isValid, isResolvingUri, uri, resolveUri, shouldFetch]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (onHidden && shouldHide) {
|
||||
onHidden(props.uri);
|
||||
}
|
||||
}, [shouldHide, onHidden, props.uri]);
|
||||
|
||||
// **************************************************************************
|
||||
// **************************************************************************
|
||||
|
||||
if (shouldHide || (isLivestream && !showNoSourceClaims)) {
|
||||
if (shouldHide) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue