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

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