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

90 lines
2.7 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
2018-11-26 02:21:25 +01:00
import * as SETTINGS from 'constants/settings';
import * as ICONS from 'constants/icons';
2018-03-26 23:32:43 +02:00
import * as React 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';
2017-05-05 10:01:16 +02:00
2018-03-26 23:32:43 +02:00
type Props = {
query: ?string,
resultCount: number,
setClientSetting: (string, number | boolean) => void,
2018-03-26 23:32:43 +02:00
};
class SearchPage extends React.PureComponent<Props> {
constructor() {
super();
(this: any).onShowUnavailableChange = this.onShowUnavailableChange.bind(this);
(this: any).onSearchResultCountChange = this.onSearchResultCountChange.bind(this);
}
onSearchResultCountChange(event: SyntheticInputEvent<*>) {
2018-06-22 21:18:08 +02:00
const count = Number(event.target.value);
2018-11-26 02:21:25 +01:00
this.props.setClientSetting(SETTINGS.RESULT_COUNT, count);
}
onShowUnavailableChange(event: SyntheticInputEvent<*>) {
2018-11-26 02:21:25 +01:00
this.props.setClientSetting(SETTINGS.SHOW_UNAVAILABLE, event.target.checked);
}
2018-03-26 23:32:43 +02:00
render() {
const { query, resultCount } = this.props;
2018-08-24 23:25:18 +02:00
const isValid = isURIValid(query);
let uri;
let isChannel;
if (isValid) {
uri = normalizeURI(query);
({ isChannel } = parseURI(uri));
}
return (
2018-08-14 05:52:09 +02:00
<Page noPadding>
<section className="search">
2019-02-13 17:27:20 +01:00
{query &&
isValid && (
<header className="search__header">
<h1 className="search__title">
{`lbry://${query}`}
<ToolTip
icon
body={__(
'This is the resolution of a LBRY URL and not controlled by LBRY Inc.'
)}
>
<Icon icon={ICONS.HELP} />
</ToolTip>
</h1>
{isChannel ? (
2019-02-15 02:52:10 +01:00
<ChannelTile size="large" isSearchResult uri={uri} />
2019-02-13 17:27:20 +01:00
) : (
2019-02-15 02:52:10 +01:00
<FileTile size="large" isSearchResult displayHiddenMessage uri={uri} />
2019-02-13 17:27:20 +01:00
)}
</header>
)}
2019-02-15 02:52:10 +01:00
{/*
Commented out until I figure out what to do with it in my next PR
<div>
<FormField type="text" value={resultCount} label={__("Returned results")} /
</div>
*/}
<div className="search__results-wrapper">
<FileListSearch query={query} />
<div className="help">{__('These search results are provided by LBRY, Inc.')}</div>
</div>
</section>
2018-03-26 23:32:43 +02:00
</Page>
2017-06-06 23:19:12 +02:00
);
}
2017-05-05 10:01:16 +02:00
}
2018-03-26 23:32:43 +02:00
2017-05-05 10:01:16 +02:00
export default SearchPage;