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.tsx 4.2KB

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