2019-02-18 18:24:56 +01:00
|
|
|
// @flow
|
|
|
|
import * as ICONS from 'constants/icons';
|
2019-02-21 23:45:17 +01:00
|
|
|
import React from 'react';
|
2019-02-18 18:24:56 +01:00
|
|
|
import { SEARCH_OPTIONS } from 'lbry-redux';
|
|
|
|
import { Form, FormField } from 'component/common/form';
|
|
|
|
import posed from 'react-pose';
|
|
|
|
import Button from 'component/button';
|
|
|
|
|
|
|
|
const ExpandableOptions = posed.div({
|
|
|
|
hide: { height: 0, opacity: 0 },
|
2019-03-28 17:53:13 +01:00
|
|
|
show: { height: 300, opacity: 1 },
|
2019-02-18 18:24:56 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
setSearchOption: (string, boolean | string | number) => void,
|
|
|
|
options: {},
|
2019-02-21 23:45:17 +01:00
|
|
|
expanded: boolean,
|
|
|
|
toggleSearchExpanded: () => void,
|
|
|
|
query: string,
|
|
|
|
onFeedbackPositive: string => void,
|
|
|
|
onFeedbackNegative: string => void,
|
2019-02-18 18:24:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const SearchOptions = (props: Props) => {
|
2019-02-21 23:45:17 +01:00
|
|
|
const {
|
|
|
|
options,
|
|
|
|
setSearchOption,
|
|
|
|
expanded,
|
|
|
|
toggleSearchExpanded,
|
|
|
|
query,
|
|
|
|
onFeedbackPositive,
|
|
|
|
onFeedbackNegative,
|
|
|
|
} = props;
|
2019-02-18 18:24:56 +01:00
|
|
|
const resultCount = options[SEARCH_OPTIONS.RESULT_COUNT];
|
|
|
|
|
|
|
|
return (
|
2019-03-28 17:53:13 +01:00
|
|
|
<div className="search__options-wrapper">
|
2019-02-18 18:24:56 +01:00
|
|
|
<div className="card--space-between">
|
|
|
|
<Button
|
2019-02-21 23:45:17 +01:00
|
|
|
button="alt"
|
2019-03-28 17:53:13 +01:00
|
|
|
label={__('FILTER')}
|
2019-02-21 23:45:17 +01:00
|
|
|
iconRight={expanded ? ICONS.UP : ICONS.DOWN}
|
|
|
|
onClick={toggleSearchExpanded}
|
2019-02-18 18:24:56 +01:00
|
|
|
/>
|
2019-02-21 23:45:17 +01:00
|
|
|
|
|
|
|
<div className="media__action-group">
|
2019-02-18 18:24:56 +01:00
|
|
|
<span>{__('Find what you were looking for?')}</span>
|
2019-05-07 23:38:29 +02:00
|
|
|
<Button button="alt" description={__('Yes')} onClick={() => onFeedbackPositive(query)} icon={ICONS.YES} />
|
|
|
|
<Button button="alt" description={__('No')} onClick={() => onFeedbackNegative(query)} icon={ICONS.NO} />
|
2019-02-21 23:45:17 +01:00
|
|
|
</div>
|
2019-02-18 18:24:56 +01:00
|
|
|
</div>
|
|
|
|
<ExpandableOptions pose={expanded ? 'show' : 'hide'}>
|
|
|
|
{expanded && (
|
|
|
|
<Form className="card__content search__options">
|
|
|
|
<fieldset>
|
|
|
|
<legend className="search__legend--1">{__('Search For')}</legend>
|
|
|
|
{[
|
|
|
|
{
|
|
|
|
option: SEARCH_OPTIONS.INCLUDE_FILES,
|
|
|
|
label: __('Files'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
option: SEARCH_OPTIONS.INCLUDE_CHANNELS,
|
|
|
|
label: __('Channels'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
option: SEARCH_OPTIONS.INCLUDE_FILES_AND_CHANNELS,
|
|
|
|
label: __('Everything'),
|
|
|
|
},
|
|
|
|
].map(({ option, label }) => (
|
|
|
|
<FormField
|
|
|
|
key={option}
|
2019-02-20 06:20:29 +01:00
|
|
|
name={option}
|
2019-02-18 18:24:56 +01:00
|
|
|
type="radio"
|
|
|
|
blockWrap={false}
|
|
|
|
label={label}
|
|
|
|
checked={options[SEARCH_OPTIONS.CLAIM_TYPE] === option}
|
|
|
|
onChange={() => setSearchOption(SEARCH_OPTIONS.CLAIM_TYPE, option)}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</fieldset>
|
|
|
|
|
|
|
|
<fieldset>
|
|
|
|
<legend className="search__legend--2">{__('File Types')}</legend>
|
|
|
|
{[
|
|
|
|
{
|
|
|
|
option: SEARCH_OPTIONS.MEDIA_VIDEO,
|
|
|
|
label: __('Videos'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
option: SEARCH_OPTIONS.MEDIA_AUDIO,
|
2019-02-21 23:45:17 +01:00
|
|
|
label: __('Audio'),
|
2019-02-18 18:24:56 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
option: SEARCH_OPTIONS.MEDIA_IMAGE,
|
|
|
|
label: __('Images'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
option: SEARCH_OPTIONS.MEDIA_TEXT,
|
|
|
|
label: __('Text'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
option: SEARCH_OPTIONS.MEDIA_APPLICATION,
|
|
|
|
label: __('Other Files'),
|
|
|
|
},
|
|
|
|
].map(({ option, label }) => (
|
|
|
|
<FormField
|
|
|
|
key={option}
|
2019-02-20 06:20:29 +01:00
|
|
|
name={option}
|
2019-02-18 18:24:56 +01:00
|
|
|
type="checkbox"
|
|
|
|
blockWrap={false}
|
|
|
|
disabled={options[SEARCH_OPTIONS.CLAIM_TYPE] === SEARCH_OPTIONS.INCLUDE_CHANNELS}
|
|
|
|
label={label}
|
|
|
|
checked={options[option]}
|
|
|
|
onChange={() => setSearchOption(option, !options[option])}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</fieldset>
|
|
|
|
|
|
|
|
<fieldset>
|
|
|
|
<legend className="search__legend--3">{__('Other Options')}</legend>
|
|
|
|
<FormField
|
2019-02-21 23:45:17 +01:00
|
|
|
type="select"
|
2019-02-20 06:20:29 +01:00
|
|
|
name="result-count"
|
2019-02-18 18:24:56 +01:00
|
|
|
value={resultCount}
|
|
|
|
onChange={e => setSearchOption(SEARCH_OPTIONS.RESULT_COUNT, e.target.value)}
|
|
|
|
blockWrap={false}
|
|
|
|
label={__('Returned Results')}
|
2019-02-21 23:45:17 +01:00
|
|
|
>
|
|
|
|
<option value={10}>10</option>
|
|
|
|
<option value={30}>30</option>
|
|
|
|
<option value={50}>50</option>
|
|
|
|
<option value={100}>100</option>
|
|
|
|
</FormField>
|
2019-02-18 18:24:56 +01:00
|
|
|
</fieldset>
|
|
|
|
</Form>
|
|
|
|
)}
|
|
|
|
</ExpandableOptions>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SearchOptions;
|