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

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