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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /* global APP, interfaceConfig */
  2. import React from 'react';
  3. import { connect } from 'react-redux';
  4. import { translate } from '../../base/i18n';
  5. import { Watermarks } from '../../base/react';
  6. import { AbstractWelcomePage, _mapStateToProps } from './AbstractWelcomePage';
  7. /**
  8. * The Web container rendering the welcome page.
  9. *
  10. * @extends AbstractWelcomePage
  11. */
  12. class WelcomePage extends AbstractWelcomePage {
  13. /**
  14. * Initializes a new WelcomePage instance.
  15. *
  16. * @param {Object} props - The read-only properties with which the new
  17. * instance is to be initialized.
  18. */
  19. constructor(props) {
  20. super(props);
  21. this.state = {
  22. ...this.state,
  23. enableWelcomePage: true,
  24. generateRoomnames:
  25. interfaceConfig.GENERATE_ROOMNAMES_ON_WELCOME_PAGE
  26. };
  27. // Bind event handlers so they are only bound once for every instance.
  28. this._onDisableWelcomeChange = this._onDisableWelcomeChange.bind(this);
  29. this._onKeyDown = this._onKeyDown.bind(this);
  30. this._onRoomChange = this._onRoomChange.bind(this);
  31. }
  32. /**
  33. * Implements React's {@link Component#componentDidMount()}. Invoked
  34. * immediately after this component is mounted.
  35. *
  36. * @inheritdoc
  37. * @returns {void}
  38. */
  39. componentDidMount() {
  40. if (this.state.generateRoomnames) {
  41. this._updateRoomname();
  42. }
  43. }
  44. /**
  45. * Implements React's {@link Component#render()}.
  46. *
  47. * @inheritdoc
  48. * @returns {ReactElement|null}
  49. */
  50. render() {
  51. return (
  52. <div id = 'welcome_page'>
  53. {
  54. this._renderHeader()
  55. }
  56. {
  57. this._renderMain()
  58. }
  59. </div>
  60. );
  61. }
  62. /**
  63. * Returns the URL of this WelcomePage for display purposes. For
  64. * historic/legacy reasons, the return value is referred to as domain.
  65. *
  66. * @private
  67. * @returns {string} The URL of this WelcomePage for display purposes.
  68. */
  69. _getDomain() {
  70. // As the returned URL is for display purposes, do not return the
  71. // userinfo, query and fragment URI parts.
  72. const wl = window.location;
  73. return `${wl.protocol}//${wl.host}${wl.pathname}`;
  74. }
  75. /**
  76. * Handles {@code change} event of the checkbox which allows specifying
  77. * whether the WelcomePage is disabled.
  78. *
  79. * @param {Event} event - The (HTML) Event which details the change such as
  80. * the EventTarget.
  81. * @returns {void}
  82. */
  83. _onDisableWelcomeChange(event) {
  84. this.setState({
  85. enableWelcomePage: !event.target.checked
  86. }, () => {
  87. APP.settings.setWelcomePageEnabled(this.state.enableWelcomePage);
  88. });
  89. }
  90. /**
  91. * Handles 'keydown' event to initiate joining the room when the
  92. * 'Enter/Return' button is pressed.
  93. *
  94. * @param {Event} event - Key down event object.
  95. * @private
  96. * @returns {void}
  97. */
  98. _onKeyDown(event) {
  99. if (event.keyCode === /* Enter */ 13) {
  100. this._onJoin();
  101. }
  102. }
  103. /**
  104. * Overrides the super to account for the differences in the argument types
  105. * provided by HTML and React Native text inputs.
  106. *
  107. * @inheritdoc
  108. * @override
  109. * @param {Event} event - The (HTML) Event which details the change such as
  110. * the EventTarget.
  111. * @protected
  112. */
  113. _onRoomChange(event) {
  114. super._onRoomChange(event.target.value);
  115. }
  116. /**
  117. * Renders a feature with a specific index.
  118. *
  119. * @param {number} index - The index of the feature to render.
  120. * @private
  121. * @returns {ReactElement}
  122. */
  123. _renderFeature(index) {
  124. const { t } = this.props;
  125. const tns = `welcomepage.feature${index}`;
  126. return (
  127. <div
  128. className = 'feature_holder'
  129. key = { index } >
  130. <div className = 'feature_icon'>
  131. { t(`${tns}.title`) }
  132. </div>
  133. <div className = 'feature_description'>
  134. { t(`${tns}.content`, { postProcess: 'resolveAppName' }) }
  135. </div>
  136. </div>
  137. );
  138. }
  139. /**
  140. * Renders a row of features.
  141. *
  142. * @param {number} beginIndex - The inclusive feature index to begin the row
  143. * with.
  144. * @param {number} endIndex - The exclusive feature index to end the row
  145. * with.
  146. * @private
  147. * @returns {ReactElement}
  148. */
  149. _renderFeatureRow(beginIndex, endIndex) {
  150. const features = [];
  151. for (let index = beginIndex; index < endIndex; ++index) {
  152. features.push(this._renderFeature(index));
  153. }
  154. return (
  155. <div className = 'feature_row'>
  156. {
  157. features
  158. }
  159. </div>
  160. );
  161. }
  162. /**
  163. * Renders the header part of this WelcomePage.
  164. *
  165. * @private
  166. * @returns {ReactElement|null}
  167. */
  168. _renderHeader() {
  169. const { t } = this.props;
  170. return (
  171. <div id = 'welcome_page_header'>
  172. <Watermarks />
  173. <div id = 'enter_room_container'>
  174. <div id = 'enter_room_form'>
  175. <div className = 'domain-name'>
  176. {
  177. this._getDomain()
  178. }
  179. </div>
  180. <div id = 'enter_room'>
  181. <input
  182. autoFocus = { true }
  183. className = 'enter-room__field'
  184. data-room-name
  185. = { this.state.generatedRoomname }
  186. id = 'enter_room_field'
  187. onChange = { this._onRoomChange }
  188. onKeyDown = { this._onKeyDown }
  189. placeholder = { this.state.roomPlaceholder }
  190. type = 'text'
  191. value = { this.state.room } />
  192. { /* eslint-disable react/jsx-handler-names */ }
  193. <div
  194. className = 'icon-reload enter-room__reload'
  195. onClick = { this._updateRoomname } />
  196. { /* eslint-enable react/jsx-handler-names */ }
  197. <button
  198. className = 'enter-room__button'
  199. id = 'enter_room_button'
  200. onClick = { this._onJoin }
  201. type = 'button'>
  202. { t('welcomepage.go') }
  203. </button>
  204. </div>
  205. </div>
  206. </div>
  207. <div id = 'brand_header' />
  208. <input
  209. checked = { !this.state.enableWelcomePage }
  210. id = 'disable_welcome'
  211. name = 'checkbox'
  212. onChange = { this._onDisableWelcomeChange }
  213. type = 'checkbox' />
  214. <label
  215. className = 'disable_welcome_position'
  216. htmlFor = 'disable_welcome'>
  217. { t('welcomepage.disable') }
  218. </label>
  219. <div id = 'header_text' />
  220. </div>
  221. );
  222. }
  223. /**
  224. * Renders the main part of this WelcomePage.
  225. *
  226. * @private
  227. * @returns {ReactElement|null}
  228. */
  229. _renderMain() {
  230. return (
  231. <div id = 'welcome_page_main'>
  232. <div id = 'features'>
  233. {
  234. this._renderFeatureRow(1, 5)
  235. }
  236. {
  237. this._renderFeatureRow(5, 9)
  238. }
  239. </div>
  240. </div>
  241. );
  242. }
  243. }
  244. export default translate(connect(_mapStateToProps)(WelcomePage));