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

92 lines
2.8 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import * as React from 'react';
import * as settings from 'constants/settings';
2018-08-24 23:25:18 +02:00
import { isURIValid, normalizeURI, parseURI } from 'lbry-redux';
import { FormField, FormRow } from 'component/common/form';
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';
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);
this.props.setClientSetting(settings.RESULT_COUNT, count);
}
onShowUnavailableChange(event: SyntheticInputEvent<*>) {
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>
{query &&
2018-08-24 23:25:18 +02:00
isValid && (
2018-08-14 05:52:09 +02:00
<div className="search__top">
<div className="file-list__header">{`lbry://${query}`}</div>
2018-08-24 23:25:18 +02:00
{isChannel ? (
<ChannelTile size="large" uri={uri} />
) : (
<FileTile size="large" displayHiddenMessage uri={uri} />
)}
2018-08-14 05:52:09 +02:00
</div>
)}
<div className="search__content">
<FormRow alignRight>
<FormField
type="number"
name="result_count"
2018-06-22 21:18:08 +02:00
min={10}
max={1000}
value={resultCount}
onChange={this.onSearchResultCountChange}
postfix={__('returned results')}
/>
{
// Removing this for now, it currently doesn't do anything but ideally it would
// display content that we don't think is currently available to download
// It is like a "display all" setting
// <FormField
// type="checkbox"
// name="show_unavailable"
// onChange={this.onShowUnavailableChange}
// checked={showUnavailable}
// postfix={__('Include unavailable content')}
// />
}
</FormRow>
2018-08-14 05:52:09 +02:00
<FileListSearch query={query} />
<div className="help">{__('These search results are provided by LBRY, Inc.')}</div>
</div>
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;