Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

CalendarList.native.js 3.3KB

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