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.

CalendarListContent.web.tsx 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import { createCalendarClickedEvent, createCalendarSelectedEvent } from '../../analytics/AnalyticsEvents';
  4. import { sendAnalytics } from '../../analytics/functions';
  5. import { appNavigate } from '../../app/actions.web';
  6. import { IReduxState } from '../../app/types';
  7. import MeetingsList from '../../base/react/components/web/MeetingsList';
  8. import AddMeetingUrlButton from './AddMeetingUrlButton.web';
  9. import JoinButton from './JoinButton.web';
  10. /**
  11. * The type of the React {@code Component} props of
  12. * {@link CalendarListContent}.
  13. */
  14. interface IProps {
  15. /**
  16. * The calendar event list.
  17. */
  18. _eventList: Array<Object>;
  19. /**
  20. * Indicates if the list is disabled or not.
  21. */
  22. disabled: boolean;
  23. /**
  24. * The Redux dispatch function.
  25. */
  26. dispatch: Function;
  27. /**
  28. *
  29. */
  30. listEmptyComponent: React.ReactNode;
  31. }
  32. /**
  33. * Component to display a list of events from a connected calendar.
  34. */
  35. class CalendarListContent extends Component<IProps> {
  36. /**
  37. * Default values for the component's props.
  38. */
  39. static defaultProps = {
  40. _eventList: []
  41. };
  42. /**
  43. * Initializes a new {@code CalendarListContent} instance.
  44. *
  45. * @inheritdoc
  46. */
  47. constructor(props: IProps) {
  48. super(props);
  49. // Bind event handlers so they are only bound once per instance.
  50. this._onJoinPress = this._onJoinPress.bind(this);
  51. this._onPress = this._onPress.bind(this);
  52. this._toDisplayableItem = this._toDisplayableItem.bind(this);
  53. }
  54. /**
  55. * Implements React's {@link Component#componentDidMount()}. Invoked
  56. * immediately after this component is mounted.
  57. *
  58. * @inheritdoc
  59. * @returns {void}
  60. */
  61. componentDidMount() {
  62. sendAnalytics(createCalendarSelectedEvent());
  63. }
  64. /**
  65. * Implements React's {@link Component#render}.
  66. *
  67. * @inheritdoc
  68. */
  69. render() {
  70. const { disabled, listEmptyComponent } = this.props;
  71. const { _eventList = [] } = this.props;
  72. const meetings = _eventList.map(this._toDisplayableItem);
  73. return (
  74. <MeetingsList
  75. disabled = { disabled }
  76. listEmptyComponent = { listEmptyComponent }
  77. meetings = { meetings }
  78. onPress = { this._onPress } />
  79. );
  80. }
  81. /**
  82. * Handles the list's navigate action.
  83. *
  84. * @private
  85. * @param {Object} event - The click event.
  86. * @param {string} url - The url string to navigate to.
  87. * @returns {void}
  88. */
  89. _onJoinPress(event: React.KeyboardEvent, url: string) {
  90. event.stopPropagation();
  91. this._onPress(url, 'meeting.join');
  92. }
  93. /**
  94. * Handles the list's navigate action.
  95. *
  96. * @private
  97. * @param {string} url - The url string to navigate to.
  98. * @param {string} analyticsEventName - Тhe name of the analytics event
  99. * associated with this action.
  100. * @returns {void}
  101. */
  102. _onPress(url: string, analyticsEventName = 'meeting.tile') {
  103. sendAnalytics(createCalendarClickedEvent(analyticsEventName));
  104. this.props.dispatch(appNavigate(url));
  105. }
  106. /**
  107. * Creates a displayable object from an event.
  108. *
  109. * @param {Object} event - The calendar event.
  110. * @private
  111. * @returns {Object}
  112. */
  113. _toDisplayableItem(event: any) {
  114. return {
  115. elementAfter: event.url
  116. ? <JoinButton
  117. onPress = { this._onJoinPress }
  118. url = { event.url } />
  119. : (<AddMeetingUrlButton
  120. calendarId = { event.calendarId }
  121. eventId = { event.id } />),
  122. date: event.startDate,
  123. time: [ event.startDate, event.endDate ],
  124. description: event.url,
  125. title: event.title,
  126. url: event.url
  127. };
  128. }
  129. }
  130. /**
  131. * Maps redux state to component props.
  132. *
  133. * @param {Object} state - The redux state.
  134. * @returns {{
  135. * _eventList: Array<Object>
  136. * }}
  137. */
  138. function _mapStateToProps(state: IReduxState) {
  139. return {
  140. _eventList: state['features/calendar-sync'].events
  141. };
  142. }
  143. export default connect(_mapStateToProps)(CalendarListContent);