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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import { appNavigate, getDefaultURL } from '../../app';
  5. import { translate } from '../../base/i18n';
  6. import { NavigateSectionList } from '../../base/react';
  7. import type { Section } from '../../base/react';
  8. import { isRecentListEnabled, toDisplayableList } from '../functions';
  9. /**
  10. * The type of the React {@code Component} props of {@link RecentList}
  11. */
  12. type Props = {
  13. /**
  14. * Renders the list disabled.
  15. */
  16. disabled: boolean,
  17. /**
  18. * The redux store's {@code dispatch} function.
  19. */
  20. dispatch: Dispatch<*>,
  21. /**
  22. * The translate function.
  23. */
  24. t: Function,
  25. /**
  26. * The default server URL.
  27. */
  28. _defaultServerURL: string,
  29. /**
  30. * The recent list from the Redux store.
  31. */
  32. _recentList: Array<Section>
  33. };
  34. /**
  35. * The cross platform container rendering the list of the recently joined rooms.
  36. *
  37. */
  38. class RecentList extends Component<Props> {
  39. /**
  40. * Initializes a new {@code RecentList} instance.
  41. *
  42. * @inheritdoc
  43. */
  44. constructor(props: Props) {
  45. super(props);
  46. this._onPress = this._onPress.bind(this);
  47. }
  48. /**
  49. * Implements the React Components's render method.
  50. *
  51. * @inheritdoc
  52. */
  53. render() {
  54. if (!isRecentListEnabled()) {
  55. return null;
  56. }
  57. const { disabled, t, _defaultServerURL, _recentList } = this.props;
  58. const recentList = toDisplayableList(_recentList, t, _defaultServerURL);
  59. return (
  60. <NavigateSectionList
  61. disabled = { disabled }
  62. onPress = { this._onPress }
  63. sections = { recentList } />
  64. );
  65. }
  66. _onPress: string => Function;
  67. /**
  68. * Handles the list's navigate action.
  69. *
  70. * @private
  71. * @param {string} url - The url string to navigate to.
  72. * @returns {void}
  73. */
  74. _onPress(url) {
  75. const { dispatch } = this.props;
  76. dispatch(appNavigate(url));
  77. }
  78. }
  79. /**
  80. * Maps redux state to component props.
  81. *
  82. * @param {Object} state - The redux state.
  83. * @returns {{
  84. * _defaultServerURL: string,
  85. * _recentList: Array
  86. * }}
  87. */
  88. export function _mapStateToProps(state: Object) {
  89. return {
  90. _defaultServerURL: getDefaultURL(state),
  91. _recentList: state['features/recent-list']
  92. };
  93. }
  94. export default translate(connect(_mapStateToProps)(RecentList));