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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 { 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._onRoomChange = this._onRoomChange.bind(this);
  48. this._setAdditionalContentRef
  49. = this._setAdditionalContentRef.bind(this);
  50. }
  51. /**
  52. * Implements React's {@link Component#componentDidMount()}. Invoked
  53. * immediately after this component is mounted.
  54. *
  55. * @inheritdoc
  56. * @returns {void}
  57. */
  58. componentDidMount() {
  59. if (this.state.generateRoomnames) {
  60. this._updateRoomname();
  61. }
  62. if (this._shouldShowAdditionalContent()) {
  63. this._additionalContentRef.appendChild(
  64. this._additionalContentTemplate.content.cloneNode(true));
  65. }
  66. }
  67. /**
  68. * Implements React's {@link Component#render()}.
  69. *
  70. * @inheritdoc
  71. * @returns {ReactElement|null}
  72. */
  73. render() {
  74. const { t } = this.props;
  75. const { APP_NAME } = interfaceConfig;
  76. const showAdditionalContent = this._shouldShowAdditionalContent();
  77. return (
  78. <AtlasKitThemeProvider mode = 'light'>
  79. <div
  80. className = { `welcome ${showAdditionalContent
  81. ? 'with-content' : 'without-content'}` }
  82. id = 'new_welcome_page'>
  83. <div className = 'header'>
  84. <div className = 'header-image' />
  85. <Watermarks />
  86. <div className = 'header-text'>
  87. <h1 className = 'header-text-title'>
  88. { t('welcomepage.title') }
  89. </h1>
  90. <p className = 'header-text-description'>
  91. { t('welcomepage.appDescription',
  92. { app: APP_NAME }) }
  93. </p>
  94. </div>
  95. <div id = 'new_enter_room'>
  96. <form
  97. className = 'enter-room-input'
  98. onSubmit = { this._onJoin }>
  99. <FieldTextStateless
  100. autoFocus = { true }
  101. id = 'enter_room_field'
  102. isLabelHidden = { true }
  103. label = 'enter_room_field'
  104. onChange = { this._onRoomChange }
  105. placeholder = { this.state.roomPlaceholder }
  106. shouldFitContainer = { true }
  107. type = 'text'
  108. value = { this.state.room } />
  109. </form>
  110. <Button
  111. appearance = 'primary'
  112. className = 'welcome-page-button'
  113. id = 'enter_room_button'
  114. onClick = { this._onJoin }
  115. type = 'button'>
  116. { t('welcomepage.go') }
  117. </Button>
  118. </div>
  119. </div>
  120. { showAdditionalContent
  121. ? <div
  122. className = 'welcome-page-content'
  123. ref = { this._setAdditionalContentRef } />
  124. : null }
  125. </div>
  126. </AtlasKitThemeProvider>
  127. );
  128. }
  129. /**
  130. * Overrides the super to account for the differences in the argument types
  131. * provided by HTML and React Native text inputs.
  132. *
  133. * @inheritdoc
  134. * @override
  135. * @param {Event} event - The (HTML) Event which details the change such as
  136. * the EventTarget.
  137. * @protected
  138. */
  139. _onRoomChange(event) {
  140. super._onRoomChange(event.target.value);
  141. }
  142. /**
  143. * Sets the internal reference to the HTMLDivElement used to hold the
  144. * welcome page content.
  145. *
  146. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  147. * of the welcome page content.
  148. * @private
  149. * @returns {void}
  150. */
  151. _setAdditionalContentRef(el) {
  152. this._additionalContentRef = el;
  153. }
  154. /**
  155. * Returns whether or not additional content should be displayed belowed
  156. * the welcome page's header for entering a room name.
  157. *
  158. * @private
  159. * @returns {boolean}
  160. */
  161. _shouldShowAdditionalContent() {
  162. return interfaceConfig.DISPLAY_WELCOME_PAGE_CONTENT
  163. && this._additionalContentTemplate
  164. && this._additionalContentTemplate.content
  165. && this._additionalContentTemplate.innerHTML.trim();
  166. }
  167. }
  168. export default translate(connect(_mapStateToProps)(WelcomePage));