jiti-meet/react/features/welcome/components/WelcomePage.web.js

376 lines
10 KiB
JavaScript
Raw Normal View History

2016-12-12 21:13:17 +00:00
/* global interfaceConfig, APP, $ */
import React from 'react';
import { connect } from 'react-redux';
2016-12-16 03:00:06 +00:00
import { AbstractWelcomePage, mapStateToProps } from './AbstractWelcomePage';
2016-12-16 03:00:06 +00:00
/**
* The CSS style of the element with CSS class <tt>rightwatermark</tt>.
*/
const RIGHT_WATERMARK_STYLE = {
backgroundImage: 'url(images/rightwatermark.png)'
};
2016-12-16 03:00:06 +00:00
/* eslint-disable require-jsdoc */
/**
2016-12-16 03:00:06 +00:00
* The Web container rendering the welcome page.
*
* @extends AbstractWelcomePage
*/
class WelcomePage extends AbstractWelcomePage {
2016-12-16 03:00:06 +00:00
/* eslint-enable require-jsdoc */
/**
2016-12-16 03:00:06 +00:00
* Initializes a new WelcomePage instance.
*
* @param {Object} props - The read-only properties with which the new
* instance is to be initialized.
*/
constructor(props) {
super(props);
2016-12-16 03:00:06 +00:00
this._initState();
// Bind event handlers so they are only bound once for every instance.
2016-12-16 03:00:06 +00:00
this._onDisableWelcomeChange = this._onDisableWelcomeChange.bind(this);
this._onKeyDown = this._onKeyDown.bind(this);
2016-12-16 03:00:06 +00:00
this._onRoomChange = this._onRoomChange.bind(this);
}
/**
2016-12-16 03:00:06 +00:00
* This method is executed when comonent is mounted.
*
* @inheritdoc
* @returns {void}
*/
componentDidMount() {
if (this.state.generateRoomnames) {
this._updateRoomname();
}
2016-12-12 21:13:17 +00:00
// XXX Temporary solution until we add React translation.
APP.translation.translateElement($('#welcome_page'));
}
/**
* Implements React's {@link Component#render()}.
*
* @inheritdoc
* @returns {ReactElement|null}
*/
render() {
return (
<div>
<div id = 'welcome_page'>
{
this._renderHeader()
}
{
this._renderMain()
}
</div>
</div>
);
}
/**
2016-12-16 03:00:06 +00:00
* Returns the domain name.
*
* @private
* @returns {string} Domain name.
*/
_getDomain() {
return `${window.location.protocol}//${window.location.host}/`;
}
/**
* Method that initializes state of the component.
*
* @returns {void}
*/
_initState() {
const showBrandWatermark = interfaceConfig.SHOW_BRAND_WATERMARK;
const showJitsiWatermark = interfaceConfig.SHOW_JITSI_WATERMARK;
this.state = {
...this.state,
brandWatermarkLink:
showBrandWatermark ? interfaceConfig.BRAND_WATERMARK_LINK : '',
enableWelcomePage: true,
generateRoomnames:
interfaceConfig.GENERATE_ROOMNAMES_ON_WELCOME_PAGE,
jitsiWatermarkLink:
showJitsiWatermark ? interfaceConfig.JITSI_WATERMARK_LINK : '',
showBrandWatermark,
showJitsiWatermark,
showPoweredBy: interfaceConfig.SHOW_POWERED_BY
};
}
/**
* Handles <tt>change</tt> event of the checkbox which allows specifying
* whether the WelcomePage is disabled.
*
* @param {Event} event - The (HTML) Event which details the change such as
* the EventTarget.
* @returns {void}
*/
_onDisableWelcomeChange(event) {
this.setState({
enableWelcomePage: !event.target.value
}, () => {
APP.settings.setWelcomePageEnabled(this.state.enableWelcomePage);
});
}
/**
* Handles 'keydown' event to initiate joining the room when the
* 'Enter/Return' button is pressed.
*
* @param {Event} event - Key down event object.
* @private
* @returns {void}
*/
_onKeyDown(event) {
if (event.keyCode === /* Enter */ 13) {
this._onJoin();
}
}
/**
* Overrides the super to account for the differences in the argument types
* provided by HTML and React Native text inputs.
*
* @inheritdoc
* @override
* @param {Event} event - The (HTML) Event which details the change such as
* the EventTarget.
* @protected
*/
_onRoomChange(event) {
super._onRoomChange(event.target.value);
}
/**
* Method that returns brand watermark element if it is enabled.
*
* @private
* @returns {ReactElement|null} Watermark element or null.
*/
_renderBrandWatermark() {
if (this.state.showBrandWatermark) {
return (
<a
href = { this.state.brandWatermarkLink }
target = '_new'>
<div
className = 'watermark rightwatermark'
style = { RIGHT_WATERMARK_STYLE } />
</a>
);
}
return null;
}
/**
* Renders a feature with a specific index.
*
* @param {number} index - The index of the feature to render.
* @private
* @returns {ReactElement}
*/
_renderFeature(index) {
return (
<div className = 'feature_holder'>
<div
className = 'feature_icon'
data-i18n = { `welcomepage.feature${index}.title` } />
<div
className = 'feature_description'
data-i18n = { `welcomepage.feature${index}.content` }
data-i18n-options = { JSON.stringify({
postProcess: 'resolveAppName'
}) } />
</div>
);
}
/**
* Renders a row of features.
*
* @param {number} beginIndex - The inclusive feature index to begin the row
* with.
* @param {number} endIndex - The exclusive feature index to end the row
* with.
* @private
* @returns {ReactElement}
*/
_renderFeatureRow(beginIndex, endIndex) {
const features = [];
for (let index = beginIndex; index < endIndex; ++index) {
features.push(this._renderFeature(index));
}
return (
<div className = 'feature_row'>
{
features
}
</div>
);
}
2016-12-16 03:00:06 +00:00
/* eslint-disable require-jsdoc */
/**
* Renders the header part of this WelcomePage.
*
* @private
* @returns {ReactElement|null}
*/
_renderHeader() {
2016-12-16 03:00:06 +00:00
/* eslint-enable require-jsdoc */
return (
<div id = 'welcome_page_header'>
2016-12-16 03:00:06 +00:00
{
this._renderJitsiWatermark()
}
{
this._renderBrandWatermark()
}
{
this._renderPoweredBy()
}
<div id = 'enter_room_container'>
<div id = 'enter_room_form'>
2016-12-16 03:00:06 +00:00
<div className = 'domain-name'>
{
this._getDomain()
}
</div>
<div id = 'enter_room'>
<input
autoFocus = { true }
className = 'enter-room__field'
2016-12-16 03:00:06 +00:00
data-room-name
= { this.state.generatedRoomname }
id = 'enter_room_field'
onChange = { this._onRoomChange }
onKeyDown = { this._onKeyDown }
placeholder = { this.state.roomPlaceholder }
type = 'text'
value = { this.state.room } />
2016-12-16 03:00:06 +00:00
{ /* eslint-disable react/jsx-handler-names */ }
<div
className = 'icon-reload enter-room__reload'
2016-12-16 03:00:06 +00:00
onClick = { this._updateRoomname } />
{ /* eslint-enable react/jsx-handler-names */ }
<button
className = 'enter-room__button'
data-i18n = 'welcomepage.go'
id = 'enter_room_button'
onClick = { this._onJoin }
type = 'button' />
</div>
</div>
</div>
<div id = 'brand_header' />
<input
checked = { !this.state.enableWelcomePage }
id = 'disable_welcome'
name = 'checkbox'
2016-12-16 03:00:06 +00:00
onChange = { this._onDisableWelcomeChange }
type = 'checkbox' />
<label
className = 'disable_welcome_position'
data-i18n = 'welcomepage.disable'
htmlFor = 'disable_welcome' />
<div id = 'header_text' />
</div>
);
}
/**
2016-12-16 03:00:06 +00:00
* Method that returns jitsi watermark element if it is enabled.
*
* @private
* @returns {ReactElement|null} Watermark element or null.
*/
_renderJitsiWatermark() {
if (this.state.showJitsiWatermark) {
return (
<a
href = { this.state.jitsiWatermarkLink }
target = '_new'>
<div className = 'watermark leftwatermark' />
</a>
);
}
return null;
}
/**
2016-12-16 03:00:06 +00:00
* Renders powered by block if it is enabled.
*
* @private
* @returns {ReactElement|null}
*/
_renderPoweredBy() {
if (this.state.showPoweredBy) {
return (
<a
className = 'poweredby'
href = 'http://jitsi.org'
target = '_new'>
<span data-i18n = 'poweredby' /> jitsi.org
</a>
);
}
return null;
}
2016-12-12 21:13:17 +00:00
/**
* Handles updating roomname.
*
* @private
* @returns {void}
2016-12-16 14:19:31 +00:00
*/
2016-12-12 21:13:17 +00:00
_onUpdateRoomname() {
this._updateRoomname();
}
/**
* Renders the main part of this WelcomePage.
*
* @private
* @returns {ReactElement|null}
*/
_renderMain() {
return (
<div id = 'welcome_page_main'>
<div id = 'features'>
{
this._renderFeatureRow(1, 5)
}
{
this._renderFeatureRow(5, 9)
}
</div>
</div>
);
}
}
export default connect(mapStateToProps)(WelcomePage);