2019-02-18 18:24:56 +01:00
|
|
|
// @flow
|
2020-07-27 22:04:12 +02:00
|
|
|
import { SEARCH_OPTIONS } from 'constants/search';
|
2019-02-18 18:24:56 +01:00
|
|
|
import * as ICONS from 'constants/icons';
|
2021-02-16 17:59:16 +01:00
|
|
|
import React, { useMemo } from 'react';
|
2019-02-18 18:24:56 +01:00
|
|
|
import { Form, FormField } from 'component/common/form';
|
|
|
|
import Button from 'component/button';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
setSearchOption: (string, boolean | string | number) => void,
|
|
|
|
options: {},
|
2019-02-21 23:45:17 +01:00
|
|
|
expanded: boolean,
|
|
|
|
toggleSearchExpanded: () => void,
|
2019-02-18 18:24:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const SearchOptions = (props: Props) => {
|
2019-06-11 20:10:58 +02:00
|
|
|
const { options, setSearchOption, expanded, toggleSearchExpanded } = props;
|
2021-02-18 19:41:46 +01:00
|
|
|
const stringifiedOptions = JSON.stringify(options);
|
2019-02-18 18:24:56 +01:00
|
|
|
const resultCount = options[SEARCH_OPTIONS.RESULT_COUNT];
|
|
|
|
|
2021-02-16 17:59:16 +01:00
|
|
|
const isFilteringByChannel = useMemo(() => {
|
2021-02-18 19:41:46 +01:00
|
|
|
const jsonOptions = JSON.parse(stringifiedOptions);
|
|
|
|
const claimType = String(jsonOptions[SEARCH_OPTIONS.CLAIM_TYPE] || '');
|
2021-02-16 17:59:16 +01:00
|
|
|
return claimType.includes(SEARCH_OPTIONS.INCLUDE_CHANNELS);
|
2021-02-18 19:41:46 +01:00
|
|
|
}, [stringifiedOptions]);
|
2021-02-16 17:59:16 +01:00
|
|
|
|
2019-02-18 18:24:56 +01:00
|
|
|
return (
|
2019-06-11 20:10:58 +02:00
|
|
|
<div>
|
|
|
|
<Button
|
|
|
|
button="alt"
|
2019-06-28 09:33:07 +02:00
|
|
|
label={__('Filter')}
|
2019-06-11 20:10:58 +02:00
|
|
|
iconRight={expanded ? ICONS.UP : ICONS.DOWN}
|
|
|
|
onClick={toggleSearchExpanded}
|
|
|
|
/>
|
2019-09-26 18:07:11 +02:00
|
|
|
{expanded && (
|
|
|
|
<Form className="search__options">
|
2021-03-03 20:23:42 +01:00
|
|
|
{false && (
|
|
|
|
<fieldset>
|
|
|
|
{[
|
|
|
|
{
|
|
|
|
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}
|
|
|
|
name={option}
|
|
|
|
type="radio"
|
|
|
|
blockWrap={false}
|
|
|
|
label={label}
|
|
|
|
checked={options[SEARCH_OPTIONS.CLAIM_TYPE] === option}
|
|
|
|
onChange={() => setSearchOption(SEARCH_OPTIONS.CLAIM_TYPE, option)}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</fieldset>
|
|
|
|
)}
|
2019-02-18 18:24:56 +01:00
|
|
|
|
2021-02-16 17:59:16 +01:00
|
|
|
<fieldset disabled={isFilteringByChannel}>
|
2020-10-05 20:24:57 +02:00
|
|
|
<legend className="search__legend">{__('Type')}</legend>
|
2019-09-26 18:07:11 +02:00
|
|
|
{[
|
|
|
|
{
|
|
|
|
option: SEARCH_OPTIONS.MEDIA_VIDEO,
|
2020-10-05 20:24:57 +02:00
|
|
|
label: __('Video'),
|
2019-09-26 18:07:11 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
option: SEARCH_OPTIONS.MEDIA_AUDIO,
|
2021-03-03 20:23:42 +01:00
|
|
|
label: __('Music'),
|
2019-09-26 18:07:11 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
option: SEARCH_OPTIONS.MEDIA_IMAGE,
|
2020-10-05 20:24:57 +02:00
|
|
|
label: __('Image'),
|
2019-09-26 18:07:11 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
option: SEARCH_OPTIONS.MEDIA_TEXT,
|
|
|
|
label: __('Text'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
option: SEARCH_OPTIONS.MEDIA_APPLICATION,
|
2020-10-05 20:24:57 +02:00
|
|
|
label: __('Other'),
|
2019-09-26 18:07:11 +02:00
|
|
|
},
|
|
|
|
].map(({ option, label }) => (
|
2019-02-18 18:24:56 +01:00
|
|
|
<FormField
|
2019-09-26 18:07:11 +02:00
|
|
|
key={option}
|
|
|
|
name={option}
|
|
|
|
type="checkbox"
|
2019-02-18 18:24:56 +01:00
|
|
|
blockWrap={false}
|
2019-09-26 18:07:11 +02:00
|
|
|
disabled={options[SEARCH_OPTIONS.CLAIM_TYPE] === SEARCH_OPTIONS.INCLUDE_CHANNELS}
|
|
|
|
label={label}
|
2021-02-16 17:59:16 +01:00
|
|
|
checked={!isFilteringByChannel && options[option]}
|
2019-09-26 18:07:11 +02:00
|
|
|
onChange={() => setSearchOption(option, !options[option])}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</fieldset>
|
|
|
|
|
2021-03-03 20:23:42 +01:00
|
|
|
{false && (
|
|
|
|
<fieldset>
|
|
|
|
<legend className="search__legend">{__('Other Options')}</legend>
|
|
|
|
<FormField
|
|
|
|
type="select"
|
|
|
|
name="result-count"
|
|
|
|
value={resultCount}
|
|
|
|
onChange={(e) => setSearchOption(SEARCH_OPTIONS.RESULT_COUNT, e.target.value)}
|
|
|
|
blockWrap={false}
|
|
|
|
label={__('Returned Results')}
|
|
|
|
>
|
|
|
|
<option value={10}>10</option>
|
|
|
|
<option value={30}>30</option>
|
|
|
|
<option value={50}>50</option>
|
|
|
|
<option value={100}>100</option>
|
|
|
|
</FormField>
|
|
|
|
</fieldset>
|
|
|
|
)}
|
2019-09-26 18:07:11 +02:00
|
|
|
</Form>
|
|
|
|
)}
|
2019-02-18 18:24:56 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SearchOptions;
|