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 7.9KB

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