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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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, getGiphyProxyUrl } 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 proxyUrl = useSelector(getGiphyProxyUrl);
  20. const options = {
  21. mediaType: GiphyMediaType.Gif,
  22. limit: 20,
  23. rating
  24. };
  25. const content = searchQuery === ''
  26. ? GiphyContent.trending(options)
  27. : GiphyContent.search({
  28. ...options,
  29. searchQuery
  30. });
  31. const sendGif = useCallback(e => {
  32. const url = getGifUrl(e.nativeEvent.media, proxyUrl);
  33. sendAnalytics(createGifSentEvent());
  34. dispatch(sendMessage(formatGifUrlMessage(url), true));
  35. goBack();
  36. }, []);
  37. return (
  38. <JitsiScreen
  39. footerComponent = { GifsMenuFooter }
  40. style = { styles.container }>
  41. <Input
  42. clearable = { true }
  43. customStyles = {{ container: styles.customContainer }}
  44. onChange = { setSearchQuery }
  45. placeholder = { t('giphy.search') }
  46. value = { searchQuery } />
  47. <GiphyGridView
  48. cellPadding = { 5 }
  49. content = { content }
  50. onMediaSelect = { sendGif }
  51. style = { styles.grid } />
  52. </JitsiScreen>
  53. );
  54. };
  55. export default GifsMenu;