ClaimPreviewTile: restructure (no functional change)

Effects cannot be defined after the render function returns early, so it was not possible to add new effects when the derived variables that it depends on are way down below.
This commit is contained in:
infinite-persistence 2022-05-23 13:17:29 +08:00
parent 104dafc1e7
commit 287eb38e7a
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0

View file

@ -134,20 +134,10 @@ function ClaimPreviewTile(props: Props) {
const channelUri = !isChannel ? signingChannel && signingChannel.permanent_url : claim && claim.permanent_url;
const channelTitle = signingChannel && ((signingChannel.value && signingChannel.value.title) || signingChannel.name);
// Aria-label value for claim preview
let ariaLabelData = isChannel ? title : formatClaimPreviewTitle(title, channelTitle, date, mediaDuration);
const isChannelPage = window.location.pathname.startsWith('/@');
const shouldShowViewCount = !(!viewCount || (claim && claim.repost_url) || isLivestream || !isChannelPage);
function handleClick(e) {
if (navigateUrl) {
history.push(navigateUrl);
}
}
React.useEffect(() => {
if (isValid && !isResolvingUri && shouldFetch && uri) {
resolveUri(uri);
}
}, [isValid, isResolvingUri, uri, resolveUri, shouldFetch]);
const ariaLabelData = isChannel ? title : formatClaimPreviewTitle(title, channelTitle, date, mediaDuration);
let shouldHide = false;
@ -165,14 +155,31 @@ function ClaimPreviewTile(props: Props) {
if (onHidden && shouldHide) onHidden(props.uri);
}
// **************************************************************************
// **************************************************************************
function handleClick(e) {
if (navigateUrl) {
history.push(navigateUrl);
}
}
// **************************************************************************
// **************************************************************************
React.useEffect(() => {
if (isValid && !isResolvingUri && shouldFetch && uri) {
resolveUri(uri);
}
}, [isValid, isResolvingUri, uri, resolveUri, shouldFetch]);
// **************************************************************************
// **************************************************************************
if (shouldHide || (isLivestream && !showNoSourceClaims)) {
return null;
}
const isChannelPage = window.location.pathname.startsWith('/@');
const shouldShowViewCount = !(!viewCount || (claim && claim.repost_url) || isLivestream || !isChannelPage);
if (placeholder || (!claim && isResolvingUri)) {
return (
<li