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.

AbstractAppSettings.js 4.2KB

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