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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // @flow
  2. import React, { useEffect, useRef } from 'react';
  3. import { useTranslation } from 'react-i18next';
  4. import { useSelector } from 'react-redux';
  5. import { Icon, IconChatUnread } from '../../../base/icons';
  6. import { PollItem } from '.';
  7. const PollsList = () => {
  8. const { t } = useTranslation();
  9. const polls = useSelector(state => state['features/polls'].polls);
  10. const pollListEndRef = useRef(null);
  11. const scrollToBottom = () => {
  12. if (pollListEndRef.current) {
  13. pollListEndRef.current.scrollIntoView({ behavior: 'smooth' });
  14. }
  15. };
  16. useEffect(() => {
  17. scrollToBottom();
  18. }, [ polls ]);
  19. const listPolls = Object.keys(polls);
  20. return (
  21. <>
  22. {listPolls.length === 0
  23. ? <div className = 'pane-content'>
  24. <Icon
  25. className = 'empty-pane-icon'
  26. src = { IconChatUnread } />
  27. <span className = 'empty-pane-message'>{t('polls.results.empty')}</span>
  28. </div>
  29. : listPolls.map((id, index) => (
  30. <PollItem
  31. key = { id }
  32. pollId = { id }
  33. ref = { listPolls.length - 1 === index ? pollListEndRef : null } />
  34. ))}
  35. </>
  36. );
  37. };
  38. export default PollsList;