您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AbstractDisplayNamePrompt.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 AbstractDisplayNamePrompt}.
  7. */
  8. export type Props = {
  9. /**
  10. * Invoked to update the local participant's display name.
  11. */
  12. dispatch: Dispatch<*>,
  13. /**
  14. * Function to be invoked after a successful display name change.
  15. */
  16. onPostSubmit: ?Function,
  17. /**
  18. * Invoked to obtain translated strings.
  19. */
  20. t: Function
  21. };
  22. /**
  23. * Implements an abstract class for {@code DisplayNamePrompt}.
  24. */
  25. export default class AbstractDisplayNamePrompt<S: *>
  26. extends Component<Props, S> {
  27. /**
  28. * Instantiates a new component.
  29. *
  30. * @inheritdoc
  31. */
  32. constructor(props: Props) {
  33. super(props);
  34. this._onSetDisplayName = this._onSetDisplayName.bind(this);
  35. }
  36. _onSetDisplayName: string => boolean;
  37. /**
  38. * Dispatches an action to update the local participant's display name. A
  39. * name must be entered for the action to dispatch.
  40. *
  41. * It returns a boolean to comply the Dialog behaviour:
  42. * {@code true} - the dialog should be closed.
  43. * {@code false} - the dialog should be left open.
  44. *
  45. * @param {string} displayName - The display name to save.
  46. * @returns {boolean}
  47. */
  48. _onSetDisplayName(displayName) {
  49. if (!displayName || !displayName.trim()) {
  50. return false;
  51. }
  52. const { dispatch, onPostSubmit } = this.props;
  53. // Store display name in settings
  54. dispatch(updateSettings({
  55. displayName
  56. }));
  57. onPostSubmit && onPostSubmit();
  58. return true;
  59. }
  60. }