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.native.js 2.9KB

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