lbry-desktop/src/ui/page/search/view.jsx

86 lines
2.4 KiB
React
Raw Normal View History

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';
import FileListItem from 'component/fileListItem';
import FileList from 'component/fileList';
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';
import Button from 'component/button';
2017-05-05 10:01:16 +02:00
2019-06-11 20:10:58 +02:00
type Props = {
doSearch: string => void,
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) {
const {
doSearch,
2019-06-11 20:10:58 +02:00
uris,
onFeedbackPositive,
onFeedbackNegative,
2019-03-28 17:53:13 +01:00
location: { search },
} = props;
2019-04-04 23:05:23 +02:00
const urlParams = new URLSearchParams(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) {
doSearch(urlQuery);
2018-08-24 23:25:18 +02:00
}
2019-05-07 04:35:04 +02:00
}, [doSearch, 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-05-13 08:37:34 +02:00
<Button button="alt" navigate={uri} className="media__uri">
{uri}
</Button>
2019-06-11 20:10:58 +02:00
<FileListItem uri={uri} large />
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">
<FileList
uris={uris}
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-06-11 20:10:58 +02:00
<div className="card__content 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
}