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.

WelcomePageLists.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { translate } from '../../base/i18n';
  4. import { IconEventNote, IconRestore } from '../../base/icons';
  5. import { PagedList } from '../../base/react';
  6. import { connect } from '../../base/redux';
  7. import { CalendarList, isCalendarEnabled } from '../../calendar-sync';
  8. import { RecentList } from '../../recent-list';
  9. import { setWelcomePageListsDefaultPage } from '../actions';
  10. /**
  11. * The type of the React {@code Component} props of {@link WelcomePageLists}.
  12. */
  13. type Props = {
  14. /**
  15. * Whether the calendar functionality is enabled or not.
  16. */
  17. _calendarEnabled: boolean,
  18. /**
  19. * The stored default page index.
  20. */
  21. _defaultPage: number,
  22. /**
  23. * Renders the lists disabled.
  24. */
  25. disabled: boolean,
  26. /**
  27. * The Redux dispatch function.
  28. */
  29. dispatch: Function,
  30. /**
  31. * The i18n translate function.
  32. */
  33. t: Function
  34. };
  35. /**
  36. * Implements the lists displayed on the mobile welcome screen.
  37. */
  38. class WelcomePageLists extends Component<Props> {
  39. /**
  40. * Initializes a new {@code WelcomePageLists} instance.
  41. *
  42. * @inheritdoc
  43. */
  44. constructor(props) {
  45. super(props);
  46. // Bind event handlers so they are only bound once per instance.
  47. this._onSelectPage = this._onSelectPage.bind(this);
  48. }
  49. /**
  50. * Implements React's {@link Component#render}.
  51. *
  52. * @inheritdoc
  53. */
  54. render() {
  55. const { _calendarEnabled, _defaultPage, t } = this.props;
  56. if (typeof _defaultPage === 'undefined') {
  57. return null;
  58. }
  59. const pages = [
  60. {
  61. component: RecentList,
  62. icon: IconRestore,
  63. title: t('welcomepage.recentList')
  64. }
  65. ];
  66. if (_calendarEnabled) {
  67. pages.push(
  68. {
  69. component: CalendarList,
  70. icon: IconEventNote,
  71. title: t('welcomepage.calendar')
  72. }
  73. );
  74. }
  75. return (
  76. <PagedList
  77. defaultPage = { _defaultPage }
  78. disabled = { this.props.disabled }
  79. onSelectPage = { this._onSelectPage }
  80. pages = { pages } />
  81. );
  82. }
  83. _onSelectPage: number => void;
  84. /**
  85. * Callback for the {@code PagedList} page select action.
  86. *
  87. * @private
  88. * @param {number} pageIndex - The index of the selected page.
  89. * @returns {void}
  90. */
  91. _onSelectPage(pageIndex) {
  92. this.props.dispatch(setWelcomePageListsDefaultPage(pageIndex));
  93. }
  94. }
  95. /**
  96. * Maps (parts of) the redux state to the React {@code Component} props of
  97. * {@code WelcomePageLists}.
  98. *
  99. * @param {Object} state - The redux state.
  100. * @protected
  101. * @returns {{
  102. * _calendarEnabled: boolean,
  103. * _defaultPage: number
  104. * }}
  105. */
  106. function _mapStateToProps(state: Object) {
  107. let { defaultPage } = state['features/welcome'];
  108. if (typeof defaultPage === 'undefined') {
  109. const recentList = state['features/recent-list'];
  110. defaultPage = recentList && recentList.length ? 0 : 1;
  111. }
  112. return {
  113. _calendarEnabled: isCalendarEnabled(state),
  114. _defaultPage: defaultPage
  115. };
  116. }
  117. export default translate(connect(_mapStateToProps)(WelcomePageLists));