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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 { setActiveModalId } from '../../base/modal';
  7. import { NavigateSectionList, type Section } from '../../base/react';
  8. import { connect } from '../../base/redux';
  9. import { ColorPalette } from '../../base/styles';
  10. import { DIAL_IN_SUMMARY_VIEW_ID } from '../../invite/constants';
  11. import { deleteRecentListEntry } from '../actions';
  12. import { isRecentListEnabled, toDisplayableList } from '../functions';
  13. import AbstractRecentList from './AbstractRecentList';
  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. this._onDelete = this._onDelete.bind(this);
  54. this._onShowDialInInfo = this._onShowDialInInfo.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. const slideActions = [ {
  73. backgroundColor: ColorPalette.blue,
  74. onPress: this._onShowDialInInfo,
  75. text: t('welcomepage.info')
  76. }, {
  77. backgroundColor: 'red',
  78. onPress: this._onDelete,
  79. text: t('welcomepage.recentListDelete')
  80. } ];
  81. return (
  82. <NavigateSectionList
  83. disabled = { disabled }
  84. onPress = { this._onPress }
  85. renderListEmptyComponent
  86. = { this._getRenderListEmptyComponent() }
  87. sections = { recentList }
  88. slideActions = { slideActions } />
  89. );
  90. }
  91. _onDelete: Object => void
  92. /**
  93. * Callback for the delete action of the list.
  94. *
  95. * @param {Object} itemId - The ID of the entry thats deletion is
  96. * requested.
  97. * @returns {void}
  98. */
  99. _onDelete(itemId) {
  100. this.props.dispatch(deleteRecentListEntry(itemId));
  101. }
  102. _onShowDialInInfo: Object => void
  103. /**
  104. * Callback for the dial-in info action of the list.
  105. *
  106. * @param {Object} itemId - The ID of the entry for which we'd like to show the dial in numbers.
  107. * @returns {void}
  108. */
  109. _onShowDialInInfo(itemId) {
  110. this.props.dispatch(setActiveModalId(DIAL_IN_SUMMARY_VIEW_ID, { summaryUrl: itemId.url }));
  111. }
  112. }
  113. /**
  114. * Maps redux state to component props.
  115. *
  116. * @param {Object} state - The redux state.
  117. * @returns {{
  118. * _defaultServerURL: string,
  119. * _recentList: Array
  120. * }}
  121. */
  122. export function _mapStateToProps(state: Object) {
  123. return {
  124. _defaultServerURL: getDefaultURL(state),
  125. _recentList: state['features/recent-list']
  126. };
  127. }
  128. export default translate(connect(_mapStateToProps)(RecentList));