瀏覽代碼

Coding style: formatting, typos

master
Lyubo Marinov 7 年之前
父節點
當前提交
13e0e18f37

+ 60
- 59
react/features/base/react/components/native/NavigateSectionList.js 查看文件

@@ -1,4 +1,5 @@
1 1
 // @flow
2
+
2 3
 import React, { Component } from 'react';
3 4
 import {
4 5
     SafeAreaView,
@@ -8,11 +9,10 @@ import {
8 9
     View
9 10
 } from 'react-native';
10 11
 
11
-import styles, { UNDERLAY_COLOR } from './styles';
12
-
12
+import { Icon } from '../../../font-icons';
13 13
 import { translate } from '../../../i18n';
14 14
 
15
-import { Icon } from '../../../font-icons';
15
+import styles, { UNDERLAY_COLOR } from './styles';
16 16
 
17 17
 type Props = {
18 18
 
@@ -60,14 +60,30 @@ type Props = {
60 60
      * ]
61 61
      */
62 62
     sections: Array<Object>
63
-}
63
+};
64 64
 
65 65
 /**
66
- * Implements a general section list to display items that have a URL
67
- * property and navigates to (probably) meetings, such as the recent list
68
- * or the meeting list components.
66
+ * Implements a general section list to display items that have a URL property
67
+ * and navigates to (probably) meetings, such as the recent list or the meeting
68
+ * list components.
69 69
  */
70 70
 class NavigateSectionList extends Component<Props> {
71
+    /**
72
+     * Creates an empty section object.
73
+     *
74
+     * @param {string} title - The title of the section.
75
+     * @param {string} key - The key of the section. It must be unique.
76
+     * @private
77
+     * @returns {Object}
78
+     */
79
+    static createSection(title, key) {
80
+        return {
81
+            data: [],
82
+            key,
83
+            title
84
+        };
85
+    }
86
+
71 87
     /**
72 88
      * Constructor of the NavigateSectionList component.
73 89
      *
@@ -89,23 +105,23 @@ class NavigateSectionList extends Component<Props> {
89 105
     }
90 106
 
91 107
     /**
92
-     * Implements React's Component.render function.
108
+     * Implements React's Component.render.
93 109
      * Note: we don't use the refreshing value yet, because refreshing of these
94 110
      * lists is super quick, no need to complicate the code - yet.
95 111
      *
96 112
      * @inheritdoc
97 113
      */
98 114
     render() {
99
-        const { renderListEmptyComponent, sections } = this.props;
115
+        const {
116
+            renderListEmptyComponent = this._renderListEmptyComponent,
117
+            sections
118
+        } = this.props;
100 119
 
101 120
         return (
102 121
             <SafeAreaView
103 122
                 style = { styles.container } >
104 123
                 <SectionList
105
-                    ListEmptyComponent = {
106
-                        renderListEmptyComponent
107
-                        || this._renderListEmptyComponent
108
-                    }
124
+                    ListEmptyComponent = { renderListEmptyComponent }
109 125
                     keyExtractor = { this._getItemKey }
110 126
                     onRefresh = { this._onRefresh }
111 127
                     refreshing = { false }
@@ -117,27 +133,11 @@ class NavigateSectionList extends Component<Props> {
117 133
         );
118 134
     }
119 135
 
120
-    /**
121
-     * Creates an empty section object.
122
-     *
123
-     * @private
124
-     * @param {string} title - The title of the section.
125
-     * @param {string} key - The key of the section. It must be unique.
126
-     * @returns {Object}
127
-     */
128
-    static createSection(title, key) {
129
-        return {
130
-            data: [],
131
-            key,
132
-            title
133
-        };
134
-    }
135
-
136
-    _getAvatarColor: string => Object
136
+    _getAvatarColor: string => Object;
137 137
 
138 138
     /**
139
-     * Returns a style (color) based on the string that determines the
140
-     * color of the avatar.
139
+     * Returns a style (color) based on the string that determines the color of
140
+     * the avatar.
141 141
      *
142 142
      * @param {string} colorBase - The string that is the base of the color.
143 143
      * @private
@@ -162,22 +162,22 @@ class NavigateSectionList extends Component<Props> {
162 162
     /**
163 163
      * Generates a unique id to every item.
164 164
      *
165
-     * @private
166 165
      * @param {Object} item - The item.
167 166
      * @param {number} index - The item index.
167
+     * @private
168 168
      * @returns {string}
169 169
      */
170 170
     _getItemKey(item, index) {
171 171
         return `${index}-${item.key}`;
172 172
     }
173 173
 
174
-    _onPress: string => Function
174
+    _onPress: string => Function;
175 175
 
176 176
     /**
177 177
      * Returns a function that is used in the onPress callback of the items.
178 178
      *
179
-     * @private
180 179
      * @param {string} url - The URL of the item to navigate to.
180
+     * @private
181 181
      * @returns {Function}
182 182
      */
183 183
     _onPress(url) {
@@ -188,7 +188,7 @@ class NavigateSectionList extends Component<Props> {
188 188
         };
189 189
     }
190 190
 
191
-    _onRefresh: () => void
191
+    _onRefresh: () => void;
192 192
 
193 193
     /**
194 194
      * Invokes the onRefresh callback if present.
@@ -209,26 +209,35 @@ class NavigateSectionList extends Component<Props> {
209 209
     /**
210 210
      * Renders a single item in the list.
211 211
      *
212
-     * @private
213 212
      * @param {Object} listItem - The item to render.
213
+     * @private
214 214
      * @returns {Component}
215 215
      */
216 216
     _renderItem(listItem) {
217
-        const { item } = listItem;
217
+        const { item: { colorBase, lines, title, url } } = listItem;
218
+
219
+        // XXX The value of title cannot be undefined; otherwise, react-native
220
+        // will throw a TypeError: Cannot read property of undefined. While it's
221
+        // difficult to get an undefined title and very likely requires the
222
+        // execution of incorrect source code, it is undesirable to break the
223
+        // whole app because of an undefined string.
224
+        if (typeof title === 'undefined') {
225
+            return null;
226
+        }
218 227
 
219 228
         return (
220 229
             <TouchableHighlight
221
-                onPress = { this._onPress(item.url) }
230
+                onPress = { this._onPress(url) }
222 231
                 underlayColor = { UNDERLAY_COLOR }>
223 232
                 <View style = { styles.listItem }>
224 233
                     <View style = { styles.avatarContainer } >
225 234
                         <View
226 235
                             style = { [
227 236
                                 styles.avatar,
228
-                                this._getAvatarColor(item.colorBase)
237
+                                this._getAvatarColor(colorBase)
229 238
                             ] } >
230 239
                             <Text style = { styles.avatarContent }>
231
-                                { item.title.substr(0, 1).toUpperCase() }
240
+                                { title.substr(0, 1).toUpperCase() }
232 241
                             </Text>
233 242
                         </View>
234 243
                     </View>
@@ -239,11 +248,9 @@ class NavigateSectionList extends Component<Props> {
239 248
                                 styles.listItemText,
240 249
                                 styles.listItemTitle
241 250
                             ] }>
242
-                            { item.title }
251
+                            { title }
243 252
                         </Text>
244
-                        {
245
-                            this._renderItemLines(item.lines)
246
-                        }
253
+                        { this._renderItemLines(lines) }
247 254
                     </View>
248 255
                 </View>
249 256
             </TouchableHighlight>
@@ -255,9 +262,9 @@ class NavigateSectionList extends Component<Props> {
255 262
     /**
256 263
      * Renders a single line from the additional lines.
257 264
      *
258
-     * @private
259 265
      * @param {string} line - The line text.
260 266
      * @param {number} index - The index of the line.
267
+     * @private
261 268
      * @returns {React$Node}
262 269
      */
263 270
     _renderItemLine(line, index) {
@@ -275,32 +282,26 @@ class NavigateSectionList extends Component<Props> {
275 282
         );
276 283
     }
277 284
 
278
-    _renderItemLines: (Array<string>) => Array<React$Node>;
285
+    _renderItemLines: Array<string> => Array<React$Node>;
279 286
 
280 287
     /**
281 288
      * Renders the additional item lines, if any.
282 289
      *
283
-     * @private
284 290
      * @param {Array<string>} lines - The lines to render.
291
+     * @private
285 292
      * @returns {Array<React$Node>}
286 293
      */
287 294
     _renderItemLines(lines) {
288
-        if (lines && lines.length) {
289
-            return lines.map((line, index) =>
290
-                this._renderItemLine(line, index)
291
-            );
292
-        }
293
-
294
-        return null;
295
+        return lines && lines.length ? lines.map(this._renderItemLine) : null;
295 296
     }
296 297
 
297
-    _renderListEmptyComponent: () => Object
298
+    _renderListEmptyComponent: () => Object;
298 299
 
299 300
     /**
300 301
      * Renders a component to display when the list is empty.
301 302
      *
302
-     * @private
303 303
      * @param {Object} section - The section being rendered.
304
+     * @private
304 305
      * @returns {React$Node}
305 306
      */
306 307
     _renderListEmptyComponent() {
@@ -322,13 +323,13 @@ class NavigateSectionList extends Component<Props> {
322 323
         return null;
323 324
     }
324 325
 
325
-    _renderSection: Object => Object
326
+    _renderSection: Object => Object;
326 327
 
327 328
     /**
328 329
      * Renders a section title.
329 330
      *
330
-     * @private
331 331
      * @param {Object} section - The section being rendered.
332
+     * @private
332 333
      * @returns {React$Node}
333 334
      */
334 335
     _renderSection(section) {

+ 13
- 21
react/features/calendar-sync/components/MeetingList.native.js 查看文件

@@ -83,7 +83,7 @@ class MeetingList extends Component<Props> {
83 83
     }
84 84
 
85 85
     /**
86
-     * Implements React Component's componentWillReceiveProps function.
86
+     * Implements React Component's componentWillReceiveProps.
87 87
      *
88 88
      * @inheritdoc
89 89
      */
@@ -98,7 +98,7 @@ class MeetingList extends Component<Props> {
98 98
     }
99 99
 
100 100
     /**
101
-     * Implements the React Components's render method.
101
+     * Implements the React Components's render.
102 102
      *
103 103
      * @inheritdoc
104 104
      */
@@ -115,7 +115,7 @@ class MeetingList extends Component<Props> {
115 115
         );
116 116
     }
117 117
 
118
-    _getRenderListEmptyComponent: () => Object
118
+    _getRenderListEmptyComponent: () => Object;
119 119
 
120 120
     /**
121 121
      * Returns a list empty component if a custom one has to be rendered instead
@@ -147,7 +147,7 @@ class MeetingList extends Component<Props> {
147 147
         return null;
148 148
     }
149 149
 
150
-    _onPress: string => Function
150
+    _onPress: string => Function;
151 151
 
152 152
     /**
153 153
      * Handles the list's navigate action.
@@ -160,7 +160,7 @@ class MeetingList extends Component<Props> {
160 160
         this.props.dispatch(appNavigate(url));
161 161
     }
162 162
 
163
-    _onRefresh: () => void
163
+    _onRefresh: () => void;
164 164
 
165 165
     /**
166 166
      * Callback to execute when the list is doing a pull-to-refresh.
@@ -172,7 +172,7 @@ class MeetingList extends Component<Props> {
172 172
         this.props.dispatch(refreshCalendar(true));
173 173
     }
174 174
 
175
-    _toDisplayableItem: Object => Object
175
+    _toDisplayableItem: Object => Object;
176 176
 
177 177
     /**
178 178
      * Creates a displayable object from an event.
@@ -193,7 +193,7 @@ class MeetingList extends Component<Props> {
193 193
         };
194 194
     }
195 195
 
196
-    _toDisplayableList: () => Array<Object>
196
+    _toDisplayableList: () => Array<Object>;
197 197
 
198 198
     /**
199 199
      * Transforms the event list to a displayable list with sections.
@@ -204,18 +204,10 @@ class MeetingList extends Component<Props> {
204 204
     _toDisplayableList() {
205 205
         const { _eventList, t } = this.props;
206 206
         const now = Date.now();
207
-        const nowSection = NavigateSectionList.createSection(
208
-            t('calendarSync.now'),
209
-            'now'
210
-        );
211
-        const nextSection = NavigateSectionList.createSection(
212
-            t('calendarSync.next'),
213
-            'next'
214
-        );
215
-        const laterSection = NavigateSectionList.createSection(
216
-            t('calendarSync.later'),
217
-            'later'
218
-        );
207
+        const { createSection } = NavigateSectionList;
208
+        const nowSection = createSection(t('calendarSync.now'), 'now');
209
+        const nextSection = createSection(t('calendarSync.next'), 'next');
210
+        const laterSection = createSection(t('calendarSync.later'), 'later');
219 211
 
220 212
         for (const event of _eventList) {
221 213
             const displayableEvent = this._toDisplayableItem(event);
@@ -224,7 +216,7 @@ class MeetingList extends Component<Props> {
224 216
                 nowSection.data.push(displayableEvent);
225 217
             } else if (event.startDate > now) {
226 218
                 if (nextSection.data.length
227
-                && nextSection.data[0].startDate !== event.startDate) {
219
+                        && nextSection.data[0].startDate !== event.startDate) {
228 220
                     laterSection.data.push(displayableEvent);
229 221
                 } else {
230 222
                     nextSection.data.push(displayableEvent);
@@ -247,7 +239,7 @@ class MeetingList extends Component<Props> {
247 239
         return sectionList;
248 240
     }
249 241
 
250
-    _toDateString: Object => string
242
+    _toDateString: Object => string;
251 243
 
252 244
     /**
253 245
      * Generates a date (interval) string for a given event.

+ 3
- 4
react/features/calendar-sync/middleware.js 查看文件

@@ -102,9 +102,8 @@ function _ensureCalendarAccess(promptForPermission, dispatch) {
102 102
  * @returns {Promise}
103 103
  */
104 104
 function _ensureDefaultServer({ dispatch, getState }) {
105
-    const state = getState();
106 105
     const defaultURL
107
-        = parseURIString(state['features/app'].app._getDefaultURL());
106
+        = parseURIString(getState()['features/app'].app._getDefaultURL());
108 107
 
109 108
     dispatch(addKnownDomain(defaultURL.host));
110 109
 }
@@ -164,7 +163,7 @@ function _fetchCalendarEntries(
164 163
 }
165 164
 
166 165
 /**
167
- * Retreives a jitsi URL from an event if present.
166
+ * Retrieves a Jitsi Meet URL from an event if present.
168 167
  *
169 168
  * @param {Object} event - The event to parse.
170 169
  * @param {Array<string>} knownDomains - The known domain names.
@@ -219,7 +218,7 @@ export function _isCalendarEnabled() {
219 218
 }
220 219
 
221 220
 /**
222
- * Retreives the domain name of a room upon join and stores it in the known
221
+ * Retrieves the domain name of a room upon join and stores it in the known
223 222
  * domain list, if not present yet.
224 223
  *
225 224
  * @param {Object} store - The redux store.

+ 13
- 19
react/features/recent-list/components/RecentList.native.js 查看文件

@@ -78,7 +78,7 @@ class RecentList extends Component<Props> {
78 78
         );
79 79
     }
80 80
 
81
-    _onPress: string => Function
81
+    _onPress: string => Function;
82 82
 
83 83
     /**
84 84
      * Handles the list's navigate action.
@@ -93,7 +93,7 @@ class RecentList extends Component<Props> {
93 93
         dispatch(appNavigate(url));
94 94
     }
95 95
 
96
-    _toDisplayableItem: Object => Object
96
+    _toDisplayableItem: Object => Object;
97 97
 
98 98
     /**
99 99
      * Creates a displayable list item of a recent list entry.
@@ -121,7 +121,7 @@ class RecentList extends Component<Props> {
121 121
         };
122 122
     }
123 123
 
124
-    _toDisplayableList: () => Array<Object>
124
+    _toDisplayableList: () => Array<Object>;
125 125
 
126 126
     /**
127 127
      * Transforms the history list to a displayable list
@@ -132,18 +132,12 @@ class RecentList extends Component<Props> {
132 132
      */
133 133
     _toDisplayableList() {
134 134
         const { _recentList, t } = this.props;
135
-        const todaySection = NavigateSectionList.createSection(
136
-            t('recentList.today'),
137
-            'today'
138
-        );
139
-        const yesterdaySection = NavigateSectionList.createSection(
140
-            t('recentList.yesterday'),
141
-            'yesterday'
142
-        );
143
-        const earlierSection = NavigateSectionList.createSection(
144
-            t('recentList.earlier'),
145
-            'earlier'
146
-        );
135
+        const { createSection } = NavigateSectionList;
136
+        const todaySection = createSection(t('recentList.today'), 'today');
137
+        const yesterdaySection
138
+            = createSection(t('recentList.yesterday'), 'yesterday');
139
+        const earlierSection
140
+            = createSection(t('recentList.earlier'), 'earlier');
147 141
         const today = new Date().toDateString();
148 142
         const yesterdayDate = new Date();
149 143
 
@@ -182,7 +176,7 @@ class RecentList extends Component<Props> {
182 176
         return displayableList;
183 177
     }
184 178
 
185
-    _toDateString: number => string
179
+    _toDateString: number => string;
186 180
 
187 181
     /**
188 182
      * Generates a date string for the item.
@@ -203,7 +197,7 @@ class RecentList extends Component<Props> {
203 197
         return m.format('lll');
204 198
     }
205 199
 
206
-    _toDurationString: number => string
200
+    _toDurationString: number => string;
207 201
 
208 202
     /**
209 203
      * Generates a duration string for the item.
@@ -226,8 +220,8 @@ class RecentList extends Component<Props> {
226 220
  *
227 221
  * @param {Object} state - The redux state.
228 222
  * @returns {{
229
- *      _defaultServerURL: string,
230
- *      _recentList: Array
223
+ *     _defaultServerURL: string,
224
+ *     _recentList: Array
231 225
  * }}
232 226
  */
233 227
 export function _mapStateToProps(state: Object) {

Loading…
取消
儲存