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

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