2022-11-08 15:46:46 +00:00
|
|
|
import React, { useCallback, useState } from 'react';
|
2021-12-28 14:35:21 +00:00
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { withTheme } from 'react-native-paper';
|
2022-11-08 15:46:46 +00:00
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
2021-12-28 14:35:21 +00:00
|
|
|
|
2022-11-08 15:46:46 +00:00
|
|
|
import { IconSearch } from '../../../base/icons';
|
|
|
|
import Input from '../../../base/ui/components/native/Input';
|
|
|
|
import { escapeRegexp } from '../../../base/util';
|
|
|
|
import { initSearch } from '../../actions';
|
2021-12-28 14:35:21 +00:00
|
|
|
import { isSpeakerStatsSearchDisabled } from '../../functions';
|
|
|
|
|
|
|
|
import styles from './styles';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* React component for display an individual user's speaker stats.
|
|
|
|
*
|
|
|
|
* @returns {React$Element<any>}
|
|
|
|
*/
|
2022-11-08 15:46:46 +00:00
|
|
|
const SpeakerStatsSearch = () => {
|
2021-12-28 14:35:21 +00:00
|
|
|
const { t } = useTranslation();
|
2022-11-08 15:46:46 +00:00
|
|
|
const dispatch = useDispatch();
|
|
|
|
const [ searchQuery, setSearchQuery ] = useState('');
|
|
|
|
|
|
|
|
const onSearch = useCallback((criteria = '') => {
|
|
|
|
dispatch(initSearch(escapeRegexp(criteria)));
|
|
|
|
setSearchQuery(escapeRegexp(criteria));
|
|
|
|
}, [ dispatch ]);
|
|
|
|
|
2021-12-28 14:35:21 +00:00
|
|
|
|
|
|
|
const disableSpeakerStatsSearch = useSelector(isSpeakerStatsSearchDisabled);
|
|
|
|
|
|
|
|
if (disableSpeakerStatsSearch) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-11-08 15:46:46 +00:00
|
|
|
<Input
|
|
|
|
clearable = { true }
|
|
|
|
customStyles = {{ container: styles.customContainer }}
|
|
|
|
icon = { IconSearch }
|
2021-12-28 14:35:21 +00:00
|
|
|
onChange = { onSearch }
|
|
|
|
placeholder = { t('speakerStats.search') }
|
2022-11-08 15:46:46 +00:00
|
|
|
value = { searchQuery } />
|
2021-12-28 14:35:21 +00:00
|
|
|
);
|
2022-11-08 15:46:46 +00:00
|
|
|
};
|
2021-12-28 14:35:21 +00:00
|
|
|
|
|
|
|
export default withTheme(SpeakerStatsSearch);
|