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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. id = 'enter_room_field'
  134. onChange = { this._onRoomChange }
  135. pattern = '^[a-zA-Z0-9=\?]+$'
  136. placeholder = { this.state.roomPlaceholder }
  137. title = { t('welcomepage.onlyAsciiAllowed') }
  138. type = 'text'
  139. value = { this.state.room } />
  140. </form>
  141. </div>
  142. <div
  143. className = 'welcome-page-button'
  144. id = 'enter_room_button'
  145. onClick = { this._onJoin }>
  146. { t('welcomepage.go') }
  147. </div>
  148. </div>
  149. { this._renderTabs() }
  150. </div>
  151. { showAdditionalContent
  152. ? <div
  153. className = 'welcome-page-content'
  154. ref = { this._setAdditionalContentRef } />
  155. : null }
  156. </div>
  157. );
  158. }
  159. /**
  160. * Prevents submission of the form and delegates join logic.
  161. *
  162. * @param {Event} event - The HTML Event which details the form submission.
  163. * @private
  164. * @returns {void}
  165. */
  166. _onFormSubmit(event) {
  167. event.preventDefault();
  168. this._onJoin();
  169. }
  170. /**
  171. * Overrides the super to account for the differences in the argument types
  172. * provided by HTML and React Native text inputs.
  173. *
  174. * @inheritdoc
  175. * @override
  176. * @param {Event} event - The (HTML) Event which details the change such as
  177. * the EventTarget.
  178. * @protected
  179. */
  180. _onRoomChange(event) {
  181. super._onRoomChange(event.target.value);
  182. }
  183. /**
  184. * Callback invoked when the desired tab to display should be changed.
  185. *
  186. * @param {number} tabIndex - The index of the tab within the array of
  187. * displayed tabs.
  188. * @private
  189. * @returns {void}
  190. */
  191. _onTabSelected(tabIndex) {
  192. this.setState({ selectedTab: tabIndex });
  193. }
  194. /**
  195. * Renders tabs to show previous meetings and upcoming calendar events. The
  196. * tabs are purposefully hidden on mobile browsers.
  197. *
  198. * @returns {ReactElement|null}
  199. */
  200. _renderTabs() {
  201. const isMobileBrowser
  202. = Platform.OS === 'android' || Platform.OS === 'ios';
  203. if (isMobileBrowser) {
  204. return null;
  205. }
  206. const { _calendarEnabled, t } = this.props;
  207. const tabs = [];
  208. if (_calendarEnabled) {
  209. tabs.push({
  210. label: t('welcomepage.calendar'),
  211. content: <CalendarList />
  212. });
  213. }
  214. tabs.push({
  215. label: t('welcomepage.recentList'),
  216. content: <RecentList />
  217. });
  218. return (
  219. <Tabs
  220. onSelect = { this._onTabSelected }
  221. selected = { this.state.selectedTab }
  222. tabs = { tabs } />);
  223. }
  224. /**
  225. * Sets the internal reference to the HTMLDivElement used to hold the
  226. * welcome page content.
  227. *
  228. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  229. * of the welcome page content.
  230. * @private
  231. * @returns {void}
  232. */
  233. _setAdditionalContentRef(el) {
  234. this._additionalContentRef = el;
  235. }
  236. /**
  237. * Returns whether or not additional content should be displayed below
  238. * the welcome page's header for entering a room name.
  239. *
  240. * @private
  241. * @returns {boolean}
  242. */
  243. _shouldShowAdditionalContent() {
  244. return interfaceConfig.DISPLAY_WELCOME_PAGE_CONTENT
  245. && this._additionalContentTemplate
  246. && this._additionalContentTemplate.content
  247. && this._additionalContentTemplate.innerHTML.trim();
  248. }
  249. }
  250. export default translate(connect(_mapStateToProps)(WelcomePage));