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

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