Bläddra i källkod

feat(display-name): convert prompt to react

Create a new component that uses Dialog. Reuse existing actions
for updating a participant's display name.
master
Leonard Kim 8 år sedan
förälder
incheckning
002e48b886

+ 2
- 47
modules/UI/UI.js Visa fil

@@ -29,6 +29,7 @@ import { setAudioMuted, setVideoMuted } from '../../react/features/base/media';
29 29
 import {
30 30
     openDeviceSelectionDialog
31 31
 } from '../../react/features/device-selection';
32
+import { openDisplayNamePrompt } from '../../react/features/display-name';
32 33
 import {
33 34
     checkAutoEnableDesktopSharing,
34 35
     dockToolbox,
@@ -867,53 +868,7 @@ UI.participantConnectionStatusChanged = function (id) {
867 868
  * Prompt user for nickname.
868 869
  */
869 870
 UI.promptDisplayName = () => {
870
-    const labelKey = 'dialog.enterDisplayName';
871
-    const message = (
872
-        `<div class="form-control">
873
-            <label data-i18n="${labelKey}" class="form-control__label"></label>
874
-            <input name="displayName" type="text"
875
-               data-i18n="[placeholder]defaultNickname"
876
-               class="input-control" autofocus>
877
-         </div>`
878
-    );
879
-
880
-    // Don't use a translation string, because we're too early in the call and
881
-    // the translation may not be initialised.
882
-    const buttons = { Ok: true };
883
-
884
-    const dialog = messageHandler.openDialog(
885
-        'dialog.displayNameRequired',
886
-        message,
887
-        true,
888
-        buttons,
889
-        (e, v, m, f) => {
890
-            e.preventDefault();
891
-            if (v) {
892
-                const displayName = f.displayName;
893
-
894
-                if (displayName) {
895
-                    UI.inputDisplayNameHandler(displayName);
896
-                    dialog.close();
897
-                    return;
898
-                }
899
-            }
900
-        },
901
-        () => {
902
-            const form  = $.prompt.getPrompt();
903
-            const input = form.find("input[name='displayName']");
904
-            const button = form.find("button");
905
-
906
-            input.focus();
907
-            button.attr("disabled", "disabled");
908
-            input.keyup(() => {
909
-                if (input.val()) {
910
-                    button.removeAttr("disabled");
911
-                } else {
912
-                    button.attr("disabled", "disabled");
913
-                }
914
-            });
915
-        }
916
-    );
871
+    APP.store.dispatch(openDisplayNamePrompt());
917 872
 };
918 873
 
919 874
 /**

+ 12
- 0
react/features/display-name/actions.js Visa fil

@@ -0,0 +1,12 @@
1
+import { openDialog } from '../../features/base/dialog';
2
+
3
+import { DisplayNamePrompt } from './components';
4
+
5
+/**
6
+ * Signals to open a dialog with the {@code DisplayNamePrompt} component.
7
+ *
8
+ * @returns {Object}
9
+ */
10
+export function openDisplayNamePrompt() {
11
+    return openDialog(DisplayNamePrompt);
12
+}

+ 0
- 0
react/features/display-name/components/DisplayName.native.js Visa fil


react/features/display-name/components/DisplayName.js → react/features/display-name/components/DisplayName.web.js Visa fil


+ 0
- 0
react/features/display-name/components/DisplayNamePrompt.native.js Visa fil


+ 150
- 0
react/features/display-name/components/DisplayNamePrompt.web.js Visa fil

@@ -0,0 +1,150 @@
1
+import AKFieldText from '@atlaskit/field-text';
2
+import React, { Component } from 'react';
3
+import { connect } from 'react-redux';
4
+
5
+import { Dialog } from '../../base/dialog';
6
+import { translate } from '../../base/i18n';
7
+import {
8
+    getLocalParticipant,
9
+    participantDisplayNameChanged
10
+} from '../../base/participants';
11
+
12
+/**
13
+ * Implements a React {@code Component} for displaying a dialog with an field
14
+ * for setting the local participant's display name.
15
+ *
16
+ * @extends Component
17
+ */
18
+class DisplayNamePrompt extends Component {
19
+    /**
20
+     * {@code DisplayNamePrompt} component's property types.
21
+     *
22
+     * @static
23
+     */
24
+    static propTypes = {
25
+        /**
26
+         * The current ID for the local participant. Used for setting the
27
+         * display name on the associated participant.
28
+         */
29
+        _localParticipantID: React.PropTypes.string,
30
+
31
+        /**
32
+         * Invoked to update the local participant's display name.
33
+         */
34
+        dispatch: React.PropTypes.func,
35
+
36
+        /**
37
+         * Invoked to obtain translated strings.
38
+         */
39
+        t: React.PropTypes.func
40
+    };
41
+
42
+    /**
43
+     * Initializes a new {@code DisplayNamePrompt} instance.
44
+     *
45
+     * @param {Object} props - The read-only properties with which the new
46
+     * instance is to be initialized.
47
+     */
48
+    constructor(props) {
49
+        super(props);
50
+
51
+        this.state = {
52
+            /**
53
+             * The name to show in the display name text field.
54
+             *
55
+             * @type {string}
56
+             */
57
+            displayName: ''
58
+        };
59
+
60
+        // Bind event handlers so they are only bound once for every instance.
61
+        this._onDisplayNameChange = this._onDisplayNameChange.bind(this);
62
+        this._onSubmit = this._onSubmit.bind(this);
63
+    }
64
+
65
+    /**
66
+     * Implements React's {@link Component#render()}.
67
+     *
68
+     * @inheritdoc
69
+     * @returns {ReactElement}
70
+     */
71
+    render() {
72
+        return (
73
+            <Dialog
74
+                isModal = { true }
75
+                onSubmit = { this._onSubmit }
76
+                titleKey = 'dialog.displayNameRequired'
77
+                width = 'small'>
78
+                <AKFieldText
79
+                    autoFocus = { true }
80
+                    compact = { true }
81
+                    label = { this.props.t('dialog.enterDisplayName') }
82
+                    name = 'displayName'
83
+                    onChange = { this._onDisplayNameChange }
84
+                    shouldFitContainer = { true }
85
+                    type = 'text'
86
+                    value = { this.state.displayName } />
87
+            </Dialog>);
88
+    }
89
+
90
+    /**
91
+     * Updates the entered display name.
92
+     *
93
+     * @param {Object} event - The DOM event triggered from the entered display
94
+     * name value having changed.
95
+     * @private
96
+     * @returns {void}
97
+     */
98
+    _onDisplayNameChange(event) {
99
+        this.setState({
100
+            displayName: event.target.value
101
+        });
102
+    }
103
+
104
+    /**
105
+     * Dispatches an action to update the local participant's display name. A
106
+     * name must be entered for the action to dispatch.
107
+     *
108
+     * @private
109
+     * @returns {void}
110
+     */
111
+    _onSubmit() {
112
+        const { displayName } = this.state;
113
+
114
+        if (!displayName.trim()) {
115
+            return false;
116
+        }
117
+
118
+        const { dispatch, _localParticipantID } = this.props;
119
+
120
+        dispatch(
121
+            participantDisplayNameChanged(_localParticipantID, displayName));
122
+
123
+        return true;
124
+    }
125
+}
126
+
127
+/**
128
+ * Maps (parts of) the Redux state to the associated {@code DisplayNamePrompt}'s
129
+ * props.
130
+ *
131
+ * @param {Object} state - The Redux state.
132
+ * @private
133
+ * @returns {{
134
+ *     _localParticipantID: string
135
+ * }}
136
+ */
137
+function _mapStateToProps(state) {
138
+    const { id } = getLocalParticipant(state);
139
+
140
+    return {
141
+        /**
142
+         * The current ID for the local participant.
143
+         *
144
+         * @type {string}
145
+         */
146
+        _localParticipantID: id
147
+    };
148
+}
149
+
150
+export default translate(connect(_mapStateToProps)(DisplayNamePrompt));

+ 1
- 0
react/features/display-name/components/index.js Visa fil

@@ -1 +1,2 @@
1 1
 export { default as DisplayName } from './DisplayName';
2
+export { default as DisplayNamePrompt } from './DisplayNamePrompt';

+ 1
- 0
react/features/display-name/index.js Visa fil

@@ -1 +1,2 @@
1
+export * from './actions';
1 2
 export * from './components';

Laddar…
Avbryt
Spara