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

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