// @flow import { ENABLE_NO_SOURCE_CLAIMS } from 'config'; import * as PAGES from 'constants/pages'; import React, { useEffect } from 'react'; import { Redirect, useHistory } from 'react-router-dom'; import Spinner from 'component/spinner'; import ChannelPage from 'page/channel'; import Page from 'component/page'; import Button from 'component/button'; import Card from 'component/common/card'; import { formatLbryUrlForWeb } from 'util/url'; import { parseURI } from 'util/lbryURI'; import * as COLLECTIONS_CONSTS from 'constants/collections'; import AbandonedChannelPreview from 'component/abandonedChannelPreview'; import FilePage from 'page/file'; import LivestreamPage from 'page/livestream'; import Yrbl from 'component/yrbl'; type Props = { isResolvingUri: boolean, resolveUri: (string) => void, isSubscribed: boolean, uri: string, claim: StreamClaim, location: UrlLocation, blackListedOutpoints: Array<{ txid: string, nout: number, }>, title: string, claimIsMine: boolean, claimIsPending: boolean, isLivestream: boolean, beginPublish: (?string) => void, collectionId: string, collection: Collection, collectionUrls: Array, isResolvingCollection: boolean, fetchCollectionItems: (string) => void, }; function ShowPage(props: Props) { const { isResolvingUri, resolveUri, uri, claim, blackListedOutpoints, location, claimIsMine, isSubscribed, claimIsPending, isLivestream, beginPublish, fetchCollectionItems, collectionId, collection, collectionUrls, isResolvingCollection, } = props; const { search } = location; const signingChannel = claim && claim.signing_channel; const canonicalUrl = claim && claim.canonical_url; const claimExists = claim !== null && claim !== undefined; const haventFetchedYet = claim === undefined; const isMine = claim && claim.is_my_output; const { contentName, isChannel } = parseURI(uri); // deprecated contentName - use streamName and channelName const { push } = useHistory(); const isCollection = claim && claim.value_type === 'collection'; const resolvedCollection = collection && collection.id; // not null // changed this from 'isCollection' to resolve strangers' collections. React.useEffect(() => { if (collectionId && !resolvedCollection) { fetchCollectionItems(collectionId); } }, [isCollection, resolvedCollection, collectionId, fetchCollectionItems]); useEffect(() => { if ( (resolveUri && !isResolvingUri && uri && haventFetchedYet) || (claimExists && !claimIsPending && (!canonicalUrl || isMine === undefined)) ) { resolveUri(uri); } }, [resolveUri, isResolvingUri, canonicalUrl, uri, claimExists, haventFetchedYet, isMine, claimIsPending, search]); // Don't navigate directly to repost urls // Always redirect to the actual content // Also need to add repost_url to the Claim type for flow // $FlowFixMe if (claim && claim.repost_url === uri) { const newUrl = formatLbryUrlForWeb(claim.canonical_url); return ; } let urlForCollectionZero; if (claim && claim.value_type === 'collection' && collectionUrls && collectionUrls.length) { urlForCollectionZero = collectionUrls && collectionUrls[0]; const claimId = claim.claim_id; const urlParams = new URLSearchParams(search); urlParams.set(COLLECTIONS_CONSTS.COLLECTION_ID, claimId); const newUrl = formatLbryUrlForWeb(`${urlForCollectionZero}?${urlParams.toString()}`); return ; } let innerContent = ''; if (!claim || (claim && !claim.name)) { innerContent = ( {(claim === undefined || isResolvingUri || isResolvingCollection || // added for collection (claim && claim.value_type === 'collection' && !urlForCollectionZero)) && ( // added for collection - make sure we accept urls = []
)} {!isResolvingUri && !isSubscribed && (
) } /> )} {!isResolvingUri && isSubscribed && claim === null && }
); } else if (claim.name.length && claim.name[0] === '@') { innerContent = ; } else if (claim) { let isClaimBlackListed = false; isClaimBlackListed = blackListedOutpoints && blackListedOutpoints.some( (outpoint) => (signingChannel && outpoint.txid === signingChannel.txid && outpoint.nout === signingChannel.nout) || (outpoint.txid === claim.txid && outpoint.nout === claim.nout) ); if (isClaimBlackListed && !claimIsMine) { innerContent = (