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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // @flow
  2. import React from 'react';
  3. import { connect } from 'react-redux';
  4. import type { Dispatch } from 'redux';
  5. import { getDefaultURL } from '../../app';
  6. import { translate } from '../../base/i18n';
  7. import { NavigateSectionList } from '../../base/react';
  8. import type { Section } from '../../base/react';
  9. import { deleteRecentListEntry } from '../actions';
  10. import { isRecentListEnabled, toDisplayableList } from '../functions';
  11. import AbstractRecentList from './AbstractRecentList';
  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. this._onDelete = this._onDelete.bind(this);
  52. }
  53. /**
  54. * Implements the React Components's render method.
  55. *
  56. * @inheritdoc
  57. */
  58. render() {
  59. if (!isRecentListEnabled()) {
  60. return null;
  61. }
  62. const {
  63. disabled,
  64. t,
  65. _defaultServerURL,
  66. _recentList
  67. } = this.props;
  68. const recentList = toDisplayableList(_recentList, t, _defaultServerURL);
  69. const slideActions = [ {
  70. backgroundColor: 'red',
  71. onPress: this._onDelete,
  72. text: t('welcomepage.recentListDelete')
  73. } ];
  74. return (
  75. <NavigateSectionList
  76. disabled = { disabled }
  77. onPress = { this._onPress }
  78. renderListEmptyComponent
  79. = { this._getRenderListEmptyComponent() }
  80. sections = { recentList }
  81. slideActions = { slideActions } />
  82. );
  83. }
  84. _onDelete: Object => void
  85. /**
  86. * Callback for the delete action of the list.
  87. *
  88. * @param {Object} itemId - The ID of the entry thats deletion is
  89. * requested.
  90. * @returns {void}
  91. */
  92. _onDelete(itemId) {
  93. this.props.dispatch(deleteRecentListEntry(itemId));
  94. }
  95. }
  96. /**
  97. * Maps redux state to component props.
  98. *
  99. * @param {Object} state - The redux state.
  100. * @returns {{
  101. * _defaultServerURL: string,
  102. * _recentList: Array
  103. * }}
  104. */
  105. export function _mapStateToProps(state: Object) {
  106. return {
  107. _defaultServerURL: getDefaultURL(state),
  108. _recentList: state['features/recent-list']
  109. };
  110. }
  111. export default translate(connect(_mapStateToProps)(RecentList));