Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PollsList.tsx 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 { chatStyles } from './styles';
  12. const PollsList = () => {
  13. const polls = useSelector((state: IReduxState) => state['features/polls'].polls);
  14. const { t } = useTranslation();
  15. const listPolls = Object.keys(polls);
  16. const renderItem = useCallback(({ item }) => (
  17. <PollItem
  18. key = { item }
  19. pollId = { item } />)
  20. , []);
  21. const flatlistRef = useRef<FlatList>(null);
  22. const scrollToBottom = () => {
  23. flatlistRef.current?.scrollToEnd({ animated: true });
  24. };
  25. useEffect(() => {
  26. scrollToBottom();
  27. }, [ polls ]);
  28. return (
  29. <>
  30. {
  31. listPolls.length === 0
  32. && <View style = { chatStyles.noPollContent as ViewStyle }>
  33. <Icon
  34. color = { BaseTheme.palette.icon03 }
  35. size = { 160 }
  36. src = { IconMessage } />
  37. <Text style = { chatStyles.noPollText as TextStyle } >
  38. {
  39. t('polls.results.empty')
  40. }
  41. </Text>
  42. </View>
  43. }
  44. <FlatList
  45. data = { listPolls }
  46. extraData = { listPolls }
  47. // eslint-disable-next-line react/jsx-no-bind
  48. keyExtractor = { (item, index) => index.toString() }
  49. ref = { flatlistRef }
  50. renderItem = { renderItem } />
  51. </>
  52. );
  53. };
  54. export default PollsList;