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.

GifsMenu.tsx 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { GiphyContent, GiphyGridView, GiphyMediaType, GiphyRating } from '@giphy/react-native-sdk';
  2. import React, { useCallback, useState } from 'react';
  3. import { useTranslation } from 'react-i18next';
  4. import { useDispatch, useSelector } from 'react-redux';
  5. import { createGifSentEvent } from '../../../analytics/AnalyticsEvents';
  6. import { sendAnalytics } from '../../../analytics/functions';
  7. import JitsiScreen from '../../../base/modal/components/JitsiScreen';
  8. import Input from '../../../base/ui/components/native/Input';
  9. import { sendMessage } from '../../../chat/actions.any';
  10. import { goBack } from '../../../mobile/navigation/components/conference/ConferenceNavigationContainerRef';
  11. import { formatGifUrlMessage, getGifRating, getGifUrl } from '../../functions.native';
  12. import GifsMenuFooter from './GifsMenuFooter';
  13. import styles from './styles';
  14. const GifsMenu = () => {
  15. const [ searchQuery, setSearchQuery ] = useState('');
  16. const dispatch = useDispatch();
  17. const { t } = useTranslation();
  18. const rating = useSelector(getGifRating) as GiphyRating;
  19. const options = {
  20. mediaType: GiphyMediaType.Gif,
  21. limit: 20,
  22. rating
  23. };
  24. const content = searchQuery === ''
  25. ? GiphyContent.trending(options)
  26. : GiphyContent.search({
  27. ...options,
  28. searchQuery
  29. });
  30. const sendGif = useCallback(e => {
  31. const url = getGifUrl(e.nativeEvent.media);
  32. sendAnalytics(createGifSentEvent());
  33. dispatch(sendMessage(formatGifUrlMessage(url), true));
  34. goBack();
  35. }, []);
  36. return (
  37. <JitsiScreen
  38. footerComponent = { GifsMenuFooter }
  39. style = { styles.container }>
  40. <Input
  41. clearable = { true }
  42. customStyles = {{ container: styles.customContainer }}
  43. onChange = { setSearchQuery }
  44. placeholder = { t('giphy.search') }
  45. value = { searchQuery } />
  46. <GiphyGridView
  47. cellPadding = { 5 }
  48. content = { content }
  49. onMediaSelect = { sendGif }
  50. style = { styles.grid } />
  51. </JitsiScreen>
  52. );
  53. };
  54. export default GifsMenu;