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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* global interfaceConfig */
  2. import Button from '@atlaskit/button';
  3. import { FieldTextStateless } from '@atlaskit/field-text';
  4. import { AtlasKitThemeProvider } from '@atlaskit/theme';
  5. import React from 'react';
  6. import { connect } from 'react-redux';
  7. import { translate } from '../../base/i18n';
  8. import { HideNotificationBarStyle, Watermarks } from '../../base/react';
  9. import { AbstractWelcomePage, _mapStateToProps } from './AbstractWelcomePage';
  10. /**
  11. * The Web container rendering the welcome page.
  12. *
  13. * @extends AbstractWelcomePage
  14. */
  15. class WelcomePage extends AbstractWelcomePage {
  16. /**
  17. * Initializes a new WelcomePage instance.
  18. *
  19. * @param {Object} props - The read-only properties with which the new
  20. * instance is to be initialized.
  21. */
  22. constructor(props) {
  23. super(props);
  24. this.state = {
  25. ...this.state,
  26. generateRoomnames:
  27. interfaceConfig.GENERATE_ROOMNAMES_ON_WELCOME_PAGE
  28. };
  29. /**
  30. * The HTML Element used as the container for additional content. Used
  31. * for directly appending the additional content template to the dom
  32. *
  33. * @private
  34. * @type {HTMLTemplateElement|null}
  35. */
  36. this._additionalContentRef = null;
  37. /**
  38. * The template to use as the main content for the welcome page. If
  39. * not found then only the welcome page head will display.
  40. *
  41. * @private
  42. * @type {HTMLTemplateElement|null}
  43. */
  44. this._additionalContentTemplate = document.getElementById(
  45. 'welcome-page-additional-content-template');
  46. // Bind event handlers so they are only bound once per instance.
  47. this._onFormSubmit = this._onFormSubmit.bind(this);
  48. this._onRoomChange = this._onRoomChange.bind(this);
  49. this._setAdditionalContentRef
  50. = this._setAdditionalContentRef.bind(this);
  51. }
  52. /**
  53. * Implements React's {@link Component#componentDidMount()}. Invoked
  54. * immediately after this component is mounted.
  55. *
  56. * @inheritdoc
  57. * @returns {void}
  58. */
  59. componentDidMount() {
  60. document.body.classList.add('welcome-page');
  61. if (this.state.generateRoomnames) {
  62. this._updateRoomname();
  63. }
  64. if (this._shouldShowAdditionalContent()) {
  65. this._additionalContentRef.appendChild(
  66. this._additionalContentTemplate.content.cloneNode(true));
  67. }
  68. }
  69. /**
  70. * Removes the classname used for custom styling of the welcome page.
  71. *
  72. * @inheritdoc
  73. * @returns {void}
  74. */
  75. componentWillUnmount() {
  76. super.componentWillUnmount();
  77. document.body.classList.remove('welcome-page');
  78. }
  79. /**
  80. * Implements React's {@link Component#render()}.
  81. *
  82. * @inheritdoc
  83. * @returns {ReactElement|null}
  84. */
  85. render() {
  86. const { t } = this.props;
  87. const { APP_NAME } = interfaceConfig;
  88. const showAdditionalContent = this._shouldShowAdditionalContent();
  89. return (
  90. <AtlasKitThemeProvider mode = 'light'>
  91. <div
  92. className = { `welcome ${showAdditionalContent
  93. ? 'with-content' : 'without-content'}` }
  94. id = 'new_welcome_page'>
  95. <div className = 'header'>
  96. <div className = 'header-image' />
  97. <Watermarks />
  98. <div className = 'header-text'>
  99. <h1 className = 'header-text-title'>
  100. { t('welcomepage.title') }
  101. </h1>
  102. <p className = 'header-text-description'>
  103. { t('welcomepage.appDescription',
  104. { app: APP_NAME }) }
  105. </p>
  106. </div>
  107. <div id = 'new_enter_room'>
  108. <form
  109. className = 'enter-room-input'
  110. onSubmit = { this._onFormSubmit }>
  111. <FieldTextStateless
  112. autoFocus = { true }
  113. id = 'enter_room_field'
  114. isLabelHidden = { true }
  115. label = 'enter_room_field'
  116. onChange = { this._onRoomChange }
  117. placeholder = { this.state.roomPlaceholder }
  118. shouldFitContainer = { true }
  119. type = 'text'
  120. value = { this.state.room } />
  121. </form>
  122. <Button
  123. appearance = 'primary'
  124. className = 'welcome-page-button'
  125. id = 'enter_room_button'
  126. onClick = { this._onJoin }
  127. type = 'button'>
  128. { t('welcomepage.go') }
  129. </Button>
  130. </div>
  131. </div>
  132. { showAdditionalContent
  133. ? <div
  134. className = 'welcome-page-content'
  135. ref = { this._setAdditionalContentRef } />
  136. : null }
  137. </div>
  138. <HideNotificationBarStyle />
  139. </AtlasKitThemeProvider>
  140. );
  141. }
  142. /**
  143. * Prevents submission of the form and delagates join logic.
  144. *
  145. * @param {Event} event - The HTML Event which details the form submission.
  146. * @private
  147. * @returns {void}
  148. */
  149. _onFormSubmit(event) {
  150. event.preventDefault();
  151. this._onJoin();
  152. }
  153. /**
  154. * Overrides the super to account for the differences in the argument types
  155. * provided by HTML and React Native text inputs.
  156. *
  157. * @inheritdoc
  158. * @override
  159. * @param {Event} event - The (HTML) Event which details the change such as
  160. * the EventTarget.
  161. * @protected
  162. */
  163. _onRoomChange(event) {
  164. super._onRoomChange(event.target.value);
  165. }
  166. /**
  167. * Sets the internal reference to the HTMLDivElement used to hold the
  168. * welcome page content.
  169. *
  170. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  171. * of the welcome page content.
  172. * @private
  173. * @returns {void}
  174. */
  175. _setAdditionalContentRef(el) {
  176. this._additionalContentRef = el;
  177. }
  178. /**
  179. * Returns whether or not additional content should be displayed belowed
  180. * the welcome page's header for entering a room name.
  181. *
  182. * @private
  183. * @returns {boolean}
  184. */
  185. _shouldShowAdditionalContent() {
  186. return interfaceConfig.DISPLAY_WELCOME_PAGE_CONTENT
  187. && this._additionalContentTemplate
  188. && this._additionalContentTemplate.content
  189. && this._additionalContentTemplate.innerHTML.trim();
  190. }
  191. }
  192. export default translate(connect(_mapStateToProps)(WelcomePage));