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.tsx 2.2KB

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