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

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