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

WelcomePage.web.js 11KB

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