Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

RecentList.native.js 3.3KB

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