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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // @flow
  2. import { Component } from 'react';
  3. import { hideAppSettings } from '../actions';
  4. import { getProfile, updateProfile } from '../../base/profile';
  5. /**
  6. * The type of the React {@code Component} props of {@link AbstractAppSettings}
  7. */
  8. type Props = {
  9. /**
  10. * The current aspect ratio of the screen.
  11. */
  12. _aspectRatio: Symbol,
  13. /**
  14. * The default URL for when there is no custom URL set in the profile.
  15. */
  16. _serverURL: string,
  17. /**
  18. * The current profile object.
  19. */
  20. _profile: Object,
  21. /**
  22. * The visibility prop of the settings modal.
  23. */
  24. _visible: boolean,
  25. /**
  26. * Redux store dispatch function.
  27. */
  28. dispatch: Dispatch<*>
  29. };
  30. /**
  31. * Base (abstract) class for container component rendering
  32. * the app settings page.
  33. *
  34. * @abstract
  35. */
  36. export class AbstractAppSettings extends Component<Props> {
  37. /**
  38. * Initializes a new {@code AbstractAppSettings} 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. this._onChangeDisplayName = this._onChangeDisplayName.bind(this);
  46. this._onChangeEmail = this._onChangeEmail.bind(this);
  47. this._onChangeServerURL = this._onChangeServerURL.bind(this);
  48. this._onRequestClose = this._onRequestClose.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. * @protected
  59. * @param {string} text - The value typed in the name field.
  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. * @protected
  72. * @param {string} text - The value typed in the email field.
  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. * @protected
  85. * @param {string} text - The server URL typed in the server field.
  86. * @returns {void}
  87. */
  88. _onChangeServerURL(text) {
  89. this._updateProfile({
  90. serverURL: text
  91. });
  92. }
  93. _onRequestClose: () => void;
  94. /**
  95. * Handles the back button.
  96. *
  97. * @returns {void}
  98. */
  99. _onRequestClose() {
  100. this.props.dispatch(hideAppSettings());
  101. }
  102. _onStartAudioMutedChange: (boolean) => void;
  103. /**
  104. * Handles the start audio muted change event.
  105. *
  106. * @protected
  107. * @param {boolean} newValue - The new value for the
  108. * start audio muted option.
  109. * @returns {void}
  110. */
  111. _onStartAudioMutedChange(newValue) {
  112. this._updateProfile({
  113. startWithAudioMuted: newValue
  114. });
  115. }
  116. _onStartVideoMutedChange: (boolean) => void;
  117. /**
  118. * Handles the start video muted change event.
  119. *
  120. * @protected
  121. * @param {boolean} newValue - The new value for the
  122. * start video muted option.
  123. * @returns {void}
  124. */
  125. _onStartVideoMutedChange(newValue) {
  126. this._updateProfile({
  127. startWithVideoMuted: newValue
  128. });
  129. }
  130. _updateProfile: (Object) => void;
  131. /**
  132. * Updates the persisted profile on any change.
  133. *
  134. * @private
  135. * @param {Object} updateObject - The partial update object for the profile.
  136. * @returns {void}
  137. */
  138. _updateProfile(updateObject: Object) {
  139. this.props.dispatch(updateProfile({
  140. ...this.props._profile,
  141. ...updateObject
  142. }));
  143. }
  144. }
  145. /**
  146. * Maps (parts of) the redux state to the React {@code Component} props of
  147. * {@code AbstractAppSettings}.
  148. *
  149. * @param {Object} state - The redux state.
  150. * @protected
  151. * @returns {Object}
  152. */
  153. export function _mapStateToProps(state: Object) {
  154. const _serverURL = state['features/app'].app._getDefaultURL();
  155. const _profile = getProfile(state);
  156. return {
  157. _aspectRatio: state['features/base/aspect-ratio'].aspectRatio,
  158. _serverURL,
  159. _profile,
  160. _visible: state['features/app-settings'].visible
  161. };
  162. }