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

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