2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2019-03-28 17:53:13 +01:00
|
|
|
import type { UrlLocation } from 'types/location';
|
2018-12-19 06:44:53 +01:00
|
|
|
import * as ICONS from 'constants/icons';
|
2019-03-28 17:53:13 +01:00
|
|
|
import React, { useEffect, Fragment } from 'react';
|
2018-08-24 23:25:18 +02:00
|
|
|
import { isURIValid, normalizeURI, parseURI } from 'lbry-redux';
|
2017-12-21 22:08:54 +01:00
|
|
|
import FileTile from 'component/fileTile';
|
2018-08-24 23:25:18 +02:00
|
|
|
import ChannelTile from 'component/channelTile';
|
2017-12-21 22:08:54 +01:00
|
|
|
import FileListSearch from 'component/fileListSearch';
|
2018-03-26 23:32:43 +02:00
|
|
|
import Page from 'component/page';
|
2018-08-27 20:47:55 +02:00
|
|
|
import ToolTip from 'component/common/tooltip';
|
|
|
|
import Icon from 'component/common/icon';
|
2019-02-18 18:24:56 +01:00
|
|
|
import SearchOptions from 'component/searchOptions';
|
2017-05-05 10:01:16 +02:00
|
|
|
|
2019-03-28 17:53:13 +01:00
|
|
|
type Props = { doSearch: string => void, location: UrlLocation };
|
2018-03-26 23:32:43 +02:00
|
|
|
|
2019-03-28 17:53:13 +01:00
|
|
|
export default function SearchPage(props: Props) {
|
|
|
|
const {
|
|
|
|
doSearch,
|
|
|
|
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:06:35 +02:00
|
|
|
console.log({ isValid });
|
|
|
|
console.log({ urlQuery });
|
2019-04-04 23:05:23 +02:00
|
|
|
let uri;
|
|
|
|
let isChannel;
|
|
|
|
let label;
|
|
|
|
if (isValid) {
|
|
|
|
uri = normalizeURI(urlQuery);
|
|
|
|
({ isChannel } = parseURI(uri));
|
|
|
|
}
|
2019-03-28 17:53:13 +01:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (urlQuery) {
|
|
|
|
doSearch(urlQuery);
|
2018-08-24 23:25:18 +02:00
|
|
|
}
|
2019-03-28 17:53:13 +01:00
|
|
|
}, [urlQuery]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Page noPadding>
|
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">
|
|
|
|
<h1 className="media__uri">{uri}</h1>
|
|
|
|
{isChannel ? (
|
|
|
|
<ChannelTile size="large" isSearchResult uri={uri} />
|
|
|
|
) : (
|
|
|
|
<FileTile size="large" isSearchResult displayHiddenMessage uri={uri} />
|
|
|
|
)}
|
|
|
|
</header>
|
|
|
|
)}
|
2019-04-04 23:05:23 +02:00
|
|
|
|
|
|
|
<div className="search__results-wrapper">
|
2019-04-15 06:06:35 +02:00
|
|
|
<SearchOptions />
|
|
|
|
|
2019-04-04 23:05:23 +02:00
|
|
|
<FileListSearch query={urlQuery} />
|
|
|
|
<div className="card__content help">
|
|
|
|
{__('These search results are provided by LBRY, Inc.')}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Fragment>
|
|
|
|
)}
|
|
|
|
</section>
|
2019-03-28 17:53:13 +01:00
|
|
|
</Page>
|
|
|
|
);
|
2017-05-05 10:01:16 +02:00
|
|
|
}
|