"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-7323/react/features/display-name/components/AbstractDisplayNamePrompt.tsx" (7 Jun 2023, 1708 Bytes) of package /linux/misc/jitsi-meet-7323.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TSX (TypeScript with React) source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 import { Component } from 'react';
    2 import { WithTranslation } from 'react-i18next';
    3 
    4 import { IStore } from '../../app/types';
    5 import { updateSettings } from '../../base/settings/actions';
    6 
    7 /**
    8  * The type of the React {@code Component} props of
    9  * {@link AbstractDisplayNamePrompt}.
   10  */
   11 export interface IProps extends WithTranslation {
   12 
   13     /**
   14      * Invoked to update the local participant's display name.
   15      */
   16     dispatch: IStore['dispatch'];
   17 
   18     /**
   19      * Function to be invoked after a successful display name change.
   20      */
   21     onPostSubmit?: Function;
   22 }
   23 
   24 /**
   25  * Implements an abstract class for {@code DisplayNamePrompt}.
   26  */
   27 export default class AbstractDisplayNamePrompt<S>
   28     extends Component<IProps, S> {
   29     /**
   30      * Instantiates a new component.
   31      *
   32      * @inheritdoc
   33      */
   34     constructor(props: IProps) {
   35         super(props);
   36 
   37         this._onSetDisplayName = this._onSetDisplayName.bind(this);
   38     }
   39 
   40     /**
   41      * Dispatches an action to update the local participant's display name. A
   42      * name must be entered for the action to dispatch.
   43      *
   44      * It returns a boolean to comply the Dialog behaviour:
   45      *     {@code true} - the dialog should be closed.
   46      *     {@code false} - the dialog should be left open.
   47      *
   48      * @param {string} displayName - The display name to save.
   49      * @returns {boolean}
   50      */
   51     _onSetDisplayName(displayName: string) {
   52         if (!displayName?.trim()) {
   53             return false;
   54         }
   55 
   56         const { dispatch, onPostSubmit } = this.props;
   57 
   58         // Store display name in settings
   59         dispatch(updateSettings({
   60             displayName
   61         }));
   62 
   63         onPostSubmit?.();
   64 
   65         return true;
   66     }
   67 }