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

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