You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SpeakerStatsSearch.tsx 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import React, { useCallback, useState } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { withTheme } from 'react-native-paper';
  4. import { useDispatch, useSelector } from 'react-redux';
  5. import { IconSearch } from '../../../base/icons/svg';
  6. import Input from '../../../base/ui/components/native/Input';
  7. import { escapeRegexp } from '../../../base/util/helpers';
  8. import { initSearch } from '../../actions.native';
  9. import { isSpeakerStatsSearchDisabled } from '../../functions';
  10. import styles from './styles';
  11. /**
  12. * React component for display an individual user's speaker stats.
  13. *
  14. * @returns {React$Element<any>}
  15. */
  16. const SpeakerStatsSearch = () => {
  17. const { t } = useTranslation();
  18. const dispatch = useDispatch();
  19. const [ searchQuery, setSearchQuery ] = useState('');
  20. const onSearch = useCallback((criteria = '') => {
  21. dispatch(initSearch(escapeRegexp(criteria)));
  22. setSearchQuery(escapeRegexp(criteria));
  23. }, [ dispatch ]);
  24. const disableSpeakerStatsSearch = useSelector(isSpeakerStatsSearchDisabled);
  25. if (disableSpeakerStatsSearch) {
  26. return null;
  27. }
  28. return (
  29. <Input
  30. clearable = { true }
  31. customStyles = {{ container: styles.customContainer }}
  32. icon = { IconSearch }
  33. onChange = { onSearch }
  34. placeholder = { t('speakerStats.search') }
  35. value = { searchQuery } />
  36. );
  37. };
  38. export default withTheme(SpeakerStatsSearch);