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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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. window.glob_dev_hooks.wp=this
  96. }
  97. /**
  98. * Implements React's {@link Component#componentDidMount()}. Invoked
  99. * immediately after this component is mounted.
  100. *
  101. * @inheritdoc
  102. * @returns {void}
  103. */
  104. componentDidMount() {
  105. super.componentDidMount();
  106. document.body.classList.add('welcome-page');
  107. document.title = interfaceConfig.APP_NAME;
  108. if (this.state.generateRoomnames) {
  109. this._updateRoomname();
  110. }
  111. if (this._shouldShowAdditionalContent()) {
  112. this._additionalContentRef.appendChild(
  113. this._additionalContentTemplate.content.cloneNode(true));
  114. }
  115. if (this._shouldShowAdditionalToolbarContent()) {
  116. this._additionalToolbarContentRef.appendChild(
  117. this._additionalToolbarContentTemplate.content.cloneNode(true)
  118. );
  119. }
  120. }
  121. /**
  122. * Removes the classname used for custom styling of the welcome page.
  123. *
  124. * @inheritdoc
  125. * @returns {void}
  126. */
  127. componentWillUnmount() {
  128. super.componentWillUnmount();
  129. document.body.classList.remove('welcome-page');
  130. }
  131. /**
  132. * Implements React's {@link Component#render()}.
  133. *
  134. * @inheritdoc
  135. * @returns {ReactElement|null}
  136. */
  137. render() {
  138. const { t } = this.props;
  139. const { APP_NAME } = interfaceConfig;
  140. const showAdditionalContent = this._shouldShowAdditionalContent();
  141. const showAdditionalToolbarContent = this._shouldShowAdditionalToolbarContent();
  142. const showResponsiveText = this._shouldShowResponsiveText();
  143. return (
  144. <div
  145. className = { `welcome ${showAdditionalContent
  146. ? 'with-content' : 'without-content'}` }
  147. id = 'welcome_page'>
  148. <div className = 'welcome-watermark'>
  149. <Watermarks />
  150. </div>
  151. <div className = 'header'>
  152. <div className = 'welcome-page-settings'>
  153. <SettingsButton
  154. defaultTab = { SETTINGS_TABS.CALENDAR } />
  155. { showAdditionalToolbarContent
  156. ? <div
  157. className = 'settings-toolbar-content'
  158. ref = { this._setAdditionalToolbarContentRef } />
  159. : null
  160. }
  161. </div>
  162. <div className = 'header-image' />
  163. <div className = 'header-text'>
  164. <h1 className = 'header-text-title'>
  165. { t('welcomepage.title') }
  166. </h1>
  167. <p className = 'header-text-description'>
  168. { t('welcomepage.appDescription',
  169. { app: APP_NAME }) }
  170. </p>
  171. </div>
  172. <div id = 'enter_room'>
  173. <div className = 'enter-room-input-container'>
  174. <div className = 'enter-room-title'>
  175. { t('welcomepage.enterRoomTitle') }
  176. </div>
  177. <form onSubmit = { this._onFormSubmit }>
  178. <input
  179. autoFocus = { true }
  180. className = 'enter-room-input'
  181. id = 'enter_room_field'
  182. onChange = { this._onRoomChange }
  183. pattern = { ROOM_NAME_VALIDATE_PATTERN_STR }
  184. placeholder = { this.state.roomPlaceholder }
  185. ref = { this._setRoomInputRef }
  186. title = { t('welcomepage.roomNameAllowedChars') }
  187. type = 'text'
  188. value = { this.state.room } />
  189. </form>
  190. </div>
  191. <div
  192. className = 'welcome-page-button'
  193. id = 'enter_room_button'
  194. onClick = { this._onFormSubmit }>
  195. {
  196. showResponsiveText
  197. ? t('welcomepage.goSmall')
  198. : t('welcomepage.go')
  199. }
  200. </div>
  201. </div>
  202. { this._renderTabs() }
  203. </div>
  204. { showAdditionalContent
  205. ? <div
  206. className = 'welcome-page-content'
  207. ref = { this._setAdditionalContentRef } />
  208. : null }
  209. </div>
  210. );
  211. }
  212. /**
  213. * Prevents submission of the form and delegates join logic.
  214. *
  215. * @param {Event} event - The HTML Event which details the form submission.
  216. * @private
  217. * @returns {void}
  218. */
  219. _onFormSubmit(event) {
  220. event.preventDefault();
  221. if (!this._roomInputRef || this._roomInputRef.reportValidity()) {
  222. this._onJoin();
  223. }
  224. }
  225. /**
  226. * Overrides the super to account for the differences in the argument types
  227. * provided by HTML and React Native text inputs.
  228. *
  229. * @inheritdoc
  230. * @override
  231. * @param {Event} event - The (HTML) Event which details the change such as
  232. * the EventTarget.
  233. * @protected
  234. */
  235. _onRoomChange(event) {
  236. super._onRoomChange(event.target.value);
  237. }
  238. /**
  239. * Callback invoked when the desired tab to display should be changed.
  240. *
  241. * @param {number} tabIndex - The index of the tab within the array of
  242. * displayed tabs.
  243. * @private
  244. * @returns {void}
  245. */
  246. _onTabSelected(tabIndex) {
  247. this.setState({ selectedTab: tabIndex });
  248. }
  249. /**
  250. * Renders tabs to show previous meetings and upcoming calendar events. The
  251. * tabs are purposefully hidden on mobile browsers.
  252. *
  253. * @returns {ReactElement|null}
  254. */
  255. _renderTabs() {
  256. if (isMobileBrowser()) {
  257. return null;
  258. }
  259. const { _calendarEnabled, _recentListEnabled, t } = this.props;
  260. const tabs = [];
  261. if (_calendarEnabled) {
  262. tabs.push({
  263. label: t('welcomepage.calendar'),
  264. content: <CalendarList />
  265. });
  266. }
  267. if (_recentListEnabled) {
  268. tabs.push({
  269. label: t('welcomepage.recentList'),
  270. content: <RecentList />
  271. });
  272. }
  273. if (tabs.length === 0) {
  274. return null;
  275. }
  276. return (
  277. <Tabs
  278. onSelect = { this._onTabSelected }
  279. selected = { this.state.selectedTab }
  280. tabs = { tabs } />);
  281. }
  282. /**
  283. * Sets the internal reference to the HTMLDivElement used to hold the
  284. * welcome page content.
  285. *
  286. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  287. * of the welcome page content.
  288. * @private
  289. * @returns {void}
  290. */
  291. _setAdditionalContentRef(el) {
  292. this._additionalContentRef = el;
  293. }
  294. /**
  295. * Sets the internal reference to the HTMLDivElement used to hold the
  296. * toolbar additional content.
  297. *
  298. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  299. * of the additional toolbar content.
  300. * @private
  301. * @returns {void}
  302. */
  303. _setAdditionalToolbarContentRef(el) {
  304. this._additionalToolbarContentRef = el;
  305. }
  306. /**
  307. * Sets the internal reference to the HTMLInputElement used to hold the
  308. * welcome page input room element.
  309. *
  310. * @param {HTMLInputElement} el - The HTMLElement for the input of the room name on the welcome page.
  311. * @private
  312. * @returns {void}
  313. */
  314. _setRoomInputRef(el) {
  315. this._roomInputRef = el;
  316. }
  317. /**
  318. * Returns whether or not additional content should be displayed below
  319. * the welcome page's header for entering a room name.
  320. *
  321. * @private
  322. * @returns {boolean}
  323. */
  324. _shouldShowAdditionalContent() {
  325. return interfaceConfig.DISPLAY_WELCOME_PAGE_CONTENT
  326. && this._additionalContentTemplate
  327. && this._additionalContentTemplate.content
  328. && this._additionalContentTemplate.innerHTML.trim();
  329. }
  330. /**
  331. * Returns whether or not additional content should be displayed inside
  332. * the header toolbar.
  333. *
  334. * @private
  335. * @returns {boolean}
  336. */
  337. _shouldShowAdditionalToolbarContent() {
  338. return interfaceConfig.DISPLAY_WELCOME_PAGE_TOOLBAR_ADDITIONAL_CONTENT
  339. && this._additionalToolbarContentTemplate
  340. && this._additionalToolbarContentTemplate.content
  341. && this._additionalToolbarContentTemplate.innerHTML.trim();
  342. }
  343. /**
  344. * Returns whether or not the screen has a size smaller than a custom margin
  345. * and therefore display different text in the go button.
  346. *
  347. * @private
  348. * @returns {boolean}
  349. */
  350. _shouldShowResponsiveText() {
  351. const { innerWidth } = window;
  352. return innerWidth <= WINDOW_WIDTH_THRESHOLD;
  353. }
  354. }
  355. export default translate(connect(_mapStateToProps)(WelcomePage));