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

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