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

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