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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import React, { useCallback, useEffect, useRef } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { useSelector } from 'react-redux';
  4. import { makeStyles } from 'tss-react/mui';
  5. import { IReduxState } from '../../../app/types';
  6. import Icon from '../../../base/icons/components/Icon';
  7. import { IconMessage } from '../../../base/icons/svg';
  8. import { browser } from '../../../base/lib-jitsi-meet';
  9. import { withPixelLineHeight } from '../../../base/styles/functions.web';
  10. import PollItem from './PollItem';
  11. const useStyles = makeStyles()(theme => {
  12. return {
  13. container: {
  14. height: '100%',
  15. width: '100%',
  16. display: 'flex',
  17. alignItems: 'center',
  18. justifyContent: 'center',
  19. flexDirection: 'column'
  20. },
  21. emptyIcon: {
  22. width: '100px',
  23. padding: '16px',
  24. '& svg': {
  25. width: '100%',
  26. height: 'auto'
  27. }
  28. },
  29. emptyMessage: {
  30. ...withPixelLineHeight(theme.typography.bodyLongBold),
  31. color: theme.palette.text02,
  32. padding: '0 24px',
  33. textAlign: 'center'
  34. }
  35. };
  36. });
  37. const PollsList = () => {
  38. const { t } = useTranslation();
  39. const { classes, theme } = useStyles();
  40. const polls = useSelector((state: IReduxState) => state['features/polls'].polls);
  41. const pollListEndRef = useRef<HTMLDivElement>(null);
  42. const scrollToBottom = useCallback(() => {
  43. if (pollListEndRef.current) {
  44. // Safari does not support options
  45. const param = browser.isSafari()
  46. ? false : {
  47. behavior: 'smooth' as const,
  48. block: 'end' as const,
  49. inline: 'nearest' as const
  50. };
  51. pollListEndRef.current.scrollIntoView(param);
  52. }
  53. }, [ pollListEndRef.current ]);
  54. useEffect(() => {
  55. scrollToBottom();
  56. }, [ polls ]);
  57. const listPolls = Object.keys(polls);
  58. return (
  59. <>
  60. {listPolls.length === 0
  61. ? <div className = { classes.container }>
  62. <Icon
  63. className = { classes.emptyIcon }
  64. color = { theme.palette.icon03 }
  65. src = { IconMessage } />
  66. <span className = { classes.emptyMessage }>{t('polls.results.empty')}</span>
  67. </div>
  68. : listPolls.map((id, index) => (
  69. <PollItem
  70. key = { id }
  71. pollId = { id }
  72. ref = { listPolls.length - 1 === index ? pollListEndRef : null } />
  73. ))}
  74. </>
  75. );
  76. };
  77. export default PollsList;