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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. }
  60. _onChangeDisplayName: (string) => void;
  61. /**
  62. * Handles the display name field value change.
  63. *
  64. * @param {string} text - The value typed in the name field.
  65. * @protected
  66. * @returns {void}
  67. */
  68. _onChangeDisplayName(text) {
  69. this._updateSettings({
  70. displayName: text
  71. });
  72. }
  73. _onChangeEmail: (string) => void;
  74. /**
  75. * Handles the email field value change.
  76. *
  77. * @param {string} text - The value typed in the email field.
  78. * @protected
  79. * @returns {void}
  80. */
  81. _onChangeEmail(text) {
  82. this._updateSettings({
  83. email: text
  84. });
  85. }
  86. _onChangeServerURL: (string) => void;
  87. /**
  88. * Handles the server name field value change.
  89. *
  90. * @param {string} text - The server URL typed in the server field.
  91. * @protected
  92. * @returns {void}
  93. */
  94. _onChangeServerURL(text) {
  95. this._updateSettings({
  96. serverURL: text
  97. });
  98. }
  99. _onStartAudioMutedChange: (boolean) => void;
  100. /**
  101. * Handles the start audio muted change event.
  102. *
  103. * @param {boolean} newValue - The new value for the start audio muted
  104. * option.
  105. * @protected
  106. * @returns {void}
  107. */
  108. _onStartAudioMutedChange(newValue) {
  109. this._updateSettings({
  110. startWithAudioMuted: newValue
  111. });
  112. }
  113. _onStartVideoMutedChange: (boolean) => void;
  114. /**
  115. * Handles the start video muted change event.
  116. *
  117. * @param {boolean} newValue - The new value for the start video muted
  118. * option.
  119. * @protected
  120. * @returns {void}
  121. */
  122. _onStartVideoMutedChange(newValue) {
  123. this._updateSettings({
  124. startWithVideoMuted: newValue
  125. });
  126. }
  127. _updateSettings: (Object) => void;
  128. /**
  129. * Updates the persisted settings on any change.
  130. *
  131. * @param {Object} updateObject - The partial update object for the
  132. * settings.
  133. * @private
  134. * @returns {void}
  135. */
  136. _updateSettings(updateObject: Object) {
  137. this.props.dispatch(updateSettings(updateObject));
  138. }
  139. }
  140. /**
  141. * Maps (parts of) the redux state to the React {@code Component} props of
  142. * {@code AbstractSettingsView}.
  143. *
  144. * @param {Object} state - The redux state.
  145. * @protected
  146. * @returns {{
  147. * _serverURL: string,
  148. * _settings: Object,
  149. * _visible: boolean
  150. * }}
  151. */
  152. export function _mapStateToProps(state: Object) {
  153. return {
  154. _serverURL: getDefaultURL(state),
  155. _settings: state['features/base/settings'],
  156. _visible: state['features/settings'].visible
  157. };
  158. }