2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2019-06-11 20:10:58 +02:00
|
|
|
import * as ICONS from 'constants/icons';
|
2019-03-28 17:53:13 +01:00
|
|
|
import React, { useEffect, Fragment } from 'react';
|
2019-06-11 20:10:58 +02:00
|
|
|
import { isURIValid, normalizeURI } from 'lbry-redux';
|
2019-06-28 09:27:55 +02:00
|
|
|
import ClaimPreview from 'component/claimPreview';
|
2019-06-19 07:05:43 +02:00
|
|
|
import ClaimList from 'component/claimList';
|
2018-03-26 23:32:43 +02:00
|
|
|
import Page from 'component/page';
|
2019-02-18 18:24:56 +01:00
|
|
|
import SearchOptions from 'component/searchOptions';
|
2019-04-19 20:02:46 +02:00
|
|
|
import Button from 'component/button';
|
2017-05-05 10:01:16 +02:00
|
|
|
|
2019-06-11 20:10:58 +02:00
|
|
|
type Props = {
|
2019-06-20 02:57:51 +02:00
|
|
|
search: string => void,
|
2019-07-21 01:23:29 +02:00
|
|
|
isSearching: boolean,
|
2019-06-11 20:10:58 +02:00
|
|
|
location: UrlLocation,
|
|
|
|
uris: Array<string>,
|
|
|
|
onFeedbackNegative: string => void,
|
|
|
|
onFeedbackPositive: string => void,
|
|
|
|
};
|
2018-03-26 23:32:43 +02:00
|
|
|
|
2019-03-28 17:53:13 +01:00
|
|
|
export default function SearchPage(props: Props) {
|
2019-07-21 01:23:29 +02:00
|
|
|
const { search, uris, onFeedbackPositive, onFeedbackNegative, location, isSearching } = props;
|
2019-06-20 02:57:51 +02:00
|
|
|
const urlParams = new URLSearchParams(location.search);
|
2019-03-28 17:53:13 +01:00
|
|
|
const urlQuery = urlParams.get('q');
|
2019-04-04 23:05:23 +02:00
|
|
|
const isValid = isURIValid(urlQuery);
|
2019-04-15 06:07:23 +02:00
|
|
|
|
2019-04-04 23:05:23 +02:00
|
|
|
let uri;
|
|
|
|
if (isValid) {
|
|
|
|
uri = normalizeURI(urlQuery);
|
|
|
|
}
|
2019-03-28 17:53:13 +01:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (urlQuery) {
|
2019-06-20 02:57:51 +02:00
|
|
|
search(urlQuery);
|
2018-08-24 23:25:18 +02:00
|
|
|
}
|
2019-06-20 02:57:51 +02:00
|
|
|
}, [search, urlQuery]);
|
2019-03-28 17:53:13 +01:00
|
|
|
|
|
|
|
return (
|
2019-05-07 04:35:04 +02:00
|
|
|
<Page>
|
2019-04-04 23:05:23 +02:00
|
|
|
<section className="search">
|
|
|
|
{urlQuery && (
|
|
|
|
<Fragment>
|
2019-04-15 06:06:35 +02:00
|
|
|
{isValid && (
|
|
|
|
<header className="search__header">
|
2019-07-21 23:31:22 +02:00
|
|
|
<Button button="alt" navigate={uri} className="media__uri--large">
|
2019-04-19 20:02:46 +02:00
|
|
|
{uri}
|
|
|
|
</Button>
|
2019-07-21 23:31:22 +02:00
|
|
|
<div className="card">
|
|
|
|
<ClaimPreview uri={uri} type="large" placeholder="publish" />
|
|
|
|
</div>
|
2019-04-15 06:06:35 +02:00
|
|
|
</header>
|
|
|
|
)}
|
2019-04-04 23:05:23 +02:00
|
|
|
|
2019-06-11 20:10:58 +02:00
|
|
|
<div className="card">
|
2019-06-19 07:05:43 +02:00
|
|
|
<ClaimList
|
2019-06-11 20:10:58 +02:00
|
|
|
uris={uris}
|
2019-07-21 01:23:29 +02:00
|
|
|
loading={isSearching}
|
2019-06-11 20:10:58 +02:00
|
|
|
header={<SearchOptions />}
|
|
|
|
headerAltControls={
|
|
|
|
<Fragment>
|
|
|
|
<span>{__('Find what you were looking for?')}</span>
|
|
|
|
<Button
|
|
|
|
button="alt"
|
|
|
|
description={__('Yes')}
|
|
|
|
onClick={() => onFeedbackPositive(urlQuery)}
|
|
|
|
icon={ICONS.YES}
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
button="alt"
|
|
|
|
description={__('No')}
|
|
|
|
onClick={() => onFeedbackNegative(urlQuery)}
|
|
|
|
icon={ICONS.NO}
|
|
|
|
/>
|
|
|
|
</Fragment>
|
|
|
|
}
|
|
|
|
/>
|
2019-04-04 23:05:23 +02:00
|
|
|
</div>
|
2019-07-21 23:31:22 +02:00
|
|
|
<div className="help">{__('These search results are provided by LBRY, Inc.')}</div>
|
2019-04-04 23:05:23 +02:00
|
|
|
</Fragment>
|
|
|
|
)}
|
|
|
|
</section>
|
2019-03-28 17:53:13 +01:00
|
|
|
</Page>
|
|
|
|
);
|
2017-05-05 10:01:16 +02:00
|
|
|
}
|