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

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