2018-04-24 13:11:25 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React, { Component } from 'react';
|
2018-05-31 09:00:33 +00:00
|
|
|
import { connect } from 'react-redux';
|
2018-04-24 13:11:25 +00:00
|
|
|
|
|
|
|
import { translate } from '../../base/i18n';
|
|
|
|
import { PagedList } from '../../base/react';
|
2018-08-27 15:13:59 +00:00
|
|
|
import { CalendarList } from '../../calendar-sync';
|
2018-04-24 13:11:25 +00:00
|
|
|
import { RecentList } from '../../recent-list';
|
|
|
|
|
2018-06-11 17:28:45 +00:00
|
|
|
import { setWelcomePageListsDefaultPage } from '../actions';
|
2018-06-05 12:34:40 +00:00
|
|
|
|
2018-06-11 17:28:45 +00:00
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@link WelcomePageLists}.
|
|
|
|
*/
|
2018-04-24 13:11:25 +00:00
|
|
|
type Props = {
|
|
|
|
|
2018-05-31 09:00:33 +00:00
|
|
|
/**
|
2018-06-05 12:34:40 +00:00
|
|
|
* The stored default page index.
|
2018-05-31 09:00:33 +00:00
|
|
|
*/
|
2018-06-05 12:34:40 +00:00
|
|
|
_defaultPage: number,
|
2018-05-31 09:00:33 +00:00
|
|
|
|
2018-04-24 13:11:25 +00:00
|
|
|
/**
|
|
|
|
* Renders the lists disabled.
|
|
|
|
*/
|
|
|
|
disabled: boolean,
|
|
|
|
|
2018-06-05 12:34:40 +00:00
|
|
|
/**
|
|
|
|
* The Redux dispatch function.
|
|
|
|
*/
|
|
|
|
dispatch: Function,
|
|
|
|
|
2018-04-24 13:11:25 +00:00
|
|
|
/**
|
|
|
|
* The i18n translate function.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements the lists displayed on the mobile welcome screen.
|
|
|
|
*/
|
|
|
|
class WelcomePageLists extends Component<Props> {
|
|
|
|
/**
|
|
|
|
* The pages to be rendered.
|
2018-06-11 17:28:45 +00:00
|
|
|
*
|
|
|
|
* Note: An element's {@code component} may be {@code undefined} if a
|
|
|
|
* feature (such as Calendar) is disabled, and that means that the page must
|
|
|
|
* not be rendered.
|
2018-04-24 13:11:25 +00:00
|
|
|
*/
|
|
|
|
pages: Array<{
|
2018-06-11 17:28:45 +00:00
|
|
|
component: ?Object,
|
2018-04-24 13:11:25 +00:00
|
|
|
icon: string | number,
|
|
|
|
title: string
|
2018-06-11 17:28:45 +00:00
|
|
|
}>;
|
2018-04-24 13:11:25 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-11 17:28:45 +00:00
|
|
|
* Initializes a new {@code WelcomePageLists} instance.
|
2018-04-24 13:11:25 +00:00
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
const { t } = props;
|
2018-06-11 17:28:45 +00:00
|
|
|
|
|
|
|
this.pages = [
|
|
|
|
{
|
|
|
|
component: RecentList,
|
2018-09-25 12:48:03 +00:00
|
|
|
icon: 'restore',
|
2018-06-11 17:28:45 +00:00
|
|
|
title: t('welcomepage.recentList')
|
|
|
|
},
|
|
|
|
{
|
2018-08-27 15:13:59 +00:00
|
|
|
component: CalendarList,
|
2018-09-25 12:48:03 +00:00
|
|
|
icon: 'event_note',
|
2018-06-11 17:28:45 +00:00
|
|
|
title: t('welcomepage.calendar')
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once per instance.
|
2018-06-05 12:34:40 +00:00
|
|
|
this._onSelectPage = this._onSelectPage.bind(this);
|
2018-04-24 13:11:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-06-11 17:28:45 +00:00
|
|
|
* Implements React's {@link Component#render}.
|
2018-04-24 13:11:25 +00:00
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
render() {
|
2018-06-11 17:28:45 +00:00
|
|
|
const { _defaultPage } = this.props;
|
2018-06-05 12:34:40 +00:00
|
|
|
|
|
|
|
if (typeof _defaultPage === 'undefined') {
|
|
|
|
return null;
|
|
|
|
}
|
2018-04-24 13:11:25 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<PagedList
|
2018-06-05 12:34:40 +00:00
|
|
|
defaultPage = { _defaultPage }
|
2018-06-11 17:28:45 +00:00
|
|
|
disabled = { this.props.disabled }
|
2018-06-05 12:34:40 +00:00
|
|
|
onSelectPage = { this._onSelectPage }
|
2018-04-24 13:11:25 +00:00
|
|
|
pages = { this.pages } />
|
|
|
|
);
|
|
|
|
}
|
2018-06-05 12:34:40 +00:00
|
|
|
|
2018-06-11 17:28:45 +00:00
|
|
|
_onSelectPage: number => void;
|
2018-06-05 12:34:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for the {@code PagedList} page select action.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {number} pageIndex - The index of the selected page.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onSelectPage(pageIndex) {
|
2018-06-11 17:28:45 +00:00
|
|
|
this.props.dispatch(setWelcomePageListsDefaultPage(pageIndex));
|
2018-06-05 12:34:40 +00:00
|
|
|
}
|
2018-04-24 13:11:25 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 09:00:33 +00:00
|
|
|
/**
|
|
|
|
* Maps (parts of) the redux state to the React {@code Component} props of
|
|
|
|
* {@code WelcomePageLists}.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @protected
|
|
|
|
* @returns {{
|
2018-06-11 17:28:45 +00:00
|
|
|
* _defaultPage: number
|
2018-05-31 09:00:33 +00:00
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state: Object) {
|
2018-06-11 17:28:45 +00:00
|
|
|
let { defaultPage } = state['features/welcome'];
|
|
|
|
|
|
|
|
if (typeof defaultPage === 'undefined') {
|
|
|
|
const recentList = state['features/recent-list'];
|
|
|
|
|
|
|
|
defaultPage = recentList && recentList.length ? 0 : 1;
|
|
|
|
}
|
2018-05-31 09:00:33 +00:00
|
|
|
|
|
|
|
return {
|
2018-06-11 17:28:45 +00:00
|
|
|
_defaultPage: defaultPage
|
2018-05-31 09:00:33 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(_mapStateToProps)(WelcomePageLists));
|