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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. accessibilityLabel = { t('speakerStats.searchHint') }
  31. clearable = { true }
  32. customStyles = {{ container: styles.customContainer }}
  33. icon = { IconSearch }
  34. onChange = { onSearch }
  35. placeholder = { t('speakerStats.search') }
  36. value = { searchQuery } />
  37. );
  38. };
  39. export default withTheme(SpeakerStatsSearch);