2018-08-29 17:24:25 +00:00
|
|
|
import React, { Component } from 'react';
|
2022-08-10 06:25:31 +00:00
|
|
|
import { WithTranslation } from 'react-i18next';
|
2018-08-29 17:24:25 +00:00
|
|
|
|
2022-10-11 10:47:54 +00:00
|
|
|
import { IStore } from '../../../app/types';
|
2022-08-10 06:25:31 +00:00
|
|
|
import { translate } from '../../../base/i18n/functions';
|
|
|
|
import { connect } from '../../../base/redux/functions';
|
2022-10-11 10:47:54 +00:00
|
|
|
import { updateSettings } from '../../../base/settings/actions';
|
2022-08-10 06:25:31 +00:00
|
|
|
import { Button } from '../../../base/ui/components/web';
|
|
|
|
import Input from '../../../base/ui/components/web/Input';
|
2018-08-29 17:24:25 +00:00
|
|
|
|
2022-08-10 06:25:31 +00:00
|
|
|
// @ts-ignore
|
2021-02-23 07:39:20 +00:00
|
|
|
import KeyboardAvoider from './KeyboardAvoider';
|
|
|
|
|
2018-08-29 17:24:25 +00:00
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@DisplayNameForm}.
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
interface IProps extends WithTranslation {
|
2018-08-29 17:24:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to set the local participant display name.
|
|
|
|
*/
|
2022-10-11 10:47:54 +00:00
|
|
|
dispatch: IStore['dispatch'];
|
2018-08-29 17:24:25 +00:00
|
|
|
|
2021-09-10 18:57:36 +00:00
|
|
|
/**
|
|
|
|
* Whether the polls feature is enabled or not.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
isPollsEnabled: boolean;
|
2022-08-10 06:25:31 +00:00
|
|
|
}
|
2018-08-29 17:24:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} state of {@DisplayNameForm}.
|
|
|
|
*/
|
|
|
|
type State = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* User provided display name when the input text is provided in the view.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
displayName: string;
|
2018-08-29 17:24:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* React Component for requesting the local participant to set a display name.
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @augments Component
|
2018-08-29 17:24:25 +00:00
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
class DisplayNameForm extends Component<IProps, State> {
|
2018-08-29 17:24:25 +00:00
|
|
|
state = {
|
|
|
|
displayName: ''
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a new {@code DisplayNameForm} instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only properties with which the new
|
|
|
|
* instance is to be initialized.
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
constructor(props: IProps) {
|
2018-08-29 17:24:25 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once for every instance.
|
|
|
|
this._onDisplayNameChange = this._onDisplayNameChange.bind(this);
|
|
|
|
this._onSubmit = this._onSubmit.bind(this);
|
2021-06-10 12:48:44 +00:00
|
|
|
this._onKeyPress = this._onKeyPress.bind(this);
|
2018-08-29 17:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2021-09-10 18:57:36 +00:00
|
|
|
const { isPollsEnabled, t } = this.props;
|
2018-08-29 17:24:25 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div id = 'nickname'>
|
|
|
|
<form onSubmit = { this._onSubmit }>
|
2022-08-10 06:25:31 +00:00
|
|
|
<Input
|
|
|
|
accessibilityLabel = { t('chat.nickname.title') }
|
2018-08-29 17:24:25 +00:00
|
|
|
autoFocus = { true }
|
|
|
|
id = 'nickinput'
|
2021-09-10 18:57:36 +00:00
|
|
|
label = { t(isPollsEnabled ? 'chat.nickname.titleWithPolls' : 'chat.nickname.title') }
|
2022-08-10 06:25:31 +00:00
|
|
|
name = 'name'
|
2018-08-29 17:24:25 +00:00
|
|
|
onChange = { this._onDisplayNameChange }
|
|
|
|
placeholder = { t('chat.nickname.popover') }
|
|
|
|
type = 'text'
|
|
|
|
value = { this.state.displayName } />
|
|
|
|
</form>
|
2022-08-10 06:25:31 +00:00
|
|
|
<br />
|
|
|
|
<Button
|
|
|
|
accessibilityLabel = { t('chat.enter') }
|
|
|
|
disabled = { !this.state.displayName.trim() }
|
|
|
|
fullWidth = { true }
|
|
|
|
label = { t('chat.enter') }
|
|
|
|
onClick = { this._onSubmit } />
|
2021-02-23 07:39:20 +00:00
|
|
|
<KeyboardAvoider />
|
2018-08-29 17:24:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatches an action update the entered display name.
|
|
|
|
*
|
2022-08-10 06:25:31 +00:00
|
|
|
* @param {string} value - Keyboard event.
|
2018-08-29 17:24:25 +00:00
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-08-10 06:25:31 +00:00
|
|
|
_onDisplayNameChange(value: string) {
|
|
|
|
this.setState({ displayName: value });
|
2018-08-29 17:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatches an action to hit enter to change your display name.
|
|
|
|
*
|
|
|
|
* @param {event} event - Keyboard event
|
|
|
|
* that will check if user has pushed the enter key.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-08-10 06:25:31 +00:00
|
|
|
_onSubmit(event: any) {
|
|
|
|
event?.preventDefault && event.preventDefault();
|
2018-08-29 17:24:25 +00:00
|
|
|
|
2019-01-13 19:33:28 +00:00
|
|
|
// Store display name in settings
|
|
|
|
this.props.dispatch(updateSettings({
|
|
|
|
displayName: this.state.displayName
|
|
|
|
}));
|
2018-08-29 17:24:25 +00:00
|
|
|
}
|
2021-06-10 12:48:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* KeyPress handler for accessibility.
|
|
|
|
*
|
|
|
|
* @param {Object} e - The key event to handle.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-08-10 06:25:31 +00:00
|
|
|
_onKeyPress(e: React.KeyboardEvent) {
|
2021-06-10 12:48:44 +00:00
|
|
|
if (e.key === ' ' || e.key === 'Enter') {
|
|
|
|
this._onSubmit(e);
|
|
|
|
}
|
|
|
|
}
|
2018-08-29 17:24:25 +00:00
|
|
|
}
|
|
|
|
|
2019-01-13 19:33:28 +00:00
|
|
|
export default translate(connect()(DisplayNameForm));
|