2018-08-27 15:13:59 +00:00
|
|
|
// @flow
|
|
|
|
|
2018-09-25 12:48:03 +00:00
|
|
|
import React from 'react';
|
2018-08-27 15:13:59 +00:00
|
|
|
import { Text, TouchableOpacity, View } from 'react-native';
|
|
|
|
|
|
|
|
import { openSettings } from '../../mobile/permissions';
|
|
|
|
import { translate } from '../../base/i18n';
|
2018-09-25 12:48:03 +00:00
|
|
|
import { AbstractPage } from '../../base/react';
|
2019-03-21 16:38:29 +00:00
|
|
|
import { connect } from '../../base/redux';
|
2018-08-27 15:13:59 +00:00
|
|
|
|
2018-09-25 12:48:03 +00:00
|
|
|
import { refreshCalendar } from '../actions';
|
2018-08-27 15:13:59 +00:00
|
|
|
import styles from './styles';
|
|
|
|
|
2018-09-25 12:48:03 +00:00
|
|
|
import CalendarListContent from './CalendarListContent';
|
2018-08-27 15:13:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The tyoe of the React {@code Component} props of {@link CalendarList}.
|
|
|
|
*/
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current state of the calendar access permission.
|
|
|
|
*/
|
|
|
|
_authorization: ?string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates if the list is disabled or not.
|
|
|
|
*/
|
|
|
|
disabled: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The translate function.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component to display a list of events from the (mobile) user's calendar.
|
|
|
|
*/
|
2018-09-25 12:48:03 +00:00
|
|
|
class CalendarList extends AbstractPage<Props> {
|
2018-08-27 15:13:59 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new {@code CalendarList} instance.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once per instance.
|
|
|
|
this._getRenderListEmptyComponent
|
|
|
|
= this._getRenderListEmptyComponent.bind(this);
|
|
|
|
}
|
|
|
|
|
2018-09-25 12:48:03 +00:00
|
|
|
/**
|
|
|
|
* Public API method for {@code Component}s rendered in
|
|
|
|
* {@link AbstractPagedList}. When invoked, refreshes the calendar entries
|
|
|
|
* in the app.
|
|
|
|
*
|
|
|
|
* @param {Function} dispatch - The Redux dispatch function.
|
|
|
|
* @param {boolean} isInteractive - If true this refresh was caused by
|
|
|
|
* direct user interaction, false otherwise.
|
|
|
|
* @public
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
static refresh(dispatch, isInteractive) {
|
|
|
|
dispatch(refreshCalendar(false, isInteractive));
|
|
|
|
}
|
|
|
|
|
2018-08-27 15:13:59 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const { disabled } = this.props;
|
|
|
|
|
|
|
|
return (
|
2018-09-25 12:48:03 +00:00
|
|
|
CalendarListContent
|
|
|
|
? <CalendarListContent
|
2018-08-27 15:13:59 +00:00
|
|
|
disabled = { disabled }
|
2018-10-22 18:49:18 +00:00
|
|
|
listEmptyComponent
|
2018-08-27 15:13:59 +00:00
|
|
|
= { this._getRenderListEmptyComponent() } />
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_getRenderListEmptyComponent: () => Object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list empty component if a custom one has to be rendered instead
|
|
|
|
* of the default one in the {@link NavigateSectionList}.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {?React$Component}
|
|
|
|
*/
|
|
|
|
_getRenderListEmptyComponent() {
|
|
|
|
const { _authorization, t } = this.props;
|
|
|
|
|
|
|
|
// If we don't provide a list specific renderListEmptyComponent, then
|
|
|
|
// the default empty component of the NavigateSectionList will be
|
|
|
|
// rendered, which (atm) is a simple "Pull to refresh" message.
|
|
|
|
if (_authorization !== 'denied') {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View style = { styles.noPermissionMessageView }>
|
|
|
|
<Text style = { styles.noPermissionMessageText }>
|
|
|
|
{ t('calendarSync.permissionMessage') }
|
|
|
|
</Text>
|
|
|
|
<TouchableOpacity
|
|
|
|
onPress = { openSettings }
|
|
|
|
style = { styles.noPermissionMessageButton } >
|
|
|
|
<Text style = { styles.noPermissionMessageButtonText }>
|
|
|
|
{ t('calendarSync.permissionButton') }
|
|
|
|
</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps redux state to component props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @returns {{
|
|
|
|
* _authorization: ?string,
|
|
|
|
* _eventList: Array<Object>
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state: Object) {
|
|
|
|
const { authorization } = state['features/calendar-sync'];
|
|
|
|
|
|
|
|
return {
|
|
|
|
_authorization: authorization
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-05-28 13:32:29 +00:00
|
|
|
export default translate(connect(_mapStateToProps)(CalendarList));
|