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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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 className = 'feature_holder'>
  128. <div
  129. className = 'feature_icon'
  130. data-i18n = { `welcomepage.feature${index}.title` } />
  131. <div
  132. className = 'feature_description'
  133. data-i18n = { `welcomepage.feature${index}.content` }
  134. data-i18n-options = { JSON.stringify({
  135. postProcess: 'resolveAppName'
  136. }) } />
  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. /* eslint-disable require-jsdoc */
  164. /**
  165. * Renders the header part of this WelcomePage.
  166. *
  167. * @private
  168. * @returns {ReactElement|null}
  169. */
  170. _renderHeader() {
  171. /* eslint-enable require-jsdoc */
  172. return (
  173. <div id = 'welcome_page_header'>
  174. <Watermarks />
  175. <div id = 'enter_room_container'>
  176. <div id = 'enter_room_form'>
  177. <div className = 'domain-name'>
  178. {
  179. this._getDomain()
  180. }
  181. </div>
  182. <div id = 'enter_room'>
  183. <input
  184. autoFocus = { true }
  185. className = 'enter-room__field'
  186. data-room-name
  187. = { this.state.generatedRoomname }
  188. id = 'enter_room_field'
  189. onChange = { this._onRoomChange }
  190. onKeyDown = { this._onKeyDown }
  191. placeholder = { this.state.roomPlaceholder }
  192. type = 'text'
  193. value = { this.state.room } />
  194. { /* eslint-disable react/jsx-handler-names */ }
  195. <div
  196. className = 'icon-reload enter-room__reload'
  197. onClick = { this._updateRoomname } />
  198. { /* eslint-enable react/jsx-handler-names */ }
  199. <button
  200. className = 'enter-room__button'
  201. data-i18n = 'welcomepage.go'
  202. id = 'enter_room_button'
  203. onClick = { this._onJoin }
  204. type = '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. data-i18n = 'welcomepage.disable'
  218. htmlFor = 'disable_welcome' />
  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 connect(_mapStateToProps)(WelcomePage);