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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // @flow
  2. import React from 'react';
  3. import type { Dispatch } from 'redux';
  4. import { getDefaultURL } from '../../app';
  5. import { translate } from '../../base/i18n';
  6. import { NavigateSectionList, type Section } from '../../base/react';
  7. import { connect } from '../../base/redux';
  8. import { ColorPalette } from '../../base/styles';
  9. import { showDialInSummary } from '../../invite';
  10. import { deleteRecentListEntry } from '../actions';
  11. import { isRecentListEnabled, toDisplayableList } from '../functions';
  12. import AbstractRecentList from './AbstractRecentList';
  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. * The translate function.
  27. */
  28. t: Function,
  29. /**
  30. * The default server URL.
  31. */
  32. _defaultServerURL: string,
  33. /**
  34. * The recent list from the Redux store.
  35. */
  36. _recentList: Array<Section>
  37. };
  38. /**
  39. * A class that renders the list of the recently joined rooms.
  40. *
  41. */
  42. class RecentList extends AbstractRecentList<Props> {
  43. _getRenderListEmptyComponent: () => React$Node;
  44. _onPress: string => {};
  45. /**
  46. * Initializes a new {@code RecentList} instance.
  47. *
  48. * @inheritdoc
  49. */
  50. constructor(props: Props) {
  51. super(props);
  52. this._onDelete = this._onDelete.bind(this);
  53. this._onShowDialInInfo = this._onShowDialInInfo.bind(this);
  54. }
  55. /**
  56. * Implements the React Components's render method.
  57. *
  58. * @inheritdoc
  59. */
  60. render() {
  61. if (!isRecentListEnabled()) {
  62. return null;
  63. }
  64. const {
  65. disabled,
  66. t,
  67. _defaultServerURL,
  68. _recentList
  69. } = this.props;
  70. const recentList = toDisplayableList(_recentList, t, _defaultServerURL);
  71. const slideActions = [ {
  72. backgroundColor: ColorPalette.blue,
  73. onPress: this._onShowDialInInfo,
  74. text: t('welcomepage.info')
  75. }, {
  76. backgroundColor: 'red',
  77. onPress: this._onDelete,
  78. text: t('welcomepage.recentListDelete')
  79. } ];
  80. return (
  81. <NavigateSectionList
  82. disabled = { disabled }
  83. onPress = { this._onPress }
  84. renderListEmptyComponent
  85. = { this._getRenderListEmptyComponent() }
  86. sections = { recentList }
  87. slideActions = { slideActions } />
  88. );
  89. }
  90. _onDelete: Object => void
  91. /**
  92. * Callback for the delete action of the list.
  93. *
  94. * @param {Object} itemId - The ID of the entry thats deletion is
  95. * requested.
  96. * @returns {void}
  97. */
  98. _onDelete(itemId) {
  99. this.props.dispatch(deleteRecentListEntry(itemId));
  100. }
  101. _onShowDialInInfo: Object => void
  102. /**
  103. * Callback for the dial-in info action of the list.
  104. *
  105. * @param {Object} itemId - The ID of the entry for which we'd like to show the dial in numbers.
  106. * @returns {void}
  107. */
  108. _onShowDialInInfo(itemId) {
  109. this.props.dispatch(showDialInSummary(itemId.url));
  110. }
  111. }
  112. /**
  113. * Maps redux state to component props.
  114. *
  115. * @param {Object} state - The redux state.
  116. * @returns {{
  117. * _defaultServerURL: string,
  118. * _recentList: Array
  119. * }}
  120. */
  121. export function _mapStateToProps(state: Object) {
  122. return {
  123. _defaultServerURL: getDefaultURL(state),
  124. _recentList: state['features/recent-list']
  125. };
  126. }
  127. export default translate(connect(_mapStateToProps)(RecentList));