// @flow import * as ICONS from 'constants/icons'; import * as PAGES from 'constants/pages'; import React from 'react'; import { parseURI } from 'lbry-redux'; import ClaimPreview from 'component/claimPreview'; import Button from 'component/button'; import ClaimEffectiveAmount from 'component/claimEffectiveAmount'; import ClaimRepostAuthor from 'component/claimRepostAuthor'; import I18nMessage from 'component/i18nMessage'; import { useHistory } from 'react-router'; import LbcSymbol from 'component/common/lbc-symbol'; import { DOMAIN } from 'config'; type Props = { query: string, winningUri: ?string, doResolveUris: (Array) => void, hideLink?: boolean, setChannelActive: (boolean) => void, beginPublish: (string) => void, pendingIds: Array, isResolvingWinningUri: boolean, winningClaim: ?Claim, isSearching: boolean, preferEmbed: boolean, }; export default function SearchTopClaim(props: Props) { const { doResolveUris, query = '', winningUri, winningClaim, hideLink = false, setChannelActive, beginPublish, isResolvingWinningUri, isSearching, preferEmbed, } = props; const uriFromQuery = `lbry://${query}`; const { push } = useHistory(); let name; let channelUriFromQuery; let winningUriIsChannel; try { const { isChannel, streamName, channelName } = parseURI(uriFromQuery); const { isChannel: winnerIsChannel } = parseURI(winningUri); winningUriIsChannel = winnerIsChannel; if (!isChannel) { channelUriFromQuery = `lbry://@${query}`; name = streamName; } else { name = channelName; } } catch (e) {} React.useEffect(() => { setChannelActive && winningUriIsChannel && setChannelActive(true); }, [setChannelActive, winningUriIsChannel]); React.useEffect(() => { let urisToResolve = []; if (uriFromQuery) { urisToResolve.push(uriFromQuery); } if (channelUriFromQuery) { urisToResolve.push(channelUriFromQuery); } if (urisToResolve.length > 0) { doResolveUris(urisToResolve); } }, [doResolveUris, uriFromQuery, channelUriFromQuery]); return (
{winningUri && (
)} {winningUri && winningClaim && (
{preferEmbed && ( ( )} /> )}
)} {!winningUri && (isSearching || isResolvingWinningUri) && (
)} {!winningUri && !isSearching && !isResolvingWinningUri && uriFromQuery && (
push(`/$/${PAGES.REPOST_NEW}?to=${name}`)} label={__('Repost')} /> ), publish: (
)} {!hideLink && winningUri && (
)}
); }