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.

PollsList.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import React, { useCallback, useEffect, useRef } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { FlatList, View } from 'react-native';
  4. import { Text } from 'react-native-paper';
  5. import { useSelector } from 'react-redux';
  6. import { Icon, IconMessage } from '../../../base/icons';
  7. import BaseTheme from '../../../base/ui/components/BaseTheme.native';
  8. import PollItem from './PollItem';
  9. import { chatStyles } from './styles';
  10. const PollsList = () => {
  11. const polls = useSelector(state => state['features/polls'].polls);
  12. const { t } = useTranslation();
  13. const listPolls = Object.keys(polls);
  14. const renderItem = useCallback(({ item }) => (
  15. <PollItem
  16. key = { item }
  17. pollId = { item } />)
  18. , []);
  19. const flatlistRef = useRef();
  20. const scrollToBottom = () => {
  21. flatlistRef.current.scrollToEnd({ animating: true });
  22. };
  23. useEffect(() => {
  24. scrollToBottom();
  25. }, [ polls ]);
  26. return (
  27. <>
  28. {
  29. listPolls.length === 0
  30. && <View style = { chatStyles.noPollContent }>
  31. <Icon
  32. color = { BaseTheme.palette.icon03 }
  33. size = { 160 }
  34. src = { IconMessage } />
  35. <Text style = { chatStyles.noPollText } >
  36. {
  37. t('polls.results.empty')
  38. }
  39. </Text>
  40. </View>
  41. }
  42. <FlatList
  43. data = { listPolls }
  44. extraData = { listPolls }
  45. // eslint-disable-next-line react/jsx-no-bind
  46. keyExtractor = { (item, index) => index.toString() }
  47. ref = { flatlistRef }
  48. renderItem = { renderItem } />
  49. </>
  50. );
  51. };
  52. export default PollsList;