2017-12-14 17:02:32 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import { Component } from 'react';
|
2019-03-19 15:42:25 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
2017-12-14 17:02:32 +00:00
|
|
|
|
2020-06-04 14:09:13 +00:00
|
|
|
import { getDefaultURL } from '../../app/functions';
|
2018-04-12 19:58:20 +00:00
|
|
|
import { updateSettings } from '../../base/settings';
|
2017-12-14 17:02:32 +00:00
|
|
|
|
|
|
|
/**
|
2018-02-26 16:14:46 +00:00
|
|
|
* The type of the React {@code Component} props of
|
|
|
|
* {@link AbstractSettingsView}.
|
2018-01-18 21:28:25 +00:00
|
|
|
*/
|
2019-03-05 17:41:39 +00:00
|
|
|
export type Props = {
|
2017-12-14 17:02:32 +00:00
|
|
|
|
2018-01-08 11:00:31 +00:00
|
|
|
/**
|
2018-04-12 19:58:20 +00:00
|
|
|
* The default URL for when there is no custom URL set in the settings.
|
2018-02-27 20:21:28 +00:00
|
|
|
*
|
|
|
|
* @protected
|
2018-01-18 21:28:25 +00:00
|
|
|
*/
|
2018-04-12 19:58:20 +00:00
|
|
|
_serverURL: string,
|
2018-01-08 11:00:31 +00:00
|
|
|
|
2017-12-14 17:02:32 +00:00
|
|
|
/**
|
2018-04-12 19:58:20 +00:00
|
|
|
* The current settings object.
|
2018-01-18 21:28:25 +00:00
|
|
|
*/
|
2018-04-12 19:58:20 +00:00
|
|
|
_settings: Object,
|
2017-12-14 17:02:32 +00:00
|
|
|
|
|
|
|
/**
|
2018-02-26 16:14:46 +00:00
|
|
|
* Whether {@link AbstractSettingsView} is visible.
|
2018-02-27 20:21:28 +00:00
|
|
|
*
|
|
|
|
* @protected
|
2018-01-18 21:28:25 +00:00
|
|
|
*/
|
2017-12-14 17:02:32 +00:00
|
|
|
_visible: boolean,
|
|
|
|
|
|
|
|
/**
|
2018-01-18 21:28:25 +00:00
|
|
|
* Redux store dispatch function.
|
|
|
|
*/
|
2019-03-19 15:42:25 +00:00
|
|
|
dispatch: Dispatch<any>,
|
2018-01-26 10:19:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The i18n translate function.
|
|
|
|
*/
|
|
|
|
t: Function
|
2017-12-14 17:02:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2018-01-18 21:28:25 +00:00
|
|
|
* Base (abstract) class for container component rendering the app settings
|
|
|
|
* page.
|
2017-12-14 17:02:32 +00:00
|
|
|
*
|
|
|
|
* @abstract
|
|
|
|
*/
|
2019-10-18 14:30:59 +00:00
|
|
|
export class AbstractSettingsView<P: Props, S: *> extends Component<P, S> {
|
2018-01-26 10:19:43 +00:00
|
|
|
|
2017-12-14 17:02:32 +00:00
|
|
|
/**
|
2018-02-26 16:14:46 +00:00
|
|
|
* Initializes a new {@code AbstractSettingsView} instance.
|
2017-12-14 17:02:32 +00:00
|
|
|
*
|
2019-03-05 17:41:39 +00:00
|
|
|
* @param {P} props - The React {@code Component} props to initialize
|
2017-12-14 17:02:32 +00:00
|
|
|
* the component.
|
|
|
|
*/
|
2019-03-05 17:41:39 +00:00
|
|
|
constructor(props: P) {
|
2017-12-14 17:02:32 +00:00
|
|
|
super(props);
|
|
|
|
|
2018-02-26 16:14:46 +00:00
|
|
|
// Bind event handlers so they are only bound once per instance.
|
2017-12-14 17:02:32 +00:00
|
|
|
this._onChangeDisplayName = this._onChangeDisplayName.bind(this);
|
|
|
|
this._onChangeEmail = this._onChangeEmail.bind(this);
|
2018-01-08 11:00:31 +00:00
|
|
|
this._onChangeServerURL = this._onChangeServerURL.bind(this);
|
2017-12-14 17:02:32 +00:00
|
|
|
this._onStartAudioMutedChange
|
|
|
|
= this._onStartAudioMutedChange.bind(this);
|
|
|
|
this._onStartVideoMutedChange
|
|
|
|
= this._onStartVideoMutedChange.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onChangeDisplayName: (string) => void;
|
|
|
|
|
|
|
|
/**
|
2018-01-18 21:28:25 +00:00
|
|
|
* Handles the display name field value change.
|
|
|
|
*
|
|
|
|
* @param {string} text - The value typed in the name field.
|
2018-02-26 16:14:46 +00:00
|
|
|
* @protected
|
2018-01-18 21:28:25 +00:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-12-14 17:02:32 +00:00
|
|
|
_onChangeDisplayName(text) {
|
2018-04-12 19:58:20 +00:00
|
|
|
this._updateSettings({
|
2017-12-14 17:02:32 +00:00
|
|
|
displayName: text
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_onChangeEmail: (string) => void;
|
|
|
|
|
|
|
|
/**
|
2018-01-18 21:28:25 +00:00
|
|
|
* Handles the email field value change.
|
|
|
|
*
|
|
|
|
* @param {string} text - The value typed in the email field.
|
2018-02-26 16:14:46 +00:00
|
|
|
* @protected
|
2018-01-18 21:28:25 +00:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-12-14 17:02:32 +00:00
|
|
|
_onChangeEmail(text) {
|
2018-04-12 19:58:20 +00:00
|
|
|
this._updateSettings({
|
2017-12-14 17:02:32 +00:00
|
|
|
email: text
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-01-08 11:00:31 +00:00
|
|
|
_onChangeServerURL: (string) => void;
|
2017-12-14 17:02:32 +00:00
|
|
|
|
|
|
|
/**
|
2018-01-18 21:28:25 +00:00
|
|
|
* Handles the server name field value change.
|
|
|
|
*
|
|
|
|
* @param {string} text - The server URL typed in the server field.
|
2018-02-26 16:14:46 +00:00
|
|
|
* @protected
|
2018-01-18 21:28:25 +00:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2018-01-08 11:00:31 +00:00
|
|
|
_onChangeServerURL(text) {
|
2018-04-12 19:58:20 +00:00
|
|
|
this._updateSettings({
|
2017-12-14 17:02:32 +00:00
|
|
|
serverURL: text
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_onStartAudioMutedChange: (boolean) => void;
|
|
|
|
|
|
|
|
/**
|
2018-01-18 21:28:25 +00:00
|
|
|
* Handles the start audio muted change event.
|
|
|
|
*
|
2018-02-26 16:14:46 +00:00
|
|
|
* @param {boolean} newValue - The new value for the start audio muted
|
|
|
|
* option.
|
2018-01-18 21:28:25 +00:00
|
|
|
* @protected
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-12-14 17:02:32 +00:00
|
|
|
_onStartAudioMutedChange(newValue) {
|
2018-04-12 19:58:20 +00:00
|
|
|
this._updateSettings({
|
2017-12-14 17:02:32 +00:00
|
|
|
startWithAudioMuted: newValue
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_onStartVideoMutedChange: (boolean) => void;
|
|
|
|
|
|
|
|
/**
|
2018-01-18 21:28:25 +00:00
|
|
|
* Handles the start video muted change event.
|
|
|
|
*
|
2018-02-26 16:14:46 +00:00
|
|
|
* @param {boolean} newValue - The new value for the start video muted
|
|
|
|
* option.
|
2018-01-18 21:28:25 +00:00
|
|
|
* @protected
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-12-14 17:02:32 +00:00
|
|
|
_onStartVideoMutedChange(newValue) {
|
2018-04-12 19:58:20 +00:00
|
|
|
this._updateSettings({
|
2017-12-14 17:02:32 +00:00
|
|
|
startWithVideoMuted: newValue
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-12 19:58:20 +00:00
|
|
|
_updateSettings: (Object) => void;
|
2017-12-14 17:02:32 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-12 19:58:20 +00:00
|
|
|
* Updates the persisted settings on any change.
|
2018-01-18 21:28:25 +00:00
|
|
|
*
|
2018-04-12 19:58:20 +00:00
|
|
|
* @param {Object} updateObject - The partial update object for the
|
|
|
|
* settings.
|
2018-02-26 16:14:46 +00:00
|
|
|
* @private
|
2018-01-18 21:28:25 +00:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2018-04-12 19:58:20 +00:00
|
|
|
_updateSettings(updateObject: Object) {
|
|
|
|
this.props.dispatch(updateSettings(updateObject));
|
2017-12-14 17:02:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the redux state to the React {@code Component} props of
|
2018-02-26 16:14:46 +00:00
|
|
|
* {@code AbstractSettingsView}.
|
2017-12-14 17:02:32 +00:00
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @protected
|
2018-02-26 16:14:46 +00:00
|
|
|
* @returns {{
|
|
|
|
* _serverURL: string,
|
2018-04-12 19:58:20 +00:00
|
|
|
* _settings: Object,
|
2018-02-26 16:14:46 +00:00
|
|
|
* _visible: boolean
|
|
|
|
* }}
|
2017-12-14 17:02:32 +00:00
|
|
|
*/
|
|
|
|
export function _mapStateToProps(state: Object) {
|
|
|
|
return {
|
2018-07-11 08:57:07 +00:00
|
|
|
_serverURL: getDefaultURL(state),
|
2018-04-12 19:58:20 +00:00
|
|
|
_settings: state['features/base/settings'],
|
2018-02-26 16:14:46 +00:00
|
|
|
_visible: state['features/settings'].visible
|
2017-12-14 17:02:32 +00:00
|
|
|
};
|
|
|
|
}
|