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

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