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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /* global interfaceConfig */
  2. import React from 'react';
  3. import { translate } from '../../base/i18n';
  4. import { Watermarks } from '../../base/react';
  5. import { connect } from '../../base/redux';
  6. import { isMobileBrowser } from '../../base/environment/utils';
  7. import { CalendarList } from '../../calendar-sync';
  8. import { RecentList } from '../../recent-list';
  9. import { SettingsButton, SETTINGS_TABS } from '../../settings';
  10. import { AbstractWelcomePage, _mapStateToProps } from './AbstractWelcomePage';
  11. import Tabs from './Tabs';
  12. /**
  13. * The pattern used to validate room name.
  14. * @type {string}
  15. */
  16. export const ROOM_NAME_VALIDATE_PATTERN_STR = '^[^?&:\u0022\u0027%#]+$';
  17. /**
  18. * Maximum number of pixels corresponding to a mobile layout.
  19. * @type {number}
  20. */
  21. const WINDOW_WIDTH_THRESHOLD = 425;
  22. /**
  23. * The Web container rendering the welcome page.
  24. *
  25. * @extends AbstractWelcomePage
  26. */
  27. class WelcomePage extends AbstractWelcomePage {
  28. /**
  29. * Default values for {@code WelcomePage} component's properties.
  30. *
  31. * @static
  32. */
  33. static defaultProps = {
  34. _room: ''
  35. };
  36. /**
  37. * Initializes a new WelcomePage instance.
  38. *
  39. * @param {Object} props - The read-only properties with which the new
  40. * instance is to be initialized.
  41. */
  42. constructor(props) {
  43. super(props);
  44. this.state = {
  45. ...this.state,
  46. generateRoomnames:
  47. interfaceConfig.GENERATE_ROOMNAMES_ON_WELCOME_PAGE,
  48. selectedTab: 0
  49. };
  50. /**
  51. * The HTML Element used as the container for additional content. Used
  52. * for directly appending the additional content template to the dom.
  53. *
  54. * @private
  55. * @type {HTMLTemplateElement|null}
  56. */
  57. this._additionalContentRef = null;
  58. this._roomInputRef = null;
  59. /**
  60. * The HTML Element used as the container for additional toolbar content. Used
  61. * for directly appending the additional content template to the dom.
  62. *
  63. * @private
  64. * @type {HTMLTemplateElement|null}
  65. */
  66. this._additionalToolbarContentRef = null;
  67. /**
  68. * The template to use as the main content for the welcome page. If
  69. * not found then only the welcome page head will display.
  70. *
  71. * @private
  72. * @type {HTMLTemplateElement|null}
  73. */
  74. this._additionalContentTemplate = document.getElementById(
  75. 'welcome-page-additional-content-template');
  76. /**
  77. * The template to use as the additional content for the welcome page header toolbar.
  78. * If not found then only the settings icon will be displayed.
  79. *
  80. * @private
  81. * @type {HTMLTemplateElement|null}
  82. */
  83. this._additionalToolbarContentTemplate = document.getElementById(
  84. 'settings-toolbar-additional-content-template'
  85. );
  86. // Bind event handlers so they are only bound once per instance.
  87. this._onFormSubmit = this._onFormSubmit.bind(this);
  88. this._onRoomChange = this._onRoomChange.bind(this);
  89. this._setAdditionalContentRef
  90. = this._setAdditionalContentRef.bind(this);
  91. this._setRoomInputRef = this._setRoomInputRef.bind(this);
  92. this._setAdditionalToolbarContentRef
  93. = this._setAdditionalToolbarContentRef.bind(this);
  94. this._onTabSelected = this._onTabSelected.bind(this);
  95. }
  96. /**
  97. * Implements React's {@link Component#componentDidMount()}. Invoked
  98. * immediately after this component is mounted.
  99. *
  100. * @inheritdoc
  101. * @returns {void}
  102. */
  103. componentDidMount() {
  104. super.componentDidMount();
  105. document.body.classList.add('welcome-page');
  106. document.title = interfaceConfig.APP_NAME;
  107. if (this.state.generateRoomnames) {
  108. this._updateRoomname();
  109. }
  110. if (this._shouldShowAdditionalContent()) {
  111. this._additionalContentRef.appendChild(
  112. this._additionalContentTemplate.content.cloneNode(true));
  113. }
  114. if (this._shouldShowAdditionalToolbarContent()) {
  115. this._additionalToolbarContentRef.appendChild(
  116. this._additionalToolbarContentTemplate.content.cloneNode(true)
  117. );
  118. }
  119. }
  120. /**
  121. * Removes the classname used for custom styling of the welcome page.
  122. *
  123. * @inheritdoc
  124. * @returns {void}
  125. */
  126. componentWillUnmount() {
  127. super.componentWillUnmount();
  128. document.body.classList.remove('welcome-page');
  129. }
  130. /**
  131. * Implements React's {@link Component#render()}.
  132. *
  133. * @inheritdoc
  134. * @returns {ReactElement|null}
  135. */
  136. render() {
  137. const { t } = this.props;
  138. const { APP_NAME } = interfaceConfig;
  139. const showAdditionalContent = this._shouldShowAdditionalContent();
  140. const showAdditionalToolbarContent = this._shouldShowAdditionalToolbarContent();
  141. const showResponsiveText = this._shouldShowResponsiveText();
  142. return (
  143. <div
  144. className = { `welcome ${showAdditionalContent
  145. ? 'with-content' : 'without-content'}` }
  146. id = 'welcome_page'>
  147. <div className = 'welcome-watermark'>
  148. <Watermarks />
  149. </div>
  150. <div className = 'header'>
  151. <div className = 'welcome-page-settings'>
  152. <SettingsButton
  153. defaultTab = { SETTINGS_TABS.CALENDAR } />
  154. { showAdditionalToolbarContent
  155. ? <div
  156. className = 'settings-toolbar-content'
  157. ref = { this._setAdditionalToolbarContentRef } />
  158. : null
  159. }
  160. </div>
  161. <div className = 'header-image' />
  162. <div className = 'header-text'>
  163. <h1 className = 'header-text-title'>
  164. { t('welcomepage.title') }
  165. </h1>
  166. <p className = 'header-text-description'>
  167. { t('welcomepage.appDescription',
  168. { app: APP_NAME }) }
  169. </p>
  170. </div>
  171. <div id = 'enter_room'>
  172. <div className = 'enter-room-input-container'>
  173. <div className = 'enter-room-title'>
  174. { t('welcomepage.enterRoomTitle') }
  175. </div>
  176. <form onSubmit = { this._onFormSubmit }>
  177. <input
  178. autoFocus = { true }
  179. className = 'enter-room-input'
  180. id = 'enter_room_field'
  181. onChange = { this._onRoomChange }
  182. pattern = { ROOM_NAME_VALIDATE_PATTERN_STR }
  183. placeholder = { this.state.roomPlaceholder }
  184. ref = { this._setRoomInputRef }
  185. title = { t('welcomepage.roomNameAllowedChars') }
  186. type = 'text'
  187. value = { this.state.room } />
  188. </form>
  189. </div>
  190. <div
  191. className = 'welcome-page-button'
  192. id = 'enter_room_button'
  193. onClick = { this._onFormSubmit }>
  194. {
  195. showResponsiveText
  196. ? t('welcomepage.goSmall')
  197. : t('welcomepage.go')
  198. }
  199. </div>
  200. </div>
  201. { this._renderTabs() }
  202. </div>
  203. { showAdditionalContent
  204. ? <div
  205. className = 'welcome-page-content'
  206. ref = { this._setAdditionalContentRef } />
  207. : null }
  208. </div>
  209. );
  210. }
  211. /**
  212. * Prevents submission of the form and delegates join logic.
  213. *
  214. * @param {Event} event - The HTML Event which details the form submission.
  215. * @private
  216. * @returns {void}
  217. */
  218. _onFormSubmit(event) {
  219. event.preventDefault();
  220. if (!this._roomInputRef || this._roomInputRef.reportValidity()) {
  221. this._onJoin();
  222. }
  223. }
  224. /**
  225. * Overrides the super to account for the differences in the argument types
  226. * provided by HTML and React Native text inputs.
  227. *
  228. * @inheritdoc
  229. * @override
  230. * @param {Event} event - The (HTML) Event which details the change such as
  231. * the EventTarget.
  232. * @protected
  233. */
  234. _onRoomChange(event) {
  235. super._onRoomChange(event.target.value);
  236. }
  237. /**
  238. * Callback invoked when the desired tab to display should be changed.
  239. *
  240. * @param {number} tabIndex - The index of the tab within the array of
  241. * displayed tabs.
  242. * @private
  243. * @returns {void}
  244. */
  245. _onTabSelected(tabIndex) {
  246. this.setState({ selectedTab: tabIndex });
  247. }
  248. /**
  249. * Renders tabs to show previous meetings and upcoming calendar events. The
  250. * tabs are purposefully hidden on mobile browsers.
  251. *
  252. * @returns {ReactElement|null}
  253. */
  254. _renderTabs() {
  255. if (isMobileBrowser()) {
  256. return null;
  257. }
  258. const { _calendarEnabled, _recentListEnabled, t } = this.props;
  259. const tabs = [];
  260. if (_calendarEnabled) {
  261. tabs.push({
  262. label: t('welcomepage.calendar'),
  263. content: <CalendarList />
  264. });
  265. }
  266. if (_recentListEnabled) {
  267. tabs.push({
  268. label: t('welcomepage.recentList'),
  269. content: <RecentList />
  270. });
  271. }
  272. if (tabs.length === 0) {
  273. return null;
  274. }
  275. return (
  276. <Tabs
  277. onSelect = { this._onTabSelected }
  278. selected = { this.state.selectedTab }
  279. tabs = { tabs } />);
  280. }
  281. /**
  282. * Sets the internal reference to the HTMLDivElement used to hold the
  283. * welcome page content.
  284. *
  285. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  286. * of the welcome page content.
  287. * @private
  288. * @returns {void}
  289. */
  290. _setAdditionalContentRef(el) {
  291. this._additionalContentRef = el;
  292. }
  293. /**
  294. * Sets the internal reference to the HTMLDivElement used to hold the
  295. * toolbar additional content.
  296. *
  297. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  298. * of the additional toolbar content.
  299. * @private
  300. * @returns {void}
  301. */
  302. _setAdditionalToolbarContentRef(el) {
  303. this._additionalToolbarContentRef = el;
  304. }
  305. /**
  306. * Sets the internal reference to the HTMLInputElement used to hold the
  307. * welcome page input room element.
  308. *
  309. * @param {HTMLInputElement} el - The HTMLElement for the input of the room name on the welcome page.
  310. * @private
  311. * @returns {void}
  312. */
  313. _setRoomInputRef(el) {
  314. this._roomInputRef = el;
  315. }
  316. /**
  317. * Returns whether or not additional content should be displayed below
  318. * the welcome page's header for entering a room name.
  319. *
  320. * @private
  321. * @returns {boolean}
  322. */
  323. _shouldShowAdditionalContent() {
  324. return interfaceConfig.DISPLAY_WELCOME_PAGE_CONTENT
  325. && this._additionalContentTemplate
  326. && this._additionalContentTemplate.content
  327. && this._additionalContentTemplate.innerHTML.trim();
  328. }
  329. /**
  330. * Returns whether or not additional content should be displayed inside
  331. * the header toolbar.
  332. *
  333. * @private
  334. * @returns {boolean}
  335. */
  336. _shouldShowAdditionalToolbarContent() {
  337. return interfaceConfig.DISPLAY_WELCOME_PAGE_TOOLBAR_ADDITIONAL_CONTENT
  338. && this._additionalToolbarContentTemplate
  339. && this._additionalToolbarContentTemplate.content
  340. && this._additionalToolbarContentTemplate.innerHTML.trim();
  341. }
  342. /**
  343. * Returns whether or not the screen has a size smaller than a custom margin
  344. * and therefore display different text in the go button.
  345. *
  346. * @private
  347. * @returns {boolean}
  348. */
  349. _shouldShowResponsiveText() {
  350. const { innerWidth } = window;
  351. return innerWidth <= WINDOW_WIDTH_THRESHOLD;
  352. }
  353. }
  354. export default translate(connect(_mapStateToProps)(WelcomePage));