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

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