2020-10-28 20:18:58 +01:00
|
|
|
// @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 HelpLink from 'component/common/help-link';
|
|
|
|
import I18nMessage from 'component/i18nMessage';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
query: string,
|
|
|
|
winningUri: ?Claim,
|
|
|
|
doResolveUris: (Array<string>) => void,
|
|
|
|
hideLink?: boolean,
|
2020-12-08 03:53:06 +01:00
|
|
|
setChannelActive: boolean => void,
|
2020-10-28 20:18:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default function SearchTopClaim(props: Props) {
|
2020-12-08 03:53:06 +01:00
|
|
|
const { doResolveUris, query = '', winningUri, hideLink = false, setChannelActive } = props;
|
2020-10-28 20:18:58 +01:00
|
|
|
const uriFromQuery = `lbry://${query}`;
|
|
|
|
|
|
|
|
let channelUriFromQuery;
|
2020-12-08 03:53:06 +01:00
|
|
|
let winningUriIsChannel;
|
2020-10-28 20:18:58 +01:00
|
|
|
try {
|
|
|
|
const { isChannel } = parseURI(uriFromQuery);
|
2020-12-08 03:53:06 +01:00
|
|
|
const { isChannel: winnerIsChannel } = parseURI(winningUri);
|
|
|
|
winningUriIsChannel = winnerIsChannel;
|
2020-10-28 20:18:58 +01:00
|
|
|
if (!isChannel) {
|
|
|
|
channelUriFromQuery = `lbry://@${query}`;
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
|
2020-12-08 03:53:06 +01:00
|
|
|
React.useEffect(() => {
|
|
|
|
setChannelActive && winningUriIsChannel && setChannelActive(true);
|
|
|
|
}, [setChannelActive, winningUriIsChannel]);
|
|
|
|
|
2020-10-28 20:18:58 +01:00
|
|
|
React.useEffect(() => {
|
|
|
|
let urisToResolve = [];
|
|
|
|
if (uriFromQuery) {
|
|
|
|
urisToResolve.push(uriFromQuery);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channelUriFromQuery) {
|
|
|
|
urisToResolve.push(channelUriFromQuery);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (urisToResolve.length > 0) {
|
|
|
|
doResolveUris(urisToResolve);
|
|
|
|
}
|
|
|
|
}, [doResolveUris, uriFromQuery, channelUriFromQuery]);
|
|
|
|
|
|
|
|
if (!winningUri) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<section className="search">
|
|
|
|
<header className="search__header">
|
|
|
|
<div className="claim-preview__actions--header">
|
|
|
|
<span className="media__uri">
|
|
|
|
{__('Most supported')}
|
|
|
|
<HelpLink href="https://lbry.com/faq/tipping" />
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div className="card">
|
|
|
|
<ClaimPreview
|
|
|
|
hideRepostLabel
|
|
|
|
uri={winningUri}
|
|
|
|
type="large"
|
|
|
|
placeholder="publish"
|
|
|
|
properties={claim => (
|
|
|
|
<span className="claim-preview__custom-properties">
|
|
|
|
<ClaimEffectiveAmount uri={winningUri} />
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{!hideLink && (
|
|
|
|
<div className="section__actions--between section__actions--no-margin">
|
|
|
|
<span />
|
|
|
|
<Button
|
|
|
|
button="link"
|
|
|
|
className="search__top-link"
|
|
|
|
label={
|
|
|
|
<I18nMessage tokens={{ name: <strong>{query}</strong> }}>View competing uploads for %name%</I18nMessage>
|
|
|
|
}
|
|
|
|
navigate={`/$/${PAGES.TOP}?name=${query}`}
|
|
|
|
iconRight={ICONS.ARROW_RIGHT}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</header>
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|