Преглед изворни кода

Simplify. Comply w/ coding style.

j8
Lyubomir Marinov пре 8 година
родитељ
комит
4810249301

+ 2
- 4
modules/UI/welcome_page/WelcomePage.js Прегледај датотеку

@@ -13,10 +13,8 @@ function enterRoom() {
13 13
 }
14 14
 
15 15
 function setupWelcomePage() {
16
-    /*
17
-    * XXX: We left only going to conference page here because transitions via
18
-    * React Router isn't implemented yet.
19
-    */
16
+    // XXX: We left only going to conference page here because transitions via
17
+    // React Router isn't implemented yet.
20 18
 
21 19
     $("#enter_room_button").click(function() {
22 20
         enterRoom();

+ 69
- 66
react/features/welcome/components/AbstractWelcomePage.js Прегледај датотеку

@@ -36,31 +36,30 @@ export class AbstractWelcomePage extends Component {
36 36
          * Save room name into component's local state.
37 37
          *
38 38
          * @type {Object}
39
+         * @property {number|null} animateTimeoutId - Identificator for
40
+         * letter animation timeout.
41
+         * @property {string} generatedRoomname - Automatically generated
42
+         * room name.
39 43
          * @property {string} room - Room name.
40 44
          * @property {string} roomPlaceholder - Room placeholder
41 45
          * that's used as a placeholder for input.
42
-         * @property {string} generatedRoomname - Automatically generated
43
-         * room name.
44
-         * @property {number|null} animateTimeoutId - Identificator for
45
-         * letter animation timeout.
46 46
          * @property {nubmer|null} updateTimeoutId - Identificator for
47 47
          * updating generated room name.
48 48
          */
49 49
         this.state = {
50
+            animateTimeoutId: null,
51
+            generatedRoomname: '',
50 52
             room: '',
51 53
             roomPlaceholder: '',
52
-            generatedRoomname: '',
53
-            animateTimeoutId: null,
54 54
             updateTimeoutId: null
55 55
         };
56 56
 
57 57
         // Bind event handlers so they are only bound once for every instance.
58
-        const roomnameChanging = this._animateRoomnameChanging.bind(this);
59
-
58
+        this._animateRoomnameChanging
59
+            = this._animateRoomnameChanging.bind(this);
60 60
         this._onJoin = this._onJoin.bind(this);
61 61
         this._onRoomChange = this._onRoomChange.bind(this);
62 62
         this._updateRoomname = this._updateRoomname.bind(this);
63
-        this._animateRoomnameChanging = roomnameChanging.bind(this);
64 63
     }
65 64
 
66 65
     /**
@@ -74,73 +73,34 @@ export class AbstractWelcomePage extends Component {
74 73
     }
75 74
 
76 75
     /**
77
-    * This method is executed when method will be unmounted from DOM.
78
-    *
79
-    * @inheritdoc
80
-    */
81
-    componentWillUnmount() {
82
-        this._clearTimeouts();
83
-    }
84
-
85
-    /**
86
-    * Method that clears timeouts for animations and updates of room name.
87
-    *
88
-    * @private
89
-    * @returns {void}
90
-    */
91
-    _clearTimeouts() {
92
-        clearTimeout(this.state.animateTimeoutId);
93
-        clearTimeout(this.state.updateTimeoutId);
94
-    }
95
-
96
-    /**
97
-     * Determines whether the 'Join' button is (to be) disabled i.e. there's no
98
-     * valid room name typed into the respective text input field.
76
+     * This method is executed when method will be unmounted from DOM.
99 77
      *
100
-     * @protected
101
-     * @returns {boolean} If the 'Join' button is (to be) disabled, true;
102
-     * otherwise, false.
103
-     */
104
-    _isJoinDisabled() {
105
-        return !isRoomValid(this.state.room);
106
-    }
107
-
108
-    /**
109
-     * Method triggering generation of new room name and
110
-     * initiating animation of its changing.
111
-     *
112
-     * @protected
113
-     * @returns {void}
78
+     * @inheritdoc
114 79
      */
115
-    _updateRoomname() {
116
-        const generatedRoomname = generateRoomWithoutSeparator();
117
-        const roomPlaceholder = '';
118
-        const updateTimeoutId = setTimeout(this._updateRoomname, 10000);
119
-
80
+    componentWillUnmount() {
120 81
         this._clearTimeouts();
121
-        this.setState({
122
-            updateTimeoutId,
123
-            generatedRoomname,
124
-            roomPlaceholder
125
-        }, () => this._animateRoomnameChanging(generatedRoomname));
126 82
     }
127 83
 
128 84
     /**
129
-     * Method animating changing room name.
85
+     * Animates the changing of the room name.
130 86
      *
131
-     * @param {string} word - The part of room name that should
132
-     * be added to placeholder.
87
+     * @param {string} word - The part of room name that should be added to
88
+     * placeholder.
133 89
      * @private
134 90
      * @returns {void}
135 91
      */
136 92
     _animateRoomnameChanging(word) {
137
-        const roomPlaceholder = this.state.roomPlaceholder + word.substr(0, 1);
138 93
         let animateTimeoutId = null;
94
+        const roomPlaceholder = this.state.roomPlaceholder + word.substr(0, 1);
139 95
 
140 96
         if (word.length > 1) {
141
-            animateTimeoutId = setTimeout(() => {
142
-                this._animateRoomnameChanging(word.substring(1, word.length));
143
-            }, 70);
97
+            animateTimeoutId
98
+                = setTimeout(
99
+                        () => {
100
+                            this._animateRoomnameChanging(
101
+                                    word.substring(1, word.length));
102
+                        },
103
+                        70);
144 104
         }
145 105
 
146 106
         this.setState({
@@ -149,6 +109,29 @@ export class AbstractWelcomePage extends Component {
149 109
         });
150 110
     }
151 111
 
112
+    /**
113
+     * Method that clears timeouts for animations and updates of room name.
114
+     *
115
+     * @private
116
+     * @returns {void}
117
+     */
118
+    _clearTimeouts() {
119
+        clearTimeout(this.state.animateTimeoutId);
120
+        clearTimeout(this.state.updateTimeoutId);
121
+    }
122
+
123
+    /**
124
+     * Determines whether the 'Join' button is (to be) disabled i.e. there's no
125
+     * valid room name typed into the respective text input field.
126
+     *
127
+     * @protected
128
+     * @returns {boolean} If the 'Join' button is (to be) disabled, true;
129
+     * otherwise, false.
130
+     */
131
+    _isJoinDisabled() {
132
+        return !isRoomValid(this.state.room);
133
+    }
134
+
152 135
     /**
153 136
      * Handles joining. Either by clicking on 'Join' button
154 137
      * or by pressing 'Enter' in room name input field.
@@ -157,12 +140,10 @@ export class AbstractWelcomePage extends Component {
157 140
      * @returns {void}
158 141
      */
159 142
     _onJoin() {
160
-        const { room, generatedRoomname } = this.state;
143
+        const room = this.state.room || this.state.generatedRoomname;
161 144
 
162
-        if (room && room.length) {
145
+        if (room) {
163 146
             this.props.dispatch(appNavigate(room));
164
-        } else {
165
-            this.props.dispatch(appNavigate(generatedRoomname));
166 147
         }
167 148
     }
168 149
 
@@ -189,6 +170,28 @@ export class AbstractWelcomePage extends Component {
189 170
             <VideoTrack videoTrack = { this.props.localVideoTrack } />
190 171
         );
191 172
     }
173
+
174
+    /**
175
+     * Triggers the generation of a new room name and initiates an animation of
176
+     * its changing.
177
+     *
178
+     * @protected
179
+     * @returns {void}
180
+     */
181
+    _updateRoomname() {
182
+        const generatedRoomname = generateRoomWithoutSeparator();
183
+        const roomPlaceholder = '';
184
+        const updateTimeoutId = setTimeout(this._updateRoomname, 10000);
185
+
186
+        this._clearTimeouts();
187
+        this.setState(
188
+            {
189
+                generatedRoomname,
190
+                roomPlaceholder,
191
+                updateTimeoutId
192
+            },
193
+            () => this._animateRoomnameChanging(generatedRoomname));
194
+    }
192 195
 }
193 196
 
194 197
 /**

+ 173
- 177
react/features/welcome/components/WelcomePage.web.js Прегледај датотеку

@@ -1,113 +1,59 @@
1
-/* global interfaceConfig, APP  */
1
+/* global APP, interfaceConfig */
2 2
 
3 3
 import React from 'react';
4 4
 import { connect } from 'react-redux';
5 5
 
6
-import {
7
-    AbstractWelcomePage,
8
-    mapStateToProps
9
-} from './AbstractWelcomePage';
6
+import { Conference } from '../../conference';
7
+
8
+import { AbstractWelcomePage, mapStateToProps } from './AbstractWelcomePage';
10 9
 
11
-const RIGHT_WATERMARK_STYLES = {
10
+/**
11
+ * The CSS style of the element with CSS class <tt>rightwatermark</tt>.
12
+ */
13
+const RIGHT_WATERMARK_STYLE = {
12 14
     backgroundImage: 'url(images/rightwatermark.png)'
13 15
 };
14 16
 
15
-import { Conference } from '../../conference';
17
+/* eslint-disable require-jsdoc */
16 18
 
17 19
 /**
18
- * The web container rendering the welcome page.
20
+ * The Web container rendering the welcome page.
21
+ *
22
+ * @extends AbstractWelcomePage
19 23
  */
20 24
 class WelcomePage extends AbstractWelcomePage {
21 25
 
26
+/* eslint-enable require-jsdoc */
27
+
22 28
     /**
23
-    * Constructor function of WelcomePage.
24
-    *
25
-    * @param {Object} props - Props to be set.
26
-    **/
29
+     * Initializes a new WelcomePage instance.
30
+     *
31
+     * @param {Object} props - The read-only properties with which the new
32
+     * instance is to be initialized.
33
+     */
27 34
     constructor(props) {
28 35
         super(props);
36
+
29 37
         this._initState();
30 38
 
31 39
         // Bind event handlers so they are only bound once for every instance.
32
-        const onToggleDisableWelcome = this._onToggleDisableWelcomePage;
33
-
34
-        this._onRoomChange = this._onRoomChange.bind(this);
40
+        this._onDisableWelcomeChange = this._onDisableWelcomeChange.bind(this);
35 41
         this._onKeyDown = this._onKeyDown.bind(this);
36
-        this._setInput = this._setInput.bind(this);
37
-        this._onUpdateRoomname = this._onUpdateRoomname.bind(this);
38
-        this._onToggleDisableWelcomePage = onToggleDisableWelcome.bind(this);
39
-    }
40
-
41
-    /**
42
-    * Method that initializes state of the component.
43
-    *
44
-    * @returns {void}
45
-    **/
46
-    _initState() {
47
-        const showPoweredBy = interfaceConfig.SHOW_POWERED_BY;
48
-        const generateRoomnames
49
-            = interfaceConfig.GENERATE_ROOMNAMES_ON_WELCOME_PAGE;
50
-        const enableWelcomePage = true;
51
-        const showJitsiWatermark = interfaceConfig.SHOW_JITSI_WATERMARK;
52
-        const showBrandWatermark = interfaceConfig.SHOW_BRAND_WATERMARK;
53
-        let jitsiWatermarkLink = '';
54
-        let brandWatermarkLink = '';
55
-
56
-        if (showJitsiWatermark) {
57
-            jitsiWatermarkLink = interfaceConfig.JITSI_WATERMARK_LINK;
58
-        }
59
-
60
-        if (showBrandWatermark) {
61
-            brandWatermarkLink = interfaceConfig.BRAND_WATERMARK_LINK;
62
-        }
63
-
64
-        this.state = Object.assign({}, this.state, {
65
-            showPoweredBy,
66
-            generateRoomnames,
67
-            showJitsiWatermark,
68
-            showBrandWatermark,
69
-            jitsiWatermarkLink,
70
-            brandWatermarkLink,
71
-            enableWelcomePage
72
-        });
73
-    }
74
-
75
-    /**
76
-    * Returns the domain name.
77
-    *
78
-    * @private
79
-    * @returns {string} Domain name.
80
-    **/
81
-    _getDomain() {
82
-        return `${window.location.protocol}//${window.location.host}/`;
42
+        this._onRoomChange = this._onRoomChange.bind(this);
83 43
     }
84 44
 
85 45
     /**
86
-    * This method is executed when comonent is mounted.
87
-    *
88
-    * @inheritdoc
89
-    */
46
+     * This method is executed when comonent is mounted.
47
+     *
48
+     * @inheritdoc
49
+     * @returns {void}
50
+     */
90 51
     componentDidMount() {
91 52
         if (this.state.generateRoomnames) {
92 53
             this._updateRoomname();
93 54
         }
94 55
     }
95 56
 
96
-    /**
97
-    * Handles toggling disable welcome page checkbox
98
-    *
99
-    * @returns {void}
100
-    **/
101
-    _onToggleDisableWelcomePage() {
102
-        const shouldEnable = this.state.enableWelcomePage;
103
-
104
-        this.setState({
105
-            enableWelcomePage: !shouldEnable
106
-        }, () => {
107
-            APP.settings.setWelcomePageEnabled(this.state.enableWelcomePage);
108
-        });
109
-    }
110
-
111 57
     /**
112 58
      * Implements React's {@link Component#render()}.
113 59
      *
@@ -137,14 +83,116 @@ class WelcomePage extends AbstractWelcomePage {
137 83
     }
138 84
 
139 85
     /**
140
-    * Sets input element as property of class.
141
-    *
142
-    * @param {HTMLInputElement} input - input element to be set.
143
-    * @returns {void}
144
-    * @private
145
-    **/
146
-    _setInput(input) {
147
-        this.roomNameInput = input;
86
+     * Returns the domain name.
87
+     *
88
+     * @private
89
+     * @returns {string} Domain name.
90
+     */
91
+    _getDomain() {
92
+        return `${window.location.protocol}//${window.location.host}/`;
93
+    }
94
+
95
+    /**
96
+     * Method that initializes state of the component.
97
+     *
98
+     * @returns {void}
99
+     */
100
+    _initState() {
101
+        const showBrandWatermark = interfaceConfig.SHOW_BRAND_WATERMARK;
102
+        const showJitsiWatermark = interfaceConfig.SHOW_JITSI_WATERMARK;
103
+
104
+        this.state = {
105
+            ...this.state,
106
+            brandWatermarkLink:
107
+                showBrandWatermark ? interfaceConfig.BRAND_WATERMARK_LINK : '',
108
+            enableWelcomePage: true,
109
+            generateRoomnames:
110
+                interfaceConfig.GENERATE_ROOMNAMES_ON_WELCOME_PAGE,
111
+            jitsiWatermarkLink:
112
+                showJitsiWatermark ? interfaceConfig.JITSI_WATERMARK_LINK : '',
113
+            showBrandWatermark,
114
+            showJitsiWatermark,
115
+            showPoweredBy: interfaceConfig.SHOW_POWERED_BY
116
+        };
117
+    }
118
+
119
+    /**
120
+     * Handles <tt>change</tt> event of the checkbox which allows specifying
121
+     * whether the WelcomePage is disabled.
122
+     *
123
+     * @param {Event} event - The (HTML) Event which details the change such as
124
+     * the EventTarget.
125
+     * @returns {void}
126
+     */
127
+    _onDisableWelcomeChange(event) {
128
+        this.setState({
129
+            enableWelcomePage: !event.target.value
130
+        }, () => {
131
+            APP.settings.setWelcomePageEnabled(this.state.enableWelcomePage);
132
+        });
133
+    }
134
+
135
+    /**
136
+     * Overrides the super in order to prevent the dispatching of the Redux
137
+     * action SET_ROOM.
138
+     *
139
+     * @override
140
+     * @protected
141
+     * @returns {null}
142
+     */
143
+    _onJoin() {
144
+        // Don't call the super implementation and thus prevent the dispatching
145
+        // of the Redux action SET_ROOM.
146
+    }
147
+
148
+    /**
149
+     * Handles 'keydown' event to initiate joining the room when the
150
+     * 'Enter/Return' button is pressed.
151
+     *
152
+     * @param {Event} event - Key down event object.
153
+     * @private
154
+     * @returns {void}
155
+     */
156
+    _onKeyDown(event) {
157
+        if (event.keyCode === /* Enter */ 13) {
158
+            this._onJoin();
159
+        }
160
+    }
161
+
162
+    /**
163
+     * Overrides the super to account for the differences in the argument types
164
+     * provided by HTML and React Native text inputs.
165
+     *
166
+     * @inheritdoc
167
+     * @override
168
+     * @param {Event} event - The (HTML) Event which details the change such as
169
+     * the EventTarget.
170
+     * @protected
171
+     */
172
+    _onRoomChange(event) {
173
+        super._onRoomChange(event.target.value);
174
+    }
175
+
176
+    /**
177
+     * Method that returns brand watermark element if it is enabled.
178
+     *
179
+     * @private
180
+     * @returns {ReactElement|null} Watermark element or null.
181
+     */
182
+    _renderBrandWatermark() {
183
+        if (this.state.showBrandWatermark) {
184
+            return (
185
+                <a
186
+                    href = { this.state.brandWatermarkLink }
187
+                    target = '_new'>
188
+                    <div
189
+                        className = 'watermark rightwatermark'
190
+                        style = { RIGHT_WATERMARK_STYLE } />
191
+                </a>
192
+            );
193
+        }
194
+
195
+        return null;
148 196
     }
149 197
 
150 198
     /**
@@ -196,6 +244,8 @@ class WelcomePage extends AbstractWelcomePage {
196 244
         );
197 245
     }
198 246
 
247
+/* eslint-disable require-jsdoc */
248
+
199 249
     /**
200 250
      * Renders the header part of this WelcomePage.
201 251
      *
@@ -203,32 +253,46 @@ class WelcomePage extends AbstractWelcomePage {
203 253
      * @returns {ReactElement|null}
204 254
      */
205 255
     _renderHeader() {
256
+
257
+/* eslint-enable require-jsdoc */
258
+
206 259
         return (
207 260
             <div id = 'welcome_page_header'>
208
-                { this._renderJitsiWatermark() }
209
-                { this._renderBrandWatermark() }
210
-                { this._renderPoweredBy() }
261
+                {
262
+                    this._renderJitsiWatermark()
263
+                }
264
+                {
265
+                    this._renderBrandWatermark()
266
+                }
267
+                {
268
+                    this._renderPoweredBy()
269
+                }
211 270
                 <div id = 'enter_room_container'>
212 271
                     <div id = 'enter_room_form'>
213
-                        <div className = 'domain-name' >
214
-                            { this._getDomain() }
272
+                        <div className = 'domain-name'>
273
+                            {
274
+                                this._getDomain()
275
+                            }
215 276
                         </div>
216 277
                         <div id = 'enter_room'>
217 278
                             <input
218 279
                                 autoFocus = { true }
219 280
                                 className = 'enter-room__field'
220
-                                data-room-name =
221
-                                    { this.state.generatedRoomname }
281
+                                data-room-name
282
+                                    = { this.state.generatedRoomname }
222 283
                                 id = 'enter_room_field'
223 284
                                 onChange = { this._onRoomChange }
224 285
                                 onKeyDown = { this._onKeyDown }
225 286
                                 placeholder = { this.state.roomPlaceholder }
226
-                                ref = { this._setInput }
227 287
                                 type = 'text'
228 288
                                 value = { this.state.room } />
289
+
290
+                            { /* eslint-disable react/jsx-handler-names */ }
229 291
                             <div
230 292
                                 className = 'icon-reload enter-room__reload'
231
-                                onClick = { this._onUpdateRoomname } />
293
+                                onClick = { this._updateRoomname } />
294
+                            { /* eslint-enable react/jsx-handler-names */ }
295
+
232 296
                             <button
233 297
                                 className = 'enter-room__button'
234 298
                                 data-i18n = 'welcomepage.go'
@@ -243,7 +307,7 @@ class WelcomePage extends AbstractWelcomePage {
243 307
                     checked = { !this.state.enableWelcomePage }
244 308
                     id = 'disable_welcome'
245 309
                     name = 'checkbox'
246
-                    onChange = { this._onToggleDisableWelcomePage }
310
+                    onChange = { this._onDisableWelcomeChange }
247 311
                     type = 'checkbox' />
248 312
                 <label
249 313
                     className = 'disable_welcome_position'
@@ -255,31 +319,11 @@ class WelcomePage extends AbstractWelcomePage {
255 319
     }
256 320
 
257 321
     /**
258
-    * Method that returns brand watermark element if it is enabled.
259
-    *
260
-    * @returns {ReactElement|null} Watermark element or null.
261
-    **/
262
-    _renderBrandWatermark() {
263
-        if (this.state.showBrandWatermark) {
264
-            return (
265
-                <a
266
-                    href = { this.state.brandWatermarkLink }
267
-                    target = '_new'>
268
-                    <div
269
-                        className = 'watermark rightwatermark'
270
-                        style = { RIGHT_WATERMARK_STYLES } />
271
-                </a>
272
-            );
273
-        }
274
-
275
-        return null;
276
-    }
277
-
278
-    /**
279
-    * Method that returns jitsi watermark element if it is enabled.
280
-    *
281
-    * @returns {ReactElement|null} Watermark element or null.
282
-    **/
322
+     * Method that returns jitsi watermark element if it is enabled.
323
+     *
324
+     * @private
325
+     * @returns {ReactElement|null} Watermark element or null.
326
+     */
283 327
     _renderJitsiWatermark() {
284 328
         if (this.state.showJitsiWatermark) {
285 329
             return (
@@ -295,11 +339,11 @@ class WelcomePage extends AbstractWelcomePage {
295 339
     }
296 340
 
297 341
     /**
298
-    * Renders powered by block if it is enabled
299
-    *
300
-    * @returns {void}
301
-    * @private
302
-    **/
342
+     * Renders powered by block if it is enabled.
343
+     *
344
+     * @private
345
+     * @returns {ReactElement|null}
346
+     */
303 347
     _renderPoweredBy() {
304 348
         if (this.state.showPoweredBy) {
305 349
             return (
@@ -315,54 +359,6 @@ class WelcomePage extends AbstractWelcomePage {
315 359
         return null;
316 360
     }
317 361
 
318
-    /**
319
-    * Handles updating roomname.
320
-    *
321
-    * @private
322
-    * @returns {void}
323
-    **/
324
-    _onUpdateRoomname() {
325
-        this._updateRoomname();
326
-    }
327
-
328
-    /**
329
-    * Event handler for changing room name input from web.
330
-    *
331
-    * @inheritdoc
332
-    * @override
333
-    * @protected
334
-    */
335
-    _onRoomChange() {
336
-        super._onRoomChange(this.roomNameInput.value);
337
-    }
338
-
339
-    /**
340
-    * Handles 'keydown' event and initiate joining the room if 'return' button
341
-    * was pressed.
342
-    *
343
-    * @param {Event} event - Key down event object.
344
-    * @returns {void}
345
-    * @private
346
-    */
347
-    _onKeyDown(event) {
348
-        const RETURN_BUTTON_CODE = 13;
349
-
350
-        if (event.keyCode === RETURN_BUTTON_CODE) {
351
-            this._onJoin();
352
-        }
353
-    }
354
-
355
-    /**
356
-    * We override this method for web app for not dispatching 'set room' action.
357
-    *
358
-    * @returns {null}
359
-    * @override
360
-    * @protected
361
-    **/
362
-    _onJoin() {
363
-        return null;
364
-    }
365
-
366 362
     /**
367 363
      * Renders the main part of this WelcomePage.
368 364
      *

Loading…
Откажи
Сачувај