您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

WelcomePage.web.js 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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._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 = 'welcome_page'>
  95. <div className = 'welcome-watermark'>
  96. <Watermarks />
  97. </div>
  98. <div className = 'header'>
  99. <div className = 'header-image' />
  100. <div className = 'header-text'>
  101. <h1 className = 'header-text-title'>
  102. { t('welcomepage.title') }
  103. </h1>
  104. <p className = 'header-text-description'>
  105. { t('welcomepage.appDescription',
  106. { app: APP_NAME }) }
  107. </p>
  108. </div>
  109. <div id = 'enter_room'>
  110. <form
  111. className = 'enter-room-input'
  112. onSubmit = { this._onFormSubmit }>
  113. <FieldTextStateless
  114. autoFocus = { true }
  115. id = 'enter_room_field'
  116. isLabelHidden = { true }
  117. label = 'enter_room_field'
  118. onChange = { this._onRoomChange }
  119. placeholder = { this.state.roomPlaceholder }
  120. shouldFitContainer = { true }
  121. type = 'text'
  122. value = { this.state.room } />
  123. </form>
  124. <Button
  125. appearance = 'primary'
  126. className = 'welcome-page-button'
  127. id = 'enter_room_button'
  128. onClick = { this._onJoin }
  129. type = 'button'>
  130. { t('welcomepage.go') }
  131. </Button>
  132. </div>
  133. </div>
  134. { showAdditionalContent
  135. ? <div
  136. className = 'welcome-page-content'
  137. ref = { this._setAdditionalContentRef } />
  138. : null }
  139. </div>
  140. </AtlasKitThemeProvider>
  141. );
  142. }
  143. /**
  144. * Prevents submission of the form and delegates join logic.
  145. *
  146. * @param {Event} event - The HTML Event which details the form submission.
  147. * @private
  148. * @returns {void}
  149. */
  150. _onFormSubmit(event) {
  151. event.preventDefault();
  152. this._onJoin();
  153. }
  154. /**
  155. * Overrides the super to account for the differences in the argument types
  156. * provided by HTML and React Native text inputs.
  157. *
  158. * @inheritdoc
  159. * @override
  160. * @param {Event} event - The (HTML) Event which details the change such as
  161. * the EventTarget.
  162. * @protected
  163. */
  164. _onRoomChange(event) {
  165. super._onRoomChange(event.target.value);
  166. }
  167. /**
  168. * Sets the internal reference to the HTMLDivElement used to hold the
  169. * welcome page content.
  170. *
  171. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  172. * of the welcome page content.
  173. * @private
  174. * @returns {void}
  175. */
  176. _setAdditionalContentRef(el) {
  177. this._additionalContentRef = el;
  178. }
  179. /**
  180. * Returns whether or not additional content should be displayed below
  181. * the welcome page's header for entering a room name.
  182. *
  183. * @private
  184. * @returns {boolean}
  185. */
  186. _shouldShowAdditionalContent() {
  187. return interfaceConfig.DISPLAY_WELCOME_PAGE_CONTENT
  188. && this._additionalContentTemplate
  189. && this._additionalContentTemplate.content
  190. && this._additionalContentTemplate.innerHTML.trim();
  191. }
  192. }
  193. export default translate(connect(_mapStateToProps)(WelcomePage));