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

RecentList.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 type { Section } from '../../base/react/Types';
  7. import { NavigateSectionList } from '../../base/react';
  8. import { 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. const { disabled, t, _defaultServerURL, _recentList } = this.props;
  55. const recentList = toDisplayableList(_recentList, t, _defaultServerURL);
  56. return (
  57. <NavigateSectionList
  58. disabled = { disabled }
  59. onPress = { this._onPress }
  60. sections = { recentList } />
  61. );
  62. }
  63. _onPress: string => Function;
  64. /**
  65. * Handles the list's navigate action.
  66. *
  67. * @private
  68. * @param {string} url - The url string to navigate to.
  69. * @returns {void}
  70. */
  71. _onPress(url) {
  72. const { dispatch } = this.props;
  73. dispatch(appNavigate(url));
  74. }
  75. }
  76. /**
  77. * Maps redux state to component props.
  78. *
  79. * @param {Object} state - The redux state.
  80. * @returns {{
  81. * _defaultServerURL: string,
  82. * _recentList: Array
  83. * }}
  84. */
  85. export function _mapStateToProps(state: Object) {
  86. return {
  87. _defaultServerURL: getDefaultURL(state),
  88. _recentList: state['features/recent-list']
  89. };
  90. }
  91. export default translate(connect(_mapStateToProps)(RecentList));