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

98 lines
3 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
2019-03-28 17:53:13 +01:00
import type { UrlLocation } from 'types/location';
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';
import FileTile from 'component/fileTile';
2018-08-24 23:25:18 +02:00
import ChannelTile from 'component/channelTile';
import FileListSearch from 'component/fileListSearch';
2018-03-26 23:32:43 +02:00
import Page from 'component/page';
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';
2019-03-28 17:53:13 +01:00
import { Location } from '@reach/router';
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;
2018-08-24 23:25:18 +02:00
2019-03-28 17:53:13 +01:00
const urlParams = new URLSearchParams(location.search);
const urlQuery = urlParams.get('q');
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>
<Location>
{(locationProps: {
location: {
search: string,
},
}) => {
const { location } = locationProps;
const urlParams = new URLSearchParams(location.search);
const query = urlParams.get('q');
const isValid = isURIValid(query);
let uri;
let isChannel;
let label;
if (isValid) {
uri = normalizeURI(query);
({ isChannel } = parseURI(uri));
// label = (
// <Fragment>
// {`lbry://${query}`}
// <ToolTip
// icon
// body={__('This is the resolution of a LBRY URL and not controlled by LBRY Inc.')}
// >
// <Icon icon={ICONS.HELP} />
// </ToolTip>
// </Fragment>
// );
}
2018-08-24 23:25:18 +02:00
2019-03-28 17:53:13 +01:00
return (
<section className="search">
{query && (
<Fragment>
<header className="search__header">
{isValid && (
<Fragment>
<SearchOptions />
<h1 className="media__uri">{uri}</h1>
{isChannel ? (
<ChannelTile size="large" isSearchResult uri={uri} />
) : (
<FileTile size="large" isSearchResult displayHiddenMessage uri={uri} />
)}
</Fragment>
)}
</header>
<div className="search__results-wrapper">
<FileListSearch query={query} />
<div className="card__content help">
{__('These search results are provided by LBRY, Inc.')}
</div>
</div>
</Fragment>
2019-03-05 05:46:57 +01:00
)}
2019-03-28 17:53:13 +01:00
</section>
);
}}
</Location>
</Page>
);
2017-05-05 10:01:16 +02:00
}