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

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