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.

RecentList.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import {
  5. createRecentClickedEvent,
  6. createRecentSelectedEvent,
  7. sendAnalytics
  8. } from '../../analytics';
  9. import { appNavigate, getDefaultURL } from '../../app';
  10. import { translate } from '../../base/i18n';
  11. import { Container, NavigateSectionList, Text } from '../../base/react';
  12. import type { Section } from '../../base/react';
  13. import { isRecentListEnabled, toDisplayableList } from '../functions';
  14. import styles from './styles';
  15. /**
  16. * The type of the React {@code Component} props of {@link RecentList}
  17. */
  18. type Props = {
  19. /**
  20. * Renders the list disabled.
  21. */
  22. disabled: boolean,
  23. /**
  24. * The redux store's {@code dispatch} function.
  25. */
  26. dispatch: Dispatch<*>,
  27. /**
  28. * The translate function.
  29. */
  30. t: Function,
  31. /**
  32. * The default server URL.
  33. */
  34. _defaultServerURL: string,
  35. /**
  36. * The recent list from the Redux store.
  37. */
  38. _recentList: Array<Section>
  39. };
  40. /**
  41. * The cross platform container rendering the list of the recently joined rooms.
  42. *
  43. */
  44. class RecentList extends Component<Props> {
  45. /**
  46. * Initializes a new {@code RecentList} instance.
  47. *
  48. * @inheritdoc
  49. */
  50. constructor(props: Props) {
  51. super(props);
  52. this._onPress = this._onPress.bind(this);
  53. }
  54. /**
  55. * Implements React's {@link Component#componentDidMount()}. Invoked
  56. * immediately after this component is mounted.
  57. *
  58. * @inheritdoc
  59. * @returns {void}
  60. */
  61. componentDidMount() {
  62. sendAnalytics(createRecentSelectedEvent());
  63. }
  64. /**
  65. * Implements the React Components's render method.
  66. *
  67. * @inheritdoc
  68. */
  69. render() {
  70. if (!isRecentListEnabled()) {
  71. return null;
  72. }
  73. const { disabled, t, _defaultServerURL, _recentList } = this.props;
  74. const recentList = toDisplayableList(_recentList, t, _defaultServerURL);
  75. return (
  76. <NavigateSectionList
  77. disabled = { disabled }
  78. onPress = { this._onPress }
  79. renderListEmptyComponent
  80. = { this._getRenderListEmptyComponent() }
  81. sections = { recentList } />
  82. );
  83. }
  84. _getRenderListEmptyComponent: () => Object;
  85. /**
  86. * Returns a list empty component if a custom one has to be rendered instead
  87. * of the default one in the {@link NavigateSectionList}.
  88. *
  89. * @private
  90. * @returns {React$Component}
  91. */
  92. _getRenderListEmptyComponent() {
  93. const { t } = this.props;
  94. return (
  95. <Container
  96. className = 'navigate-section-list-empty'
  97. style = { styles.emptyListContainer }>
  98. <Text
  99. className = 'header-text-description'
  100. style = { styles.emptyListText }>
  101. { t('welcomepage.recentListEmpty') }
  102. </Text>
  103. </Container>
  104. );
  105. }
  106. _onPress: string => Function;
  107. /**
  108. * Handles the list's navigate action.
  109. *
  110. * @private
  111. * @param {string} url - The url string to navigate to.
  112. * @returns {void}
  113. */
  114. _onPress(url) {
  115. const { dispatch } = this.props;
  116. sendAnalytics(createRecentClickedEvent('recent.meeting.tile'));
  117. dispatch(appNavigate(url));
  118. }
  119. }
  120. /**
  121. * Maps redux state to component props.
  122. *
  123. * @param {Object} state - The redux state.
  124. * @returns {{
  125. * _defaultServerURL: string,
  126. * _recentList: Array
  127. * }}
  128. */
  129. export function _mapStateToProps(state: Object) {
  130. return {
  131. _defaultServerURL: getDefaultURL(state),
  132. _recentList: state['features/recent-list']
  133. };
  134. }
  135. export default translate(connect(_mapStateToProps)(RecentList));