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.

WelcomePage.web.js 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. document.title = interfaceConfig.APP_NAME;
  73. if (this.state.generateRoomnames) {
  74. this._updateRoomname();
  75. }
  76. if (this._shouldShowAdditionalContent()) {
  77. this._additionalContentRef.appendChild(
  78. this._additionalContentTemplate.content.cloneNode(true));
  79. }
  80. }
  81. /**
  82. * Removes the classname used for custom styling of the welcome page.
  83. *
  84. * @inheritdoc
  85. * @returns {void}
  86. */
  87. componentWillUnmount() {
  88. super.componentWillUnmount();
  89. document.body.classList.remove('welcome-page');
  90. }
  91. /**
  92. * Implements React's {@link Component#render()}.
  93. *
  94. * @inheritdoc
  95. * @returns {ReactElement|null}
  96. */
  97. render() {
  98. const { t } = this.props;
  99. const { APP_NAME } = interfaceConfig;
  100. const showAdditionalContent = this._shouldShowAdditionalContent();
  101. return (
  102. <div
  103. className = { `welcome ${showAdditionalContent
  104. ? 'with-content' : 'without-content'}` }
  105. id = 'welcome_page'>
  106. <div className = 'welcome-watermark'>
  107. <Watermarks />
  108. </div>
  109. <div className = 'header'>
  110. <div className = 'welcome-page-settings'>
  111. <SettingsButton
  112. defaultTab = { SETTINGS_TABS.CALENDAR } />
  113. </div>
  114. <div className = 'header-image' />
  115. <div className = 'header-text'>
  116. <h1 className = 'header-text-title'>
  117. { t('welcomepage.title') }
  118. </h1>
  119. <p className = 'header-text-description'>
  120. { t('welcomepage.appDescription',
  121. { app: APP_NAME }) }
  122. </p>
  123. </div>
  124. <div id = 'enter_room'>
  125. <div className = 'enter-room-input-container'>
  126. <div className = 'enter-room-title'>
  127. { t('welcomepage.enterRoomTitle') }
  128. </div>
  129. <form onSubmit = { this._onFormSubmit }>
  130. <input
  131. autoFocus = { true }
  132. className = 'enter-room-input'
  133. id = 'enter_room_field'
  134. onChange = { this._onRoomChange }
  135. placeholder
  136. = { this.state.roomPlaceholder }
  137. type = 'text'
  138. value = { this.state.room } />
  139. </form>
  140. </div>
  141. <div
  142. className = 'welcome-page-button'
  143. id = 'enter_room_button'
  144. onClick = { this._onJoin }>
  145. { t('welcomepage.go') }
  146. </div>
  147. </div>
  148. { this._renderTabs() }
  149. </div>
  150. { showAdditionalContent
  151. ? <div
  152. className = 'welcome-page-content'
  153. ref = { this._setAdditionalContentRef } />
  154. : null }
  155. </div>
  156. );
  157. }
  158. /**
  159. * Prevents submission of the form and delegates join logic.
  160. *
  161. * @param {Event} event - The HTML Event which details the form submission.
  162. * @private
  163. * @returns {void}
  164. */
  165. _onFormSubmit(event) {
  166. event.preventDefault();
  167. this._onJoin();
  168. }
  169. /**
  170. * Overrides the super to account for the differences in the argument types
  171. * provided by HTML and React Native text inputs.
  172. *
  173. * @inheritdoc
  174. * @override
  175. * @param {Event} event - The (HTML) Event which details the change such as
  176. * the EventTarget.
  177. * @protected
  178. */
  179. _onRoomChange(event) {
  180. super._onRoomChange(event.target.value);
  181. }
  182. /**
  183. * Callback invoked when the desired tab to display should be changed.
  184. *
  185. * @param {number} tabIndex - The index of the tab within the array of
  186. * displayed tabs.
  187. * @private
  188. * @returns {void}
  189. */
  190. _onTabSelected(tabIndex) {
  191. this.setState({ selectedTab: tabIndex });
  192. }
  193. /**
  194. * Renders tabs to show previous meetings and upcoming calendar events. The
  195. * tabs are purposefully hidden on mobile browsers.
  196. *
  197. * @returns {ReactElement|null}
  198. */
  199. _renderTabs() {
  200. const isMobileBrowser
  201. = Platform.OS === 'android' || Platform.OS === 'ios';
  202. if (isMobileBrowser) {
  203. return null;
  204. }
  205. const { _calendarEnabled, t } = this.props;
  206. const tabs = [];
  207. if (_calendarEnabled) {
  208. tabs.push({
  209. label: t('welcomepage.calendar'),
  210. content: <CalendarList />
  211. });
  212. }
  213. tabs.push({
  214. label: t('welcomepage.recentList'),
  215. content: <RecentList />
  216. });
  217. return (
  218. <Tabs
  219. onSelect = { this._onTabSelected }
  220. selected = { this.state.selectedTab }
  221. tabs = { tabs } />);
  222. }
  223. /**
  224. * Sets the internal reference to the HTMLDivElement used to hold the
  225. * welcome page content.
  226. *
  227. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  228. * of the welcome page content.
  229. * @private
  230. * @returns {void}
  231. */
  232. _setAdditionalContentRef(el) {
  233. this._additionalContentRef = el;
  234. }
  235. /**
  236. * Returns whether or not additional content should be displayed below
  237. * the welcome page's header for entering a room name.
  238. *
  239. * @private
  240. * @returns {boolean}
  241. */
  242. _shouldShowAdditionalContent() {
  243. return interfaceConfig.DISPLAY_WELCOME_PAGE_CONTENT
  244. && this._additionalContentTemplate
  245. && this._additionalContentTemplate.content
  246. && this._additionalContentTemplate.innerHTML.trim();
  247. }
  248. }
  249. export default translate(connect(_mapStateToProps)(WelcomePage));