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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { Platform } from 'react-native';
  4. import { connect } from 'react-redux';
  5. import { translate } from '../../base/i18n';
  6. import { PagedList } from '../../base/react';
  7. import { MeetingList } 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. * The stored default page index.
  16. */
  17. _defaultPage: number,
  18. /**
  19. * Renders the lists disabled.
  20. */
  21. disabled: boolean,
  22. /**
  23. * The Redux dispatch function.
  24. */
  25. dispatch: Function,
  26. /**
  27. * The i18n translate function.
  28. */
  29. t: Function
  30. };
  31. /**
  32. * Icon to be used for the calendar page on iOS.
  33. */
  34. const IOS_CALENDAR_ICON = require('../../../../images/calendar.png');
  35. /**
  36. * Icon to be used for the recent list page on iOS.
  37. */
  38. const IOS_RECENT_LIST_ICON = require('../../../../images/history.png');
  39. /**
  40. * Implements the lists displayed on the mobile welcome screen.
  41. */
  42. class WelcomePageLists extends Component<Props> {
  43. /**
  44. * The pages to be rendered.
  45. *
  46. * Note: An element's {@code component} may be {@code undefined} if a
  47. * feature (such as Calendar) is disabled, and that means that the page must
  48. * not be rendered.
  49. */
  50. pages: Array<{
  51. component: ?Object,
  52. icon: string | number,
  53. title: string
  54. }>;
  55. /**
  56. * Initializes a new {@code WelcomePageLists} instance.
  57. *
  58. * @inheritdoc
  59. */
  60. constructor(props) {
  61. super(props);
  62. const { t } = props;
  63. const android = Platform.OS === 'android';
  64. this.pages = [
  65. {
  66. component: RecentList,
  67. icon: android ? 'restore' : IOS_RECENT_LIST_ICON,
  68. title: t('welcomepage.recentList')
  69. },
  70. {
  71. component: MeetingList,
  72. icon: android ? 'event_note' : IOS_CALENDAR_ICON,
  73. title: t('welcomepage.calendar')
  74. }
  75. ];
  76. // Bind event handlers so they are only bound once per instance.
  77. this._onSelectPage = this._onSelectPage.bind(this);
  78. }
  79. /**
  80. * Implements React's {@link Component#render}.
  81. *
  82. * @inheritdoc
  83. */
  84. render() {
  85. const { _defaultPage } = this.props;
  86. if (typeof _defaultPage === 'undefined') {
  87. return null;
  88. }
  89. return (
  90. <PagedList
  91. defaultPage = { _defaultPage }
  92. disabled = { this.props.disabled }
  93. onSelectPage = { this._onSelectPage }
  94. pages = { this.pages } />
  95. );
  96. }
  97. _onSelectPage: number => void;
  98. /**
  99. * Callback for the {@code PagedList} page select action.
  100. *
  101. * @private
  102. * @param {number} pageIndex - The index of the selected page.
  103. * @returns {void}
  104. */
  105. _onSelectPage(pageIndex) {
  106. this.props.dispatch(setWelcomePageListsDefaultPage(pageIndex));
  107. }
  108. }
  109. /**
  110. * Maps (parts of) the redux state to the React {@code Component} props of
  111. * {@code WelcomePageLists}.
  112. *
  113. * @param {Object} state - The redux state.
  114. * @protected
  115. * @returns {{
  116. * _defaultPage: number
  117. * }}
  118. */
  119. function _mapStateToProps(state: Object) {
  120. let { defaultPage } = state['features/welcome'];
  121. if (typeof defaultPage === 'undefined') {
  122. const recentList = state['features/recent-list'];
  123. defaultPage = recentList && recentList.length ? 0 : 1;
  124. }
  125. return {
  126. _defaultPage: defaultPage
  127. };
  128. }
  129. export default translate(connect(_mapStateToProps)(WelcomePageLists));