Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

WelcomePage.web.js 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /* global interfaceConfig */
  2. import React from 'react';
  3. import { translate } from '../../base/i18n';
  4. import { Platform, Watermarks } from '../../base/react';
  5. import { connect } from '../../base/redux';
  6. import { CalendarList } from '../../calendar-sync';
  7. import { RecentList } from '../../recent-list';
  8. import { SettingsButton, SETTINGS_TABS } from '../../settings';
  9. import { AbstractWelcomePage, _mapStateToProps } from './AbstractWelcomePage';
  10. import Tabs from './Tabs';
  11. /**
  12. * The Web container rendering the welcome page.
  13. *
  14. * @extends AbstractWelcomePage
  15. */
  16. class WelcomePage extends AbstractWelcomePage {
  17. /**
  18. * Default values for {@code WelcomePage} component's properties.
  19. *
  20. * @static
  21. */
  22. static defaultProps = {
  23. _room: ''
  24. };
  25. /**
  26. * Initializes a new WelcomePage instance.
  27. *
  28. * @param {Object} props - The read-only properties with which the new
  29. * instance is to be initialized.
  30. */
  31. constructor(props) {
  32. super(props);
  33. this.state = {
  34. ...this.state,
  35. generateRoomnames:
  36. interfaceConfig.GENERATE_ROOMNAMES_ON_WELCOME_PAGE,
  37. selectedTab: 0
  38. };
  39. /**
  40. * The HTML Element used as the container for additional content. Used
  41. * for directly appending the additional content template to the dom.
  42. *
  43. * @private
  44. * @type {HTMLTemplateElement|null}
  45. */
  46. this._additionalContentRef = null;
  47. /**
  48. * The template to use as the main content for the welcome page. If
  49. * not found then only the welcome page head will display.
  50. *
  51. * @private
  52. * @type {HTMLTemplateElement|null}
  53. */
  54. this._additionalContentTemplate = document.getElementById(
  55. 'welcome-page-additional-content-template');
  56. // Bind event handlers so they are only bound once per instance.
  57. this._onFormSubmit = this._onFormSubmit.bind(this);
  58. this._onRoomChange = this._onRoomChange.bind(this);
  59. this._setAdditionalContentRef
  60. = this._setAdditionalContentRef.bind(this);
  61. this._onTabSelected = this._onTabSelected.bind(this);
  62. }
  63. /**
  64. * Implements React's {@link Component#componentDidMount()}. Invoked
  65. * immediately after this component is mounted.
  66. *
  67. * @inheritdoc
  68. * @returns {void}
  69. */
  70. componentDidMount() {
  71. document.body.classList.add('welcome-page');
  72. if (this.state.generateRoomnames) {
  73. this._updateRoomname();
  74. }
  75. if (this._shouldShowAdditionalContent()) {
  76. this._additionalContentRef.appendChild(
  77. this._additionalContentTemplate.content.cloneNode(true));
  78. }
  79. }
  80. /**
  81. * Removes the classname used for custom styling of the welcome page.
  82. *
  83. * @inheritdoc
  84. * @returns {void}
  85. */
  86. componentWillUnmount() {
  87. super.componentWillUnmount();
  88. document.body.classList.remove('welcome-page');
  89. }
  90. /**
  91. * Implements React's {@link Component#render()}.
  92. *
  93. * @inheritdoc
  94. * @returns {ReactElement|null}
  95. */
  96. render() {
  97. const { t } = this.props;
  98. const { APP_NAME } = interfaceConfig;
  99. const showAdditionalContent = this._shouldShowAdditionalContent();
  100. return (
  101. <div
  102. className = { `welcome ${showAdditionalContent
  103. ? 'with-content' : 'without-content'}` }
  104. id = 'welcome_page'>
  105. <Watermarks />
  106. <div className = 'header'>
  107. <div className = 'welcome-page-settings'>
  108. <SettingsButton
  109. defaultTab = { SETTINGS_TABS.CALENDAR } />
  110. </div>
  111. <div className = 'header-image' />
  112. <div className = 'header-text'>
  113. <h1 className = 'header-text-title'>
  114. { t('welcomepage.title') }
  115. </h1>
  116. <p className = 'header-text-description'>
  117. { t('welcomepage.appDescription',
  118. { app: APP_NAME }) }
  119. </p>
  120. </div>
  121. <div id = 'enter_room'>
  122. <div className = 'enter-room-input-container'>
  123. <div className = 'enter-room-title'>
  124. { t('welcomepage.enterRoomTitle') }
  125. </div>
  126. <form onSubmit = { this._onFormSubmit }>
  127. <input
  128. autoFocus = { true }
  129. className = 'enter-room-input'
  130. id = 'enter_room_field'
  131. onChange = { this._onRoomChange }
  132. placeholder
  133. = { this.state.roomPlaceholder }
  134. type = 'text'
  135. value = { this.state.room } />
  136. </form>
  137. </div>
  138. <div
  139. className = 'welcome-page-button'
  140. id = 'enter_room_button'
  141. onClick = { this._onJoin }>
  142. { t('welcomepage.go') }
  143. </div>
  144. </div>
  145. { this._renderTabs() }
  146. </div>
  147. { showAdditionalContent
  148. ? <div
  149. className = 'welcome-page-content'
  150. ref = { this._setAdditionalContentRef } />
  151. : null }
  152. </div>
  153. );
  154. }
  155. /**
  156. * Prevents submission of the form and delegates join logic.
  157. *
  158. * @param {Event} event - The HTML Event which details the form submission.
  159. * @private
  160. * @returns {void}
  161. */
  162. _onFormSubmit(event) {
  163. event.preventDefault();
  164. this._onJoin();
  165. }
  166. /**
  167. * Overrides the super to account for the differences in the argument types
  168. * provided by HTML and React Native text inputs.
  169. *
  170. * @inheritdoc
  171. * @override
  172. * @param {Event} event - The (HTML) Event which details the change such as
  173. * the EventTarget.
  174. * @protected
  175. */
  176. _onRoomChange(event) {
  177. super._onRoomChange(event.target.value);
  178. }
  179. /**
  180. * Callback invoked when the desired tab to display should be changed.
  181. *
  182. * @param {number} tabIndex - The index of the tab within the array of
  183. * displayed tabs.
  184. * @private
  185. * @returns {void}
  186. */
  187. _onTabSelected(tabIndex) {
  188. this.setState({ selectedTab: tabIndex });
  189. }
  190. /**
  191. * Renders tabs to show previous meetings and upcoming calendar events. The
  192. * tabs are purposefully hidden on mobile browsers.
  193. *
  194. * @returns {ReactElement|null}
  195. */
  196. _renderTabs() {
  197. const isMobileBrowser
  198. = Platform.OS === 'android' || Platform.OS === 'ios';
  199. if (isMobileBrowser) {
  200. return null;
  201. }
  202. const { t } = this.props;
  203. const tabs = [];
  204. if (CalendarList) {
  205. tabs.push({
  206. label: t('welcomepage.calendar'),
  207. content: <CalendarList />
  208. });
  209. }
  210. tabs.push({
  211. label: t('welcomepage.recentList'),
  212. content: <RecentList />
  213. });
  214. return (
  215. <Tabs
  216. onSelect = { this._onTabSelected }
  217. selected = { this.state.selectedTab }
  218. tabs = { tabs } />);
  219. }
  220. /**
  221. * Sets the internal reference to the HTMLDivElement used to hold the
  222. * welcome page content.
  223. *
  224. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  225. * of the welcome page content.
  226. * @private
  227. * @returns {void}
  228. */
  229. _setAdditionalContentRef(el) {
  230. this._additionalContentRef = el;
  231. }
  232. /**
  233. * Returns whether or not additional content should be displayed below
  234. * the welcome page's header for entering a room name.
  235. *
  236. * @private
  237. * @returns {boolean}
  238. */
  239. _shouldShowAdditionalContent() {
  240. return interfaceConfig.DISPLAY_WELCOME_PAGE_CONTENT
  241. && this._additionalContentTemplate
  242. && this._additionalContentTemplate.content
  243. && this._additionalContentTemplate.innerHTML.trim();
  244. }
  245. }
  246. export default translate(connect(_mapStateToProps)(WelcomePage));