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

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