2017-12-14 17:02:32 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import { Component } from 'react';
|
|
|
|
|
2018-02-27 20:21:28 +00:00
|
|
|
import { updateProfile } from '../../base/profile';
|
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
|
|
|
*/
|
2017-12-14 17:02:32 +00:00
|
|
|
type Props = {
|
|
|
|
|
2018-01-08 11:00:31 +00:00
|
|
|
/**
|
2018-01-18 21:28:25 +00:00
|
|
|
* The current profile object.
|
2018-02-27 20:21:28 +00:00
|
|
|
*
|
|
|
|
* @protected
|
2018-01-18 21:28:25 +00:00
|
|
|
*/
|
|
|
|
_profile: Object,
|
2018-01-08 11:00:31 +00:00
|
|
|
|
2017-12-14 17:02:32 +00:00
|
|
|
/**
|
2018-01-18 21:28:25 +00:00
|
|
|
* The default URL for when there is no custom URL set in the profile.
|
2018-02-27 20:21:28 +00:00
|
|
|
*
|
|
|
|
* @protected
|
2018-01-18 21:28:25 +00:00
|
|
|
*/
|
|
|
|
_serverURL: string,
|
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.
|
|
|
|
*/
|
2018-01-26 10:19:43 +00:00
|
|
|
dispatch: Dispatch<*>,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2018-02-26 16:14:46 +00:00
|
|
|
export class AbstractSettingsView extends Component<Props> {
|
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
|
|
|
*
|
|
|
|
* @param {Props} props - The React {@code Component} props to initialize
|
|
|
|
* the component.
|
|
|
|
*/
|
|
|
|
constructor(props: Props) {
|
|
|
|
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-01-08 11:00:31 +00:00
|
|
|
this._updateProfile({
|
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-01-08 11:00:31 +00:00
|
|
|
this._updateProfile({
|
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) {
|
|
|
|
this._updateProfile({
|
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) {
|
|
|
|
this._updateProfile({
|
|
|
|
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) {
|
|
|
|
this._updateProfile({
|
|
|
|
startWithVideoMuted: newValue
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_updateProfile: (Object) => void;
|
|
|
|
|
|
|
|
/**
|
2018-01-18 21:28:25 +00:00
|
|
|
* Updates the persisted profile on any change.
|
|
|
|
*
|
|
|
|
* @param {Object} updateObject - The partial update object for the profile.
|
2018-02-26 16:14:46 +00:00
|
|
|
* @private
|
2018-01-18 21:28:25 +00:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-12-14 17:02:32 +00:00
|
|
|
_updateProfile(updateObject: Object) {
|
2018-02-12 20:18:08 +00:00
|
|
|
this.props.dispatch(updateProfile(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 {{
|
|
|
|
* _profile: Object,
|
|
|
|
* _serverURL: string,
|
|
|
|
* _visible: boolean
|
|
|
|
* }}
|
2017-12-14 17:02:32 +00:00
|
|
|
*/
|
|
|
|
export function _mapStateToProps(state: Object) {
|
|
|
|
return {
|
2018-02-27 20:21:28 +00:00
|
|
|
_profile: state['features/base/profile'],
|
2018-02-26 16:14:46 +00:00
|
|
|
_serverURL: state['features/app'].app._getDefaultURL(),
|
|
|
|
_visible: state['features/settings'].visible
|
2017-12-14 17:02:32 +00:00
|
|
|
};
|
|
|
|
}
|