Bladeren bron

Flow, coding style

master
Lyubo Marinov 7 jaren geleden
bovenliggende
commit
2eb36c4053

+ 0
- 10
react/features/authentication/actionTypes.js Bestand weergeven

@@ -8,16 +8,6 @@
8 8
  */
9 9
 export const CANCEL_LOGIN = Symbol('CANCEL_LOGIN');
10 10
 
11
-/**
12
- * The type of (redux) action which signals that the {@link WaitForOwnerDialog}
13
- * has been canceled.
14
- *
15
- * {
16
- *     type: CANCEL_WAIT_FOR_OWNER
17
- * }
18
- */
19
-export const CANCEL_WAIT_FOR_OWNER = Symbol('CANCEL_WAIT_FOR_OWNER');
20
-
21 11
 /**
22 12
  * The type of (redux) action which signals that the cyclic operation of waiting
23 13
  * for conference owner has been aborted.

+ 8
- 9
react/features/authentication/actions.js Bestand weergeven

@@ -1,11 +1,11 @@
1
-/* @flow */
1
+// @flow
2 2
 
3
+import { appNavigate } from '../app';
3 4
 import { checkIfCanJoin } from '../base/conference';
4 5
 import { openDialog } from '../base/dialog';
5 6
 
6 7
 import {
7 8
     CANCEL_LOGIN,
8
-    CANCEL_WAIT_FOR_OWNER,
9 9
     STOP_WAIT_FOR_OWNER,
10 10
     UPGRADE_ROLE_FINISHED,
11 11
     UPGRADE_ROLE_STARTED,
@@ -25,7 +25,7 @@ const logger = require('jitsi-meet-logger').getLogger(__filename);
25 25
  * @param {string} password - The XMPP user's password.
26 26
  * @param {JitsiConference} conference - The conference for which the local
27 27
  * participant's role will be upgraded.
28
- * @returns {function({ dispatch: Dispatch, getState: Function })}
28
+ * @returns {Function}
29 29
  */
30 30
 export function authenticateAndUpgradeRole(
31 31
         id: string,
@@ -79,13 +79,12 @@ export function cancelLogin() {
79 79
 /**
80 80
  * Cancels {@link WaitForOwnerDialog}. Will navigate back to the welcome page.
81 81
  *
82
- * @returns {{
83
- *     type: CANCEL_WAIT_FOR_OWNER
84
- * }}
82
+ * @returns {Function}
85 83
  */
86 84
 export function cancelWaitForOwner() {
87
-    return {
88
-        type: CANCEL_WAIT_FOR_OWNER
85
+    return (dispatch: Dispatch<*>) => {
86
+        dispatch(stopWaitForOwner());
87
+        dispatch(appNavigate(undefined));
89 88
     };
90 89
 }
91 90
 
@@ -197,7 +196,7 @@ function _upgradeRoleStarted(thenableWithCancel) {
197 196
  * start the process of "waiting for the owner" by periodically trying to join
198 197
  * the room every five seconds.
199 198
  *
200
- * @returns {function({ dispatch: Dispatch })}
199
+ * @returns {Function}
201 200
  */
202 201
 export function waitForOwner() {
203 202
     return (dispatch: Dispatch) =>

+ 4
- 14
react/features/authentication/middleware.js Bestand weergeven

@@ -22,7 +22,6 @@ import {
22 22
 } from './actions';
23 23
 import {
24 24
     CANCEL_LOGIN,
25
-    CANCEL_WAIT_FOR_OWNER,
26 25
     STOP_WAIT_FOR_OWNER,
27 26
     WAIT_FOR_OWNER
28 27
 } from './actionTypes';
@@ -40,8 +39,8 @@ import { LoginDialog, WaitForOwnerDialog } from './components';
40 39
 MiddlewareRegistry.register(store => next => action => {
41 40
     switch (action.type) {
42 41
     case CANCEL_LOGIN: {
43
-        const { thenableWithCancel }
44
-            = store.getState()['features/authentication'];
42
+        const { dispatch, getState } = store;
43
+        const { thenableWithCancel } = getState()['features/authentication'];
45 44
 
46 45
         thenableWithCancel && thenableWithCancel.cancel();
47 46
 
@@ -53,27 +52,18 @@ MiddlewareRegistry.register(store => next => action => {
53 52
                 // Instead of hiding show the new one.
54 53
                 const result = next(action);
55 54
 
56
-                store.dispatch(_openWaitForOwnerDialog());
55
+                dispatch(_openWaitForOwnerDialog());
57 56
 
58 57
                 return result;
59 58
             }
60 59
 
61 60
             // Go back to the app's entry point.
62 61
             _hideLoginDialog(store);
63
-            store.dispatch(appNavigate(undefined));
62
+            dispatch(appNavigate(undefined));
64 63
         }
65 64
         break;
66 65
     }
67 66
 
68
-    case CANCEL_WAIT_FOR_OWNER: {
69
-        const result = next(action);
70
-
71
-        store.dispatch(stopWaitForOwner());
72
-        store.dispatch(appNavigate(undefined));
73
-
74
-        return result;
75
-    }
76
-
77 67
     case CONFERENCE_FAILED:
78 68
         if (action.error.name
79 69
                 === JitsiConferenceErrors.AUTHENTICATION_REQUIRED) {

+ 11
- 2
react/features/base/dialog/components/AbstractDialog.js Bestand weergeven

@@ -71,6 +71,15 @@ export default class AbstractDialog extends Component {
71 71
         this._mounted = false;
72 72
     }
73 73
 
74
+    /**
75
+     * Dispatches a redux action to hide this dialog.
76
+     *
77
+     * @returns {*} The return value of {@link hideDialog}.
78
+     */
79
+    _hide() {
80
+        return this.props.dispatch(hideDialog());
81
+    }
82
+
74 83
     _onCancel: () => void;
75 84
 
76 85
     /**
@@ -84,7 +93,7 @@ export default class AbstractDialog extends Component {
84 93
 
85 94
         if ((typeof cancelDisabled === 'undefined' || !cancelDisabled)
86 95
                 && (!onCancel || onCancel())) {
87
-            this.props.dispatch(hideDialog());
96
+            this._hide();
88 97
         }
89 98
     }
90 99
 
@@ -147,7 +156,7 @@ export default class AbstractDialog extends Component {
147 156
     _onSubmitFulfilled() {
148 157
         this._mounted && this.setState({ submitting: false });
149 158
 
150
-        this.props.dispatch(hideDialog());
159
+        this._hide();
151 160
     }
152 161
 
153 162
     _onSubmitRejected: () => void;

+ 1
- 1
react/features/base/react/components/web/index.js Bestand weergeven

@@ -1,4 +1,4 @@
1 1
 export { default as Container } from './Container';
2
+export { default as MultiSelectAutocomplete } from './MultiSelectAutocomplete';
2 3
 export { default as Text } from './Text';
3 4
 export { default as Watermarks } from './Watermarks';
4
-export { default as MultiSelectAutocomplete } from './MultiSelectAutocomplete';

+ 45
- 28
react/features/desktop-picker/components/DesktopPicker.js Bestand weergeven

@@ -1,3 +1,5 @@
1
+// @flow
2
+
1 3
 import Tabs from '@atlaskit/tabs';
2 4
 import PropTypes from 'prop-types';
3 5
 import React, { Component } from 'react';
@@ -15,7 +17,12 @@ const THUMBNAIL_SIZE = {
15 17
 };
16 18
 const UPDATE_INTERVAL = 1000;
17 19
 
18
-const TAB_CONFIGURATIONS = [
20
+type TabConfiguration = {
21
+    defaultSelected?: boolean,
22
+    label: string,
23
+    type: string
24
+};
25
+const TAB_CONFIGURATIONS: Array<TabConfiguration> = [
19 26
     {
20 27
         /**
21 28
          * The indicator which determines whether this tab configuration is
@@ -83,6 +90,14 @@ class DesktopPicker extends Component {
83 90
         t: PropTypes.func
84 91
     };
85 92
 
93
+    _poller = null;
94
+
95
+    state = {
96
+        selectedSource: {},
97
+        tabsToPopulate: [],
98
+        typesToFetch: []
99
+    };
100
+
86 101
     /**
87 102
      * Initializes a new DesktopPicker instance.
88 103
      *
@@ -92,13 +107,7 @@ class DesktopPicker extends Component {
92 107
     constructor(props) {
93 108
         super(props);
94 109
 
95
-        this.state = {
96
-            selectedSource: {},
97
-            tabsToPopulate: [],
98
-            typesToFetch: []
99
-        };
100
-
101
-        this._poller = null;
110
+        // Bind event handlers so they are only bound once per instance.
102 111
         this._onCloseModal = this._onCloseModal.bind(this);
103 112
         this._onPreviewClick = this._onPreviewClick.bind(this);
104 113
         this._onSubmit = this._onSubmit.bind(this);
@@ -175,12 +184,14 @@ class DesktopPicker extends Component {
175 184
         );
176 185
     }
177 186
 
187
+    _onCloseModal: (?string, string) => void;
188
+
178 189
     /**
179 190
      * Dispatches an action to hide the DesktopPicker and invokes the passed in
180 191
      * callback with a selectedSource, if any.
181 192
      *
182
-     * @param {string} id - The id of the DesktopCapturerSource to pass into the
183
-     * onSourceChoose callback.
193
+     * @param {string} [id] - The id of the DesktopCapturerSource to pass into
194
+     * the onSourceChoose callback.
184 195
      * @param {string} type - The type of the DesktopCapturerSource to pass into
185 196
      * the onSourceChoose callback.
186 197
      * @returns {void}
@@ -190,6 +201,8 @@ class DesktopPicker extends Component {
190 201
         this.props.dispatch(hideDialog());
191 202
     }
192 203
 
204
+    _onPreviewClick: (string, string) => void;
205
+
193 206
     /**
194 207
      * Sets the currently selected DesktopCapturerSource.
195 208
      *
@@ -206,6 +219,27 @@ class DesktopPicker extends Component {
206 219
         });
207 220
     }
208 221
 
222
+    /**
223
+     * Handles changing of allowed desktop sharing source types.
224
+     *
225
+     * @param {Array<string>} desktopSharingSourceTypes - The types that will be
226
+     * fetched and displayed.
227
+     * @returns {void}
228
+     */
229
+    _onSourceTypesConfigChanged(desktopSharingSourceTypes = []) {
230
+        const tabsToPopulate
231
+            = TAB_CONFIGURATIONS.filter(({ type }) =>
232
+                desktopSharingSourceTypes.includes(type)
233
+                    && VALID_TYPES.includes(type));
234
+
235
+        this.setState({
236
+            tabsToPopulate,
237
+            typesToFetch: tabsToPopulate.map(c => c.type)
238
+        });
239
+    }
240
+
241
+    _onSubmit: () => void;
242
+
209 243
     /**
210 244
      * Request to close the modal and execute callbacks with the selected source
211 245
      * id.
@@ -268,24 +302,7 @@ class DesktopPicker extends Component {
268 302
         this._poller = null;
269 303
     }
270 304
 
271
-    /**
272
-     * Handles changing of allowed desktop sharing source types.
273
-     *
274
-     * @param {Array<string>} desktopSharingSourceTypes - The types that will be
275
-     * fetched and displayed.
276
-     * @returns {void}
277
-     */
278
-    _onSourceTypesConfigChanged(desktopSharingSourceTypes = []) {
279
-        const tabsToPopulate = TAB_CONFIGURATIONS.filter(
280
-            c => desktopSharingSourceTypes.includes(c.type)
281
-                && VALID_TYPES.includes(c.type)
282
-        );
283
-
284
-        this.setState({
285
-            tabsToPopulate,
286
-            typesToFetch: tabsToPopulate.map(c => c.type)
287
-        });
288
-    }
305
+    _updateSources: () => void;
289 306
 
290 307
     /**
291 308
      * Dispatches an action to get currently available DesktopCapturerSources.

+ 107
- 98
react/features/invite/components/AddPeopleDialog.web.js Bestand weergeven

@@ -1,3 +1,5 @@
1
+// @flow
2
+
1 3
 import Avatar from '@atlaskit/avatar';
2 4
 import InlineMessage from '@atlaskit/inline-message';
3 5
 import { Immutable } from 'nuclear-js';
@@ -8,8 +10,7 @@ import { connect } from 'react-redux';
8 10
 import { getInviteURL } from '../../base/connection';
9 11
 import { Dialog, hideDialog } from '../../base/dialog';
10 12
 import { translate } from '../../base/i18n';
11
-import MultiSelectAutocomplete
12
-    from '../../base/react/components/web/MultiSelectAutocomplete';
13
+import { MultiSelectAutocomplete } from '../../base/react';
13 14
 
14 15
 import { invitePeople, inviteRooms, searchPeople } from '../functions';
15 16
 
@@ -67,6 +68,54 @@ class AddPeopleDialog extends Component {
67 68
         t: PropTypes.func
68 69
     };
69 70
 
71
+    _multiselect = null;
72
+
73
+    _resourceClient = {
74
+        makeQuery: text => {
75
+            const {
76
+                _jwt,
77
+                _peopleSearchQueryTypes,
78
+                _peopleSearchUrl
79
+            } = this.props; // eslint-disable-line no-invalid-this
80
+
81
+            return (
82
+                searchPeople(
83
+                    _peopleSearchUrl,
84
+                    _jwt,
85
+                    text,
86
+                    _peopleSearchQueryTypes));
87
+        },
88
+
89
+        parseResults: response => response.map(user => {
90
+            return {
91
+                content: user.name,
92
+                elemBefore: <Avatar
93
+                    size = 'medium'
94
+                    src = { user.avatar } />,
95
+                item: user,
96
+                value: user.id
97
+            };
98
+        })
99
+    };
100
+
101
+    state = {
102
+        /**
103
+         * Indicating that an error occurred when adding people to the call.
104
+         */
105
+        addToCallError: false,
106
+
107
+        /**
108
+         * Indicating that we're currently adding the new people to the
109
+         * call.
110
+         */
111
+        addToCallInProgress: false,
112
+
113
+        /**
114
+         * The list of invite items.
115
+         */
116
+        inviteItems: new Immutable.List()
117
+    };
118
+
70 119
     /**
71 120
      * Initializes a new {@code AddPeopleDialog} instance.
72 121
      *
@@ -76,56 +125,7 @@ class AddPeopleDialog extends Component {
76 125
     constructor(props) {
77 126
         super(props);
78 127
 
79
-        this.state = {
80
-            /**
81
-             * Indicating that an error occurred when adding people to the call.
82
-             */
83
-            addToCallError: false,
84
-
85
-            /**
86
-             * Indicating that we're currently adding the new people to the
87
-             * call.
88
-             */
89
-            addToCallInProgress: false,
90
-
91
-            /**
92
-             * The list of invite items.
93
-             */
94
-            inviteItems: new Immutable.List()
95
-        };
96
-
97
-        this._multiselect = null;
98
-        this._resourceClient = {
99
-            makeQuery: text => {
100
-                const {
101
-                    _jwt,
102
-                    _peopleSearchQueryTypes,
103
-                    _peopleSearchUrl
104
-                } = this.props;
105
-
106
-                return searchPeople(
107
-                    _peopleSearchUrl,
108
-                    _jwt,
109
-                    text,
110
-                    _peopleSearchQueryTypes
111
-                );
112
-            },
113
-            parseResults: response => response.map(user => {
114
-                const avatar = ( // eslint-disable-line no-extra-parens
115
-                    <Avatar
116
-                        size = 'medium'
117
-                        src = { user.avatar } />
118
-                );
119
-
120
-                return {
121
-                    content: user.name,
122
-                    value: user.id,
123
-                    elemBefore: avatar,
124
-                    item: user
125
-                };
126
-            })
127
-        };
128
-
128
+        // Bind event handlers so they are only bound once per instance.
129 129
         this._isAddDisabled = this._isAddDisabled.bind(this);
130 130
         this._onSelectionChange = this._onSelectionChange.bind(this);
131 131
         this._onSubmit = this._onSubmit.bind(this);
@@ -144,9 +144,9 @@ class AddPeopleDialog extends Component {
144 144
          * invite.
145 145
          */
146 146
         if (prevState.addToCallError
147
-            && !this.state.addToCallInProgress
148
-            && !this.state.addToCallError
149
-            && this._multiselect) {
147
+                && !this.state.addToCallInProgress
148
+                && !this.state.addToCallError
149
+                && this._multiselect) {
150 150
             this._multiselect.clear();
151 151
         }
152 152
     }
@@ -169,44 +169,22 @@ class AddPeopleDialog extends Component {
169 169
         );
170 170
     }
171 171
 
172
-    /**
173
-     * Renders the input form.
174
-     *
175
-     * @returns {ReactElement}
176
-     * @private
177
-     */
178
-    _renderUserInputForm() {
179
-        const { t } = this.props;
180
-
181
-        return (
182
-            <div className = 'add-people-form-wrap'>
183
-                { this._renderErrorMessage() }
184
-                <MultiSelectAutocomplete
185
-                    isDisabled
186
-                        = { this.state.addToCallInProgress || false }
187
-                    noMatchesFound = { t('addPeople.noResults') }
188
-                    onSelectionChange = { this._onSelectionChange }
189
-                    placeholder = { t('addPeople.searchPlaceholder') }
190
-                    ref = { this._setMultiSelectElement }
191
-                    resourceClient = { this._resourceClient }
192
-                    shouldFitContainer = { true }
193
-                    shouldFocus = { true } />
194
-            </div>
195
-        );
196
-    }
172
+    _isAddDisabled: () => boolean;
197 173
 
198 174
     /**
199 175
      * Indicates if the Add button should be disabled.
200 176
      *
177
+     * @private
201 178
      * @returns {boolean} - True to indicate that the Add button should
202 179
      * be disabled, false otherwise.
203
-     * @private
204 180
      */
205 181
     _isAddDisabled() {
206 182
         return !this.state.inviteItems.length
207 183
             || this.state.addToCallInProgress;
208 184
     }
209 185
 
186
+    _onSelectionChange: (Map<*, *>) => void;
187
+
210 188
     /**
211 189
      * Handles a selection change.
212 190
      *
@@ -222,6 +200,8 @@ class AddPeopleDialog extends Component {
222 200
         });
223 201
     }
224 202
 
203
+    _onSubmit: () => void;
204
+
225 205
     /**
226 206
      * Handles the submit button action.
227 207
      *
@@ -245,27 +225,28 @@ class AddPeopleDialog extends Component {
245 225
                 this.props._inviteUrl,
246 226
                 this.props._jwt,
247 227
                 this.state.inviteItems.filter(i => i.type === 'user'))
248
-            .then(() => {
249
-                this.setState({
250
-                    addToCallInProgress: false
228
+            .then(
229
+                /* onFulfilled */ () => {
230
+                    this.setState({
231
+                        addToCallInProgress: false
232
+                    });
233
+
234
+                    this.props.hideDialog();
235
+                },
236
+                /* onRejected */ () => {
237
+                    this.setState({
238
+                        addToCallInProgress: false,
239
+                        addToCallError: true
240
+                    });
251 241
                 });
252
-
253
-                this.props.hideDialog();
254
-            })
255
-            .catch(() => {
256
-                this.setState({
257
-                    addToCallInProgress: false,
258
-                    addToCallError: true
259
-                });
260
-            });
261 242
         }
262 243
     }
263 244
 
264 245
     /**
265 246
      * Renders the error message if the add doesn't succeed.
266 247
      *
267
-     * @returns {ReactElement|null}
268 248
      * @private
249
+     * @returns {ReactElement|null}
269 250
      */
270 251
     _renderErrorMessage() {
271 252
         if (!this.state.addToCallError) {
@@ -304,6 +285,34 @@ class AddPeopleDialog extends Component {
304 285
         );
305 286
     }
306 287
 
288
+    /**
289
+     * Renders the input form.
290
+     *
291
+     * @private
292
+     * @returns {ReactElement}
293
+     */
294
+    _renderUserInputForm() {
295
+        const { t } = this.props;
296
+
297
+        return (
298
+            <div className = 'add-people-form-wrap'>
299
+                { this._renderErrorMessage() }
300
+                <MultiSelectAutocomplete
301
+                    isDisabled
302
+                        = { this.state.addToCallInProgress || false }
303
+                    noMatchesFound = { t('addPeople.noResults') }
304
+                    onSelectionChange = { this._onSelectionChange }
305
+                    placeholder = { t('addPeople.searchPlaceholder') }
306
+                    ref = { this._setMultiSelectElement }
307
+                    resourceClient = { this._resourceClient }
308
+                    shouldFitContainer = { true }
309
+                    shouldFocus = { true } />
310
+            </div>
311
+        );
312
+    }
313
+
314
+    _setMultiSelectElement: (Object) => void;
315
+
307 316
     /**
308 317
      * Sets the instance variable for the multi select component
309 318
      * element so it can be accessed directly.
@@ -338,13 +347,13 @@ function _mapStateToProps(state) {
338 347
 
339 348
     return {
340 349
         _conference: conference,
341
-        _jwt: state['features/jwt'].jwt,
342
-        _inviteUrl: getInviteURL(state),
343 350
         _inviteServiceUrl: inviteServiceUrl,
351
+        _inviteUrl: getInviteURL(state),
352
+        _jwt: state['features/jwt'].jwt,
344 353
         _peopleSearchQueryTypes: peopleSearchQueryTypes,
345 354
         _peopleSearchUrl: peopleSearchUrl
346 355
     };
347 356
 }
348 357
 
349
-export default translate(
350
-    connect(_mapStateToProps, { hideDialog })(AddPeopleDialog));
358
+export default translate(connect(_mapStateToProps, { hideDialog })(
359
+    AddPeopleDialog));

+ 4
- 4
react/features/mobile/callkit/middleware.js Bestand weergeven

@@ -1,4 +1,4 @@
1
-/* @flow */
1
+// @flow
2 2
 
3 3
 import { NativeModules } from 'react-native';
4 4
 import uuid from 'uuid';
@@ -238,9 +238,9 @@ function _onPerformEndCallAction({ callUUID }) {
238 238
     const conference = getCurrentConference(getState);
239 239
 
240 240
     if (conference && conference.callUUID === callUUID) {
241
-        // We arrive here when a call is ended by the system, for
242
-        // example when another incoming call is received and the user
243
-        // selects "End & Accept".
241
+        // We arrive here when a call is ended by the system, for example, when
242
+        // another incoming call is received and the user selects "End &
243
+        // Accept".
244 244
         delete conference.callUUID;
245 245
         dispatch(appNavigate(undefined));
246 246
     }

Laden…
Annuleren
Opslaan