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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /* global APP, interfaceConfig */
  2. import React from 'react';
  3. import { connect } from 'react-redux';
  4. import { Watermarks } from '../../base/react';
  5. import { AbstractWelcomePage, _mapStateToProps } from './AbstractWelcomePage';
  6. import { translate } from '../../base/translation';
  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. return (
  127. <div
  128. className = 'feature_holder'
  129. key = { index } >
  130. <div
  131. className = 'feature_icon'>
  132. { t(`welcomepage.feature${index}.title`) }
  133. </div>
  134. <div
  135. className = 'feature_description'>
  136. { t(`welcomepage.feature${index}.content`,
  137. { postProcess: 'resolveAppName' }) }
  138. </div>
  139. </div>
  140. );
  141. }
  142. /**
  143. * Renders a row of features.
  144. *
  145. * @param {number} beginIndex - The inclusive feature index to begin the row
  146. * with.
  147. * @param {number} endIndex - The exclusive feature index to end the row
  148. * with.
  149. * @private
  150. * @returns {ReactElement}
  151. */
  152. _renderFeatureRow(beginIndex, endIndex) {
  153. const features = [];
  154. for (let index = beginIndex; index < endIndex; ++index) {
  155. features.push(this._renderFeature(index));
  156. }
  157. return (
  158. <div className = 'feature_row'>
  159. {
  160. features
  161. }
  162. </div>
  163. );
  164. }
  165. /* eslint-disable require-jsdoc */
  166. /**
  167. * Renders the header part of this WelcomePage.
  168. *
  169. * @private
  170. * @returns {ReactElement|null}
  171. */
  172. _renderHeader() {
  173. /* eslint-enable require-jsdoc */
  174. const { t } = this.props;
  175. return (
  176. <div id = 'welcome_page_header'>
  177. <Watermarks />
  178. <div id = 'enter_room_container'>
  179. <div id = 'enter_room_form'>
  180. <div className = 'domain-name'>
  181. {
  182. this._getDomain()
  183. }
  184. </div>
  185. <div id = 'enter_room'>
  186. <input
  187. autoFocus = { true }
  188. className = 'enter-room__field'
  189. data-room-name
  190. = { this.state.generatedRoomname }
  191. id = 'enter_room_field'
  192. onChange = { this._onRoomChange }
  193. onKeyDown = { this._onKeyDown }
  194. placeholder = { this.state.roomPlaceholder }
  195. type = 'text'
  196. value = { this.state.room } />
  197. { /* eslint-disable react/jsx-handler-names */ }
  198. <div
  199. className = 'icon-reload enter-room__reload'
  200. onClick = { this._updateRoomname } />
  201. { /* eslint-enable react/jsx-handler-names */ }
  202. <button
  203. className = 'enter-room__button'
  204. id = 'enter_room_button'
  205. onClick = { this._onJoin }
  206. type = 'button'>
  207. { t('welcomepage.go') }
  208. </button>
  209. </div>
  210. </div>
  211. </div>
  212. <div id = 'brand_header' />
  213. <input
  214. checked = { !this.state.enableWelcomePage }
  215. id = 'disable_welcome'
  216. name = 'checkbox'
  217. onChange = { this._onDisableWelcomeChange }
  218. type = 'checkbox' />
  219. <label
  220. className = 'disable_welcome_position'
  221. htmlFor = 'disable_welcome'>
  222. { t('welcomepage.disable') }
  223. </label>
  224. <div id = 'header_text' />
  225. </div>
  226. );
  227. }
  228. /**
  229. * Renders the main part of this WelcomePage.
  230. *
  231. * @private
  232. * @returns {ReactElement|null}
  233. */
  234. _renderMain() {
  235. return (
  236. <div id = 'welcome_page_main'>
  237. <div id = 'features'>
  238. {
  239. this._renderFeatureRow(1, 5)
  240. }
  241. {
  242. this._renderFeatureRow(5, 9)
  243. }
  244. </div>
  245. </div>
  246. );
  247. }
  248. }
  249. export default translate(connect(_mapStateToProps)(WelcomePage));