您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

PollsList.tsx 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. interface IPollListProps {
  38. setCreateMode: (mode: boolean) => void;
  39. }
  40. const PollsList = ({ setCreateMode }: IPollListProps) => {
  41. const { t } = useTranslation();
  42. const { classes, theme } = useStyles();
  43. const { polls } = useSelector((state: IReduxState) => state['features/polls']);
  44. const pollListEndRef = useRef<HTMLDivElement>(null);
  45. const scrollToBottom = useCallback(() => {
  46. if (pollListEndRef.current) {
  47. // Safari does not support options
  48. const param = browser.isSafari()
  49. ? false : {
  50. behavior: 'smooth' as const,
  51. block: 'end' as const,
  52. inline: 'nearest' as const
  53. };
  54. pollListEndRef.current.scrollIntoView(param);
  55. }
  56. }, [ pollListEndRef.current ]);
  57. useEffect(() => {
  58. scrollToBottom();
  59. }, [ polls ]);
  60. const listPolls = Object.keys(polls);
  61. return (
  62. <>
  63. {listPolls.length === 0
  64. ? <div className = { classes.container }>
  65. <Icon
  66. className = { classes.emptyIcon }
  67. color = { theme.palette.icon03 }
  68. src = { IconMessage } />
  69. <span className = { classes.emptyMessage }>{t('polls.results.empty')}</span>
  70. </div>
  71. : listPolls.map((id, index) => (
  72. <PollItem
  73. key = { id }
  74. pollId = { id }
  75. ref = { listPolls.length - 1 === index ? pollListEndRef : null }
  76. setCreateMode = { setCreateMode } />
  77. ))}
  78. </>
  79. );
  80. };
  81. export default PollsList;