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:
infinite-persistence 2022-05-23 13:39:32 +08:00
parent cde0c0b2a8
commit 8c06dab10f
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0

View file

@ -145,14 +145,18 @@ function ClaimPreviewTile(props: Props) {
// Unfortunately needed until this is resolved // Unfortunately needed until this is resolved
// https://github.com/lbryio/lbry-sdk/issues/2785 // https://github.com/lbryio/lbry-sdk/issues/2785
shouldHide = true; shouldHide = true;
} else { }
if (!shouldHide && !placeholder) {
shouldHide = shouldHide =
!placeholder && banState.blacklisted ||
(banState.blacklisted || banState.filtered ||
banState.filtered || (!showHiddenByUser && (banState.muted || banState.blocked)) ||
(!showHiddenByUser && (banState.muted || banState.blocked)) || (isAbandoned && !showUnresolvedClaims);
(isAbandoned && !showUnresolvedClaims)); }
if (onHidden && shouldHide) onHidden(props.uri);
if (!shouldHide) {
shouldHide = isLivestream && !showNoSourceClaims;
} }
// ************************************************************************** // **************************************************************************
@ -173,10 +177,16 @@ function ClaimPreviewTile(props: Props) {
} }
}, [isValid, isResolvingUri, uri, resolveUri, shouldFetch]); }, [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; return null;
} }