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

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