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.

CalendarList.native.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // @flow
  2. import React from 'react';
  3. import { Text, TouchableOpacity, View } from 'react-native';
  4. import { connect } from 'react-redux';
  5. import { openSettings } from '../../mobile/permissions';
  6. import { translate } from '../../base/i18n';
  7. import { AbstractPage } from '../../base/react';
  8. import { refreshCalendar } from '../actions';
  9. import { isCalendarEnabled } from '../functions';
  10. import styles from './styles';
  11. import CalendarListContent from './CalendarListContent';
  12. /**
  13. * The tyoe of the React {@code Component} props of {@link CalendarList}.
  14. */
  15. type Props = {
  16. /**
  17. * The current state of the calendar access permission.
  18. */
  19. _authorization: ?string,
  20. /**
  21. * Indicates if the list is disabled or not.
  22. */
  23. disabled: boolean,
  24. /**
  25. * The translate function.
  26. */
  27. t: Function
  28. };
  29. /**
  30. * Component to display a list of events from the (mobile) user's calendar.
  31. */
  32. class CalendarList extends AbstractPage<Props> {
  33. /**
  34. * Initializes a new {@code CalendarList} instance.
  35. *
  36. * @inheritdoc
  37. */
  38. constructor(props) {
  39. super(props);
  40. // Bind event handlers so they are only bound once per instance.
  41. this._getRenderListEmptyComponent
  42. = this._getRenderListEmptyComponent.bind(this);
  43. }
  44. /**
  45. * Public API method for {@code Component}s rendered in
  46. * {@link AbstractPagedList}. When invoked, refreshes the calendar entries
  47. * in the app.
  48. *
  49. * @param {Function} dispatch - The Redux dispatch function.
  50. * @param {boolean} isInteractive - If true this refresh was caused by
  51. * direct user interaction, false otherwise.
  52. * @public
  53. * @returns {void}
  54. */
  55. static refresh(dispatch, isInteractive) {
  56. dispatch(refreshCalendar(false, isInteractive));
  57. }
  58. /**
  59. * Implements React's {@link Component#render}.
  60. *
  61. * @inheritdoc
  62. */
  63. render() {
  64. const { disabled } = this.props;
  65. return (
  66. CalendarListContent
  67. ? <CalendarListContent
  68. disabled = { disabled }
  69. listEmptyComponent
  70. = { this._getRenderListEmptyComponent() } />
  71. : null
  72. );
  73. }
  74. _getRenderListEmptyComponent: () => Object;
  75. /**
  76. * Returns a list empty component if a custom one has to be rendered instead
  77. * of the default one in the {@link NavigateSectionList}.
  78. *
  79. * @private
  80. * @returns {?React$Component}
  81. */
  82. _getRenderListEmptyComponent() {
  83. const { _authorization, t } = this.props;
  84. // If we don't provide a list specific renderListEmptyComponent, then
  85. // the default empty component of the NavigateSectionList will be
  86. // rendered, which (atm) is a simple "Pull to refresh" message.
  87. if (_authorization !== 'denied') {
  88. return undefined;
  89. }
  90. return (
  91. <View style = { styles.noPermissionMessageView }>
  92. <Text style = { styles.noPermissionMessageText }>
  93. { t('calendarSync.permissionMessage') }
  94. </Text>
  95. <TouchableOpacity
  96. onPress = { openSettings }
  97. style = { styles.noPermissionMessageButton } >
  98. <Text style = { styles.noPermissionMessageButtonText }>
  99. { t('calendarSync.permissionButton') }
  100. </Text>
  101. </TouchableOpacity>
  102. </View>
  103. );
  104. }
  105. }
  106. /**
  107. * Maps redux state to component props.
  108. *
  109. * @param {Object} state - The redux state.
  110. * @returns {{
  111. * _authorization: ?string,
  112. * _eventList: Array<Object>
  113. * }}
  114. */
  115. function _mapStateToProps(state: Object) {
  116. const { authorization } = state['features/calendar-sync'];
  117. return {
  118. _authorization: authorization
  119. };
  120. }
  121. export default isCalendarEnabled()
  122. ? translate(connect(_mapStateToProps)(CalendarList))
  123. : undefined;