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';
|
2021-10-08 05:47:39 +02:00
|
|
|
import { parseURI } from 'util/lbryURI';
|
2020-10-28 20:18:58 +01:00
|
|
|
import ClaimPreview from 'component/claimPreview';
|
|
|
|
import Button from 'component/button';
|
|
|
|
import ClaimEffectiveAmount from 'component/claimEffectiveAmount';
|
2020-12-22 16:16:39 +01:00
|
|
|
import ClaimRepostAuthor from 'component/claimRepostAuthor';
|
2020-10-28 20:18:58 +01:00
|
|
|
import I18nMessage from 'component/i18nMessage';
|
2020-12-04 01:10:23 +01:00
|
|
|
import { useHistory } from 'react-router';
|
|
|
|
import LbcSymbol from 'component/common/lbc-symbol';
|
2021-12-05 04:20:24 +01:00
|
|
|
import { DOMAIN } from 'config';
|
2020-10-28 20:18:58 +01:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
query: string,
|
2020-12-16 19:31:07 +01:00
|
|
|
winningUri: ?string,
|
2020-10-28 20:18:58 +01:00
|
|
|
doResolveUris: (Array<string>) => void,
|
|
|
|
hideLink?: boolean,
|
2021-09-18 16:23:30 +02:00
|
|
|
setChannelActive: (boolean) => void,
|
2021-10-14 22:46:36 +02:00
|
|
|
beginPublish: (?string) => void,
|
2020-12-04 01:10:23 +01:00
|
|
|
pendingIds: Array<string>,
|
2020-12-16 19:31:07 +01:00
|
|
|
isResolvingWinningUri: boolean,
|
|
|
|
winningClaim: ?Claim,
|
2020-12-22 16:16:39 +01:00
|
|
|
isSearching: boolean,
|
2020-10-28 20:18:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default function SearchTopClaim(props: Props) {
|
2020-12-16 19:31:07 +01:00
|
|
|
const {
|
|
|
|
doResolveUris,
|
|
|
|
query = '',
|
|
|
|
winningUri,
|
|
|
|
winningClaim,
|
|
|
|
hideLink = false,
|
|
|
|
setChannelActive,
|
|
|
|
beginPublish,
|
|
|
|
isResolvingWinningUri,
|
2020-12-22 16:16:39 +01:00
|
|
|
isSearching,
|
2020-12-16 19:31:07 +01:00
|
|
|
} = props;
|
2020-10-28 20:18:58 +01:00
|
|
|
const uriFromQuery = `lbry://${query}`;
|
2020-12-04 01:10:23 +01:00
|
|
|
const { push } = useHistory();
|
|
|
|
let name;
|
2020-10-28 20:18:58 +01:00
|
|
|
let channelUriFromQuery;
|
2020-12-08 03:53:06 +01:00
|
|
|
let winningUriIsChannel;
|
2020-10-28 20:18:58 +01:00
|
|
|
try {
|
2020-12-04 01:10:23 +01:00
|
|
|
const { isChannel, streamName, channelName } = parseURI(uriFromQuery);
|
2020-10-28 20:18:58 +01:00
|
|
|
if (!isChannel) {
|
|
|
|
channelUriFromQuery = `lbry://@${query}`;
|
2020-12-04 01:10:23 +01:00
|
|
|
name = streamName;
|
|
|
|
} else {
|
|
|
|
name = channelName;
|
2020-10-28 20:18:58 +01:00
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
|
2021-10-14 22:46:36 +02:00
|
|
|
if (winningUri) {
|
|
|
|
try {
|
|
|
|
const { isChannel: winnerIsChannel } = parseURI(winningUri);
|
|
|
|
winningUriIsChannel = winnerIsChannel;
|
|
|
|
} 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]);
|
|
|
|
|
|
|
|
return (
|
2020-12-16 19:31:07 +01:00
|
|
|
<div className="search__header">
|
|
|
|
{winningUri && (
|
|
|
|
<div className="claim-preview__actions--header">
|
2021-12-05 04:20:24 +01:00
|
|
|
<a
|
|
|
|
className="media__uri"
|
|
|
|
href="https://lbry.com/faq/trending"
|
|
|
|
title={__('Learn more about LBRY Credits on %DOMAIN%', { DOMAIN })}
|
|
|
|
>
|
2020-12-16 19:31:07 +01:00
|
|
|
<LbcSymbol prefix={__('Most supported')} />
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
)}
|
2020-12-22 16:16:39 +01:00
|
|
|
{winningUri && winningClaim && (
|
2020-12-16 19:31:07 +01:00
|
|
|
<div className="card">
|
2021-09-20 23:06:55 +02:00
|
|
|
<ClaimPreview
|
|
|
|
hideRepostLabel
|
|
|
|
showNullPlaceholder
|
|
|
|
uri={winningUri}
|
|
|
|
properties={(claim) => (
|
|
|
|
<span className="claim-preview__custom-properties">
|
|
|
|
<ClaimRepostAuthor short uri={winningUri} />
|
|
|
|
<ClaimEffectiveAmount uri={winningUri} />
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
/>
|
2020-12-16 19:31:07 +01:00
|
|
|
</div>
|
|
|
|
)}
|
2020-12-22 16:16:39 +01:00
|
|
|
{!winningUri && (isSearching || isResolvingWinningUri) && (
|
|
|
|
<div className="card">
|
|
|
|
<ClaimPreview placeholder={'loading'} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{!winningUri && !isSearching && !isResolvingWinningUri && uriFromQuery && (
|
2020-12-16 19:31:07 +01:00
|
|
|
<div className="card card--section help--inline">
|
|
|
|
<I18nMessage
|
|
|
|
tokens={{
|
|
|
|
repost: (
|
2021-10-14 22:46:36 +02:00
|
|
|
<Button
|
|
|
|
button="link"
|
|
|
|
onClick={() => push(`/$/${PAGES.REPOST_NEW}${name ? `?to=${name}` : ''}`)}
|
|
|
|
label={__('Repost')}
|
|
|
|
/>
|
2020-12-16 19:31:07 +01:00
|
|
|
),
|
|
|
|
publish: (
|
|
|
|
<span>
|
2021-03-24 00:42:45 +01:00
|
|
|
<Button button="link" onClick={() => beginPublish(name)} label={__('publish')} />
|
2020-12-04 01:10:23 +01:00
|
|
|
</span>
|
2020-12-16 19:31:07 +01:00
|
|
|
),
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
You have found the edge of the internet. %repost% or %publish% your stuff here to claim this spot.
|
|
|
|
</I18nMessage>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{!hideLink && winningUri && (
|
|
|
|
<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>
|
|
|
|
)}
|
|
|
|
</div>
|
2020-10-28 20:18:58 +01:00
|
|
|
);
|
|
|
|
}
|