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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 { DialogContainer } from '../../base/dialog';
  8. import { translate } from '../../base/i18n';
  9. import { Watermarks } from '../../base/react';
  10. import { RecentList } from '../../recent-list';
  11. import { openSettingsDialog } from '../../settings';
  12. import { AbstractWelcomePage, _mapStateToProps } from './AbstractWelcomePage';
  13. /**
  14. * The Web container rendering the welcome page.
  15. *
  16. * @extends AbstractWelcomePage
  17. */
  18. class WelcomePage extends AbstractWelcomePage {
  19. /**
  20. * Default values for {@code WelcomePage} component's properties.
  21. *
  22. * @static
  23. */
  24. static defaultProps = {
  25. _room: ''
  26. };
  27. /**
  28. * Initializes a new WelcomePage instance.
  29. *
  30. * @param {Object} props - The read-only properties with which the new
  31. * instance is to be initialized.
  32. */
  33. constructor(props) {
  34. super(props);
  35. this.state = {
  36. ...this.state,
  37. generateRoomnames:
  38. interfaceConfig.GENERATE_ROOMNAMES_ON_WELCOME_PAGE
  39. };
  40. /**
  41. * The HTML Element used as the container for additional content. Used
  42. * for directly appending the additional content template to the dom.
  43. *
  44. * @private
  45. * @type {HTMLTemplateElement|null}
  46. */
  47. this._additionalContentRef = null;
  48. /**
  49. * The template to use as the main content for the welcome page. If
  50. * not found then only the welcome page head will display.
  51. *
  52. * @private
  53. * @type {HTMLTemplateElement|null}
  54. */
  55. this._additionalContentTemplate = document.getElementById(
  56. 'welcome-page-additional-content-template');
  57. // Bind event handlers so they are only bound once per instance.
  58. this._onFormSubmit = this._onFormSubmit.bind(this);
  59. this._onOpenSettings = this._onOpenSettings.bind(this);
  60. this._onRoomChange = this._onRoomChange.bind(this);
  61. this._setAdditionalContentRef
  62. = this._setAdditionalContentRef.bind(this);
  63. }
  64. /**
  65. * Implements React's {@link Component#componentDidMount()}. Invoked
  66. * immediately after this component is mounted.
  67. *
  68. * @inheritdoc
  69. * @returns {void}
  70. */
  71. componentDidMount() {
  72. document.body.classList.add('welcome-page');
  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. <AtlasKitThemeProvider mode = 'light'>
  103. <div
  104. className = { `welcome ${showAdditionalContent
  105. ? 'with-content' : 'without-content'}` }
  106. id = 'welcome_page'>
  107. <div className = 'welcome-watermark'>
  108. <Watermarks />
  109. </div>
  110. <div className = 'header'>
  111. <div className = 'header-image' />
  112. <div className = 'header-text'>
  113. <h1 className = 'header-text-title'>
  114. { t('welcomepage.title') }
  115. </h1>
  116. <p className = 'header-text-description'>
  117. { t('welcomepage.appDescription',
  118. { app: APP_NAME }) }
  119. </p>
  120. </div>
  121. <div id = 'enter_room'>
  122. <form
  123. className = 'enter-room-input'
  124. onSubmit = { this._onFormSubmit }>
  125. <FieldTextStateless
  126. autoFocus = { true }
  127. id = 'enter_room_field'
  128. isLabelHidden = { true }
  129. label = 'enter_room_field'
  130. onChange = { this._onRoomChange }
  131. placeholder = { this.state.roomPlaceholder }
  132. shouldFitContainer = { true }
  133. type = 'text'
  134. value = { this.state.room } />
  135. </form>
  136. <Button
  137. appearance = 'primary'
  138. className = 'welcome-page-button'
  139. id = 'enter_room_button'
  140. onClick = { this._onJoin }
  141. type = 'button'>
  142. { t('welcomepage.go') }
  143. </Button>
  144. </div>
  145. <RecentList />
  146. </div>
  147. { showAdditionalContent
  148. ? <div
  149. className = 'welcome-page-content'
  150. ref = { this._setAdditionalContentRef } />
  151. : null }
  152. </div>
  153. <AtlasKitThemeProvider mode = 'dark'>
  154. <DialogContainer />
  155. </AtlasKitThemeProvider>
  156. </AtlasKitThemeProvider>
  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. * Opens {@code SettingsDialog}.
  172. *
  173. * @private
  174. * @returns {void}
  175. */
  176. _onOpenSettings() {
  177. this.props.dispatch(openSettingsDialog());
  178. }
  179. /**
  180. * Overrides the super to account for the differences in the argument types
  181. * provided by HTML and React Native text inputs.
  182. *
  183. * @inheritdoc
  184. * @override
  185. * @param {Event} event - The (HTML) Event which details the change such as
  186. * the EventTarget.
  187. * @protected
  188. */
  189. _onRoomChange(event) {
  190. super._onRoomChange(event.target.value);
  191. }
  192. /**
  193. * Sets the internal reference to the HTMLDivElement used to hold the
  194. * welcome page content.
  195. *
  196. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  197. * of the welcome page content.
  198. * @private
  199. * @returns {void}
  200. */
  201. _setAdditionalContentRef(el) {
  202. this._additionalContentRef = el;
  203. }
  204. /**
  205. * Returns whether or not additional content should be displayed below
  206. * the welcome page's header for entering a room name.
  207. *
  208. * @private
  209. * @returns {boolean}
  210. */
  211. _shouldShowAdditionalContent() {
  212. return interfaceConfig.DISPLAY_WELCOME_PAGE_CONTENT
  213. && this._additionalContentTemplate
  214. && this._additionalContentTemplate.content
  215. && this._additionalContentTemplate.innerHTML.trim();
  216. }
  217. }
  218. export default translate(connect(_mapStateToProps)(WelcomePage));