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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 { translate } from '../../base/i18n';
  9. import { Platform, Watermarks } from '../../base/react';
  10. import { CalendarList } from '../../calendar-sync';
  11. import { RecentList } from '../../recent-list';
  12. import { SettingsButton, SETTINGS_TABS } from '../../settings';
  13. import { AbstractWelcomePage, _mapStateToProps } from './AbstractWelcomePage';
  14. /**
  15. * The Web container rendering the welcome page.
  16. *
  17. * @extends AbstractWelcomePage
  18. */
  19. class WelcomePage extends AbstractWelcomePage {
  20. /**
  21. * Default values for {@code WelcomePage} component's properties.
  22. *
  23. * @static
  24. */
  25. static defaultProps = {
  26. _room: ''
  27. };
  28. /**
  29. * Initializes a new WelcomePage instance.
  30. *
  31. * @param {Object} props - The read-only properties with which the new
  32. * instance is to be initialized.
  33. */
  34. constructor(props) {
  35. super(props);
  36. this.state = {
  37. ...this.state,
  38. generateRoomnames:
  39. interfaceConfig.GENERATE_ROOMNAMES_ON_WELCOME_PAGE
  40. };
  41. /**
  42. * The HTML Element used as the container for additional content. Used
  43. * for directly appending the additional content template to the dom.
  44. *
  45. * @private
  46. * @type {HTMLTemplateElement|null}
  47. */
  48. this._additionalContentRef = null;
  49. /**
  50. * The template to use as the main content for the welcome page. If
  51. * not found then only the welcome page head will display.
  52. *
  53. * @private
  54. * @type {HTMLTemplateElement|null}
  55. */
  56. this._additionalContentTemplate = document.getElementById(
  57. 'welcome-page-additional-content-template');
  58. // Bind event handlers so they are only bound once per instance.
  59. this._onFormSubmit = this._onFormSubmit.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. { this._renderTabs() }
  146. </div>
  147. { showAdditionalContent
  148. ? <div
  149. className = 'welcome-page-content'
  150. ref = { this._setAdditionalContentRef } />
  151. : null }
  152. </div>
  153. </AtlasKitThemeProvider>
  154. );
  155. }
  156. /**
  157. * Prevents submission of the form and delegates join logic.
  158. *
  159. * @param {Event} event - The HTML Event which details the form submission.
  160. * @private
  161. * @returns {void}
  162. */
  163. _onFormSubmit(event) {
  164. event.preventDefault();
  165. this._onJoin();
  166. }
  167. /**
  168. * Overrides the super to account for the differences in the argument types
  169. * provided by HTML and React Native text inputs.
  170. *
  171. * @inheritdoc
  172. * @override
  173. * @param {Event} event - The (HTML) Event which details the change such as
  174. * the EventTarget.
  175. * @protected
  176. */
  177. _onRoomChange(event) {
  178. super._onRoomChange(event.target.value);
  179. }
  180. /**
  181. * Renders tabs to show previous meetings and upcoming calendar events. The
  182. * tabs are purposefully hidden on mobile browsers.
  183. *
  184. * @returns {ReactElement|null}
  185. */
  186. _renderTabs() {
  187. const isMobileBrowser
  188. = Platform.OS === 'android' || Platform.OS === 'ios';
  189. if (isMobileBrowser) {
  190. return null;
  191. }
  192. const { t } = this.props;
  193. const tabs = [];
  194. if (CalendarList) {
  195. tabs.push({
  196. label: t('welcomepage.calendar'),
  197. content: <CalendarList />,
  198. defaultSelected: true
  199. });
  200. }
  201. tabs.push({
  202. label: t('welcomepage.recentList'),
  203. content: <RecentList />,
  204. defaultSelected: !CalendarList
  205. });
  206. return (
  207. <div className = 'tab-container' >
  208. <div className = 'welcome-page-settings'>
  209. <SettingsButton defaultTab = { SETTINGS_TABS.CALENDAR } />
  210. </div>
  211. <Tabs tabs = { tabs } />
  212. </div>);
  213. }
  214. /**
  215. * Sets the internal reference to the HTMLDivElement used to hold the
  216. * welcome page content.
  217. *
  218. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  219. * of the welcome page content.
  220. * @private
  221. * @returns {void}
  222. */
  223. _setAdditionalContentRef(el) {
  224. this._additionalContentRef = el;
  225. }
  226. /**
  227. * Returns whether or not additional content should be displayed below
  228. * the welcome page's header for entering a room name.
  229. *
  230. * @private
  231. * @returns {boolean}
  232. */
  233. _shouldShowAdditionalContent() {
  234. return interfaceConfig.DISPLAY_WELCOME_PAGE_CONTENT
  235. && this._additionalContentTemplate
  236. && this._additionalContentTemplate.content
  237. && this._additionalContentTemplate.innerHTML.trim();
  238. }
  239. }
  240. export default translate(connect(_mapStateToProps)(WelcomePage));