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

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