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

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