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

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