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

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