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

WelcomePage.web.js 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. selectedTab: 0
  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. this._onTabSelected = this._onTabSelected.bind(this);
  65. }
  66. /**
  67. * Implements React's {@link Component#componentDidMount()}. Invoked
  68. * immediately after this component is mounted.
  69. *
  70. * @inheritdoc
  71. * @returns {void}
  72. */
  73. componentDidMount() {
  74. document.body.classList.add('welcome-page');
  75. if (this.state.generateRoomnames) {
  76. this._updateRoomname();
  77. }
  78. if (this._shouldShowAdditionalContent()) {
  79. this._additionalContentRef.appendChild(
  80. this._additionalContentTemplate.content.cloneNode(true));
  81. }
  82. }
  83. /**
  84. * Removes the classname used for custom styling of the welcome page.
  85. *
  86. * @inheritdoc
  87. * @returns {void}
  88. */
  89. componentWillUnmount() {
  90. super.componentWillUnmount();
  91. document.body.classList.remove('welcome-page');
  92. }
  93. /**
  94. * Implements React's {@link Component#render()}.
  95. *
  96. * @inheritdoc
  97. * @returns {ReactElement|null}
  98. */
  99. render() {
  100. const { t } = this.props;
  101. const { APP_NAME } = interfaceConfig;
  102. const showAdditionalContent = this._shouldShowAdditionalContent();
  103. return (
  104. <AtlasKitThemeProvider mode = 'light'>
  105. <div
  106. className = { `welcome ${showAdditionalContent
  107. ? 'with-content' : 'without-content'}` }
  108. id = 'welcome_page'>
  109. <div className = 'welcome-watermark'>
  110. <Watermarks />
  111. </div>
  112. <div className = 'header'>
  113. <div className = 'header-image' />
  114. <div className = 'header-text'>
  115. <h1 className = 'header-text-title'>
  116. { t('welcomepage.title') }
  117. </h1>
  118. <p className = 'header-text-description'>
  119. { t('welcomepage.appDescription',
  120. { app: APP_NAME }) }
  121. </p>
  122. </div>
  123. <div id = 'enter_room'>
  124. <form
  125. className = 'enter-room-input'
  126. onSubmit = { this._onFormSubmit }>
  127. <FieldTextStateless
  128. autoFocus = { true }
  129. id = 'enter_room_field'
  130. isLabelHidden = { true }
  131. label = 'enter_room_field'
  132. onChange = { this._onRoomChange }
  133. placeholder = { this.state.roomPlaceholder }
  134. shouldFitContainer = { true }
  135. type = 'text'
  136. value = { this.state.room } />
  137. </form>
  138. <Button
  139. appearance = 'primary'
  140. className = 'welcome-page-button'
  141. id = 'enter_room_button'
  142. onClick = { this._onJoin }
  143. type = 'button'>
  144. { t('welcomepage.go') }
  145. </Button>
  146. </div>
  147. { this._renderTabs() }
  148. </div>
  149. { showAdditionalContent
  150. ? <div
  151. className = 'welcome-page-content'
  152. ref = { this._setAdditionalContentRef } />
  153. : null }
  154. </div>
  155. </AtlasKitThemeProvider>
  156. );
  157. }
  158. /**
  159. * Prevents submission of the form and delegates join logic.
  160. *
  161. * @param {Event} event - The HTML Event which details the form submission.
  162. * @private
  163. * @returns {void}
  164. */
  165. _onFormSubmit(event) {
  166. event.preventDefault();
  167. this._onJoin();
  168. }
  169. /**
  170. * Overrides the super to account for the differences in the argument types
  171. * provided by HTML and React Native text inputs.
  172. *
  173. * @inheritdoc
  174. * @override
  175. * @param {Event} event - The (HTML) Event which details the change such as
  176. * the EventTarget.
  177. * @protected
  178. */
  179. _onRoomChange(event) {
  180. super._onRoomChange(event.target.value);
  181. }
  182. /**
  183. * Callback invoked when the desired tab to display should be changed.
  184. *
  185. * @param {Object} tab - The configuration passed into atlaskit tabs to
  186. * describe how to display the selected tab.
  187. * @param {number} tabIndex - The index of the tab within the array of
  188. * displayed tabs.
  189. * @private
  190. * @returns {void}
  191. */
  192. _onTabSelected(tab, tabIndex) { // eslint-disable-line no-unused-vars
  193. this.setState({ selectedTab: tabIndex });
  194. }
  195. /**
  196. * Renders tabs to show previous meetings and upcoming calendar events. The
  197. * tabs are purposefully hidden on mobile browsers.
  198. *
  199. * @returns {ReactElement|null}
  200. */
  201. _renderTabs() {
  202. const isMobileBrowser
  203. = Platform.OS === 'android' || Platform.OS === 'ios';
  204. if (isMobileBrowser) {
  205. return null;
  206. }
  207. const { t } = this.props;
  208. const tabs = [];
  209. if (CalendarList) {
  210. tabs.push({
  211. label: t('welcomepage.calendar'),
  212. content: <CalendarList />
  213. });
  214. }
  215. tabs.push({
  216. label: t('welcomepage.recentList'),
  217. content: <RecentList />,
  218. defaultSelected: !CalendarList
  219. });
  220. return (
  221. <div className = 'tab-container' >
  222. <div className = 'welcome-page-settings'>
  223. <SettingsButton defaultTab = { SETTINGS_TABS.CALENDAR } />
  224. </div>
  225. <Tabs
  226. onSelect = { this._onTabSelected }
  227. selected = { this.state.selectedTab }
  228. tabs = { tabs } />
  229. </div>);
  230. }
  231. /**
  232. * Sets the internal reference to the HTMLDivElement used to hold the
  233. * welcome page content.
  234. *
  235. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  236. * of the welcome page content.
  237. * @private
  238. * @returns {void}
  239. */
  240. _setAdditionalContentRef(el) {
  241. this._additionalContentRef = el;
  242. }
  243. /**
  244. * Returns whether or not additional content should be displayed below
  245. * the welcome page's header for entering a room name.
  246. *
  247. * @private
  248. * @returns {boolean}
  249. */
  250. _shouldShowAdditionalContent() {
  251. return interfaceConfig.DISPLAY_WELCOME_PAGE_CONTENT
  252. && this._additionalContentTemplate
  253. && this._additionalContentTemplate.content
  254. && this._additionalContentTemplate.innerHTML.trim();
  255. }
  256. }
  257. export default translate(connect(_mapStateToProps)(WelcomePage));