// @flow import React from 'react'; import ClaimList from 'component/claimList'; import Page from 'component/page'; import * as PAGES from 'constants/pages'; import { useHistory } from 'react-router-dom'; import CollectionEdit from 'component/collectionEdit'; import Card from 'component/common/card'; import CollectionActions from 'component/collectionActions'; import classnames from 'classnames'; import ClaimAuthor from 'component/claimAuthor'; import FileDescription from 'component/fileDescription'; import { COLLECTIONS_CONSTS } from 'lbry-redux'; import Icon from 'component/common/icon'; import * as ICONS from 'constants/icons'; import Spinner from 'component/spinner'; export const PAGE_VIEW_QUERY = 'view'; export const EDIT_PAGE = 'edit'; type Props = { collectionId: string, uri: string, claim: Claim, title: string, thumbnail: string, collection: Collection, collectionUrls: Array, collectionCount: number, isResolvingCollection: boolean, isMyClaim: boolean, isMyCollection: boolean, claimIsPending: boolean, collectionHasEdits: boolean, deleteCollection: (string) => void, editCollection: (string, CollectionEditParams) => void, fetchCollectionItems: (string, () => void) => void, resolveUris: (string) => void, user: ?User, }; export default function CollectionPage(props: Props) { const { collectionId, uri, claim, collection, collectionUrls, collectionCount, collectionHasEdits, claimIsPending, isResolvingCollection, fetchCollectionItems, } = props; const { replace, location: { search }, } = useHistory(); const [didTryResolve, setDidTryResolve] = React.useState(false); const [showInfo, setShowInfo] = React.useState(false); const { name, totalItems } = collection || {}; const isBuiltin = COLLECTIONS_CONSTS.BUILTIN_LISTS.includes(collectionId); const urlParams = new URLSearchParams(search); const editing = urlParams.get(PAGE_VIEW_QUERY) === EDIT_PAGE; const urlsReady = collectionUrls && (totalItems === undefined || (totalItems && totalItems === collectionUrls.length)); const shouldFetch = !claim && !collection; React.useEffect(() => { if (collectionId && !urlsReady && !didTryResolve && shouldFetch) { fetchCollectionItems(collectionId, () => setDidTryResolve(true)); } }, [collectionId, urlsReady, didTryResolve, shouldFetch, setDidTryResolve, fetchCollectionItems]); const pending = (
{__('Your publish is being confirmed and will be live soon')}
); const unpublished = {__('Unpublished Edit')}; let titleActions; if (collectionHasEdits) { titleActions = unpublished; } else if (claimIsPending) { titleActions = pending; } const subTitle = (
{uri ? {collectionCount} items : {collectionCount} items} {uri && }
); const info = ( {claim ? claim.value.title || claim.name : collection && collection.name} {collectionHasEdits && (*)} } titleActions={titleActions} subtitle={subTitle} body={ !isBuiltin && ( ) } actions={ showInfo && uri && (
) } /> ); if (!collection && (isResolvingCollection || !didTryResolve)) { return (

{__('Loading...')}

); } if (!collection && !isResolvingCollection && didTryResolve) { return (

{__('Nothing here')}

); } if (editing) { return ( { replace(`/$/${PAGES.LIST}/${id}`); }} /> ); } if (urlsReady) { return (
{info}
); } }