You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractSettingsView.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // @flow
  2. import { Component } from 'react';
  3. import { getProfile, updateProfile } from '../../base/profile';
  4. /**
  5. * The type of the React {@code Component} props of
  6. * {@link AbstractSettingsView}.
  7. */
  8. type Props = {
  9. /**
  10. * The current profile object.
  11. */
  12. _profile: Object,
  13. /**
  14. * The default URL for when there is no custom URL set in the profile.
  15. */
  16. _serverURL: string,
  17. /**
  18. * Whether {@link AbstractSettingsView} is visible.
  19. */
  20. _visible: boolean,
  21. /**
  22. * Redux store dispatch function.
  23. */
  24. dispatch: Dispatch<*>,
  25. /**
  26. * The i18n translate function.
  27. */
  28. t: Function
  29. };
  30. /**
  31. * Base (abstract) class for container component rendering the app settings
  32. * page.
  33. *
  34. * @abstract
  35. */
  36. export class AbstractSettingsView extends Component<Props> {
  37. /**
  38. * Initializes a new {@code AbstractSettingsView} instance.
  39. *
  40. * @param {Props} props - The React {@code Component} props to initialize
  41. * the component.
  42. */
  43. constructor(props: Props) {
  44. super(props);
  45. // Bind event handlers so they are only bound once per instance.
  46. this._onChangeDisplayName = this._onChangeDisplayName.bind(this);
  47. this._onChangeEmail = this._onChangeEmail.bind(this);
  48. this._onChangeServerURL = this._onChangeServerURL.bind(this);
  49. this._onStartAudioMutedChange
  50. = this._onStartAudioMutedChange.bind(this);
  51. this._onStartVideoMutedChange
  52. = this._onStartVideoMutedChange.bind(this);
  53. }
  54. _onChangeDisplayName: (string) => void;
  55. /**
  56. * Handles the display name field value change.
  57. *
  58. * @param {string} text - The value typed in the name field.
  59. * @protected
  60. * @returns {void}
  61. */
  62. _onChangeDisplayName(text) {
  63. this._updateProfile({
  64. displayName: text
  65. });
  66. }
  67. _onChangeEmail: (string) => void;
  68. /**
  69. * Handles the email field value change.
  70. *
  71. * @param {string} text - The value typed in the email field.
  72. * @protected
  73. * @returns {void}
  74. */
  75. _onChangeEmail(text) {
  76. this._updateProfile({
  77. email: text
  78. });
  79. }
  80. _onChangeServerURL: (string) => void;
  81. /**
  82. * Handles the server name field value change.
  83. *
  84. * @param {string} text - The server URL typed in the server field.
  85. * @protected
  86. * @returns {void}
  87. */
  88. _onChangeServerURL(text) {
  89. this._updateProfile({
  90. serverURL: text
  91. });
  92. }
  93. _onStartAudioMutedChange: (boolean) => void;
  94. /**
  95. * Handles the start audio muted change event.
  96. *
  97. * @param {boolean} newValue - The new value for the start audio muted
  98. * option.
  99. * @protected
  100. * @returns {void}
  101. */
  102. _onStartAudioMutedChange(newValue) {
  103. this._updateProfile({
  104. startWithAudioMuted: newValue
  105. });
  106. }
  107. _onStartVideoMutedChange: (boolean) => void;
  108. /**
  109. * Handles the start video muted change event.
  110. *
  111. * @param {boolean} newValue - The new value for the start video muted
  112. * option.
  113. * @protected
  114. * @returns {void}
  115. */
  116. _onStartVideoMutedChange(newValue) {
  117. this._updateProfile({
  118. startWithVideoMuted: newValue
  119. });
  120. }
  121. _updateProfile: (Object) => void;
  122. /**
  123. * Updates the persisted profile on any change.
  124. *
  125. * @param {Object} updateObject - The partial update object for the profile.
  126. * @private
  127. * @returns {void}
  128. */
  129. _updateProfile(updateObject: Object) {
  130. this.props.dispatch(updateProfile({
  131. ...this.props._profile,
  132. ...updateObject
  133. }));
  134. }
  135. }
  136. /**
  137. * Maps (parts of) the redux state to the React {@code Component} props of
  138. * {@code AbstractSettingsView}.
  139. *
  140. * @param {Object} state - The redux state.
  141. * @protected
  142. * @returns {{
  143. * _profile: Object,
  144. * _serverURL: string,
  145. * _visible: boolean
  146. * }}
  147. */
  148. export function _mapStateToProps(state: Object) {
  149. return {
  150. _profile: getProfile(state),
  151. _serverURL: state['features/app'].app._getDefaultURL(),
  152. _visible: state['features/settings'].visible
  153. };
  154. }