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

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