您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

WelcomePage.web.js 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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 domain name.
  66. *
  67. * @private
  68. * @returns {string} Domain name.
  69. */
  70. _getDomain() {
  71. const windowLocation = window.location;
  72. return `${windowLocation.protocol}//${windowLocation.host}/`;
  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. return (
  124. <div className = 'feature_holder'>
  125. <div
  126. className = 'feature_icon'
  127. data-i18n = { `welcomepage.feature${index}.title` } />
  128. <div
  129. className = 'feature_description'
  130. data-i18n = { `welcomepage.feature${index}.content` }
  131. data-i18n-options = { JSON.stringify({
  132. postProcess: 'resolveAppName'
  133. }) } />
  134. </div>
  135. );
  136. }
  137. /**
  138. * Renders a row of features.
  139. *
  140. * @param {number} beginIndex - The inclusive feature index to begin the row
  141. * with.
  142. * @param {number} endIndex - The exclusive feature index to end the row
  143. * with.
  144. * @private
  145. * @returns {ReactElement}
  146. */
  147. _renderFeatureRow(beginIndex, endIndex) {
  148. const features = [];
  149. for (let index = beginIndex; index < endIndex; ++index) {
  150. features.push(this._renderFeature(index));
  151. }
  152. return (
  153. <div className = 'feature_row'>
  154. {
  155. features
  156. }
  157. </div>
  158. );
  159. }
  160. /* eslint-disable require-jsdoc */
  161. /**
  162. * Renders the header part of this WelcomePage.
  163. *
  164. * @private
  165. * @returns {ReactElement|null}
  166. */
  167. _renderHeader() {
  168. /* eslint-enable require-jsdoc */
  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. data-i18n = 'welcomepage.go'
  199. id = 'enter_room_button'
  200. onClick = { this._onJoin }
  201. type = 'button' />
  202. </div>
  203. </div>
  204. </div>
  205. <div id = 'brand_header' />
  206. <input
  207. checked = { !this.state.enableWelcomePage }
  208. id = 'disable_welcome'
  209. name = 'checkbox'
  210. onChange = { this._onDisableWelcomeChange }
  211. type = 'checkbox' />
  212. <label
  213. className = 'disable_welcome_position'
  214. data-i18n = 'welcomepage.disable'
  215. htmlFor = 'disable_welcome' />
  216. <div id = 'header_text' />
  217. </div>
  218. );
  219. }
  220. /**
  221. * Renders the main part of this WelcomePage.
  222. *
  223. * @private
  224. * @returns {ReactElement|null}
  225. */
  226. _renderMain() {
  227. return (
  228. <div id = 'welcome_page_main'>
  229. <div id = 'features'>
  230. {
  231. this._renderFeatureRow(1, 5)
  232. }
  233. {
  234. this._renderFeatureRow(5, 9)
  235. }
  236. </div>
  237. </div>
  238. );
  239. }
  240. }
  241. export default connect(_mapStateToProps)(WelcomePage);