From 13e0e18f372575125f09c55003acc94609ca91b4 Mon Sep 17 00:00:00 2001 From: Lyubo Marinov Date: Mon, 16 Apr 2018 18:07:25 -0500 Subject: [PATCH] Coding style: formatting, typos --- .../components/native/NavigateSectionList.js | 119 +++++++++--------- .../components/MeetingList.native.js | 34 ++--- react/features/calendar-sync/middleware.js | 7 +- .../components/RecentList.native.js | 32 ++--- 4 files changed, 89 insertions(+), 103 deletions(-) diff --git a/react/features/base/react/components/native/NavigateSectionList.js b/react/features/base/react/components/native/NavigateSectionList.js index d0449e8d7..96a5967ff 100644 --- a/react/features/base/react/components/native/NavigateSectionList.js +++ b/react/features/base/react/components/native/NavigateSectionList.js @@ -1,4 +1,5 @@ // @flow + import React, { Component } from 'react'; import { SafeAreaView, @@ -8,11 +9,10 @@ import { View } from 'react-native'; -import styles, { UNDERLAY_COLOR } from './styles'; - +import { Icon } from '../../../font-icons'; import { translate } from '../../../i18n'; -import { Icon } from '../../../font-icons'; +import styles, { UNDERLAY_COLOR } from './styles'; type Props = { @@ -60,14 +60,30 @@ type Props = { * ] */ sections: Array -} +}; /** - * Implements a general section list to display items that have a URL - * property and navigates to (probably) meetings, such as the recent list - * or the meeting list components. + * Implements a general section list to display items that have a URL property + * and navigates to (probably) meetings, such as the recent list or the meeting + * list components. */ class NavigateSectionList extends Component { + /** + * Creates an empty section object. + * + * @param {string} title - The title of the section. + * @param {string} key - The key of the section. It must be unique. + * @private + * @returns {Object} + */ + static createSection(title, key) { + return { + data: [], + key, + title + }; + } + /** * Constructor of the NavigateSectionList component. * @@ -89,23 +105,23 @@ class NavigateSectionList extends Component { } /** - * Implements React's Component.render function. + * Implements React's Component.render. * Note: we don't use the refreshing value yet, because refreshing of these * lists is super quick, no need to complicate the code - yet. * * @inheritdoc */ render() { - const { renderListEmptyComponent, sections } = this.props; + const { + renderListEmptyComponent = this._renderListEmptyComponent, + sections + } = this.props; return ( { ); } - /** - * Creates an empty section object. - * - * @private - * @param {string} title - The title of the section. - * @param {string} key - The key of the section. It must be unique. - * @returns {Object} - */ - static createSection(title, key) { - return { - data: [], - key, - title - }; - } - - _getAvatarColor: string => Object + _getAvatarColor: string => Object; /** - * Returns a style (color) based on the string that determines the - * color of the avatar. + * Returns a style (color) based on the string that determines the color of + * the avatar. * * @param {string} colorBase - The string that is the base of the color. * @private @@ -162,22 +162,22 @@ class NavigateSectionList extends Component { /** * Generates a unique id to every item. * - * @private * @param {Object} item - The item. * @param {number} index - The item index. + * @private * @returns {string} */ _getItemKey(item, index) { return `${index}-${item.key}`; } - _onPress: string => Function + _onPress: string => Function; /** * Returns a function that is used in the onPress callback of the items. * - * @private * @param {string} url - The URL of the item to navigate to. + * @private * @returns {Function} */ _onPress(url) { @@ -188,7 +188,7 @@ class NavigateSectionList extends Component { }; } - _onRefresh: () => void + _onRefresh: () => void; /** * Invokes the onRefresh callback if present. @@ -209,26 +209,35 @@ class NavigateSectionList extends Component { /** * Renders a single item in the list. * - * @private * @param {Object} listItem - The item to render. + * @private * @returns {Component} */ _renderItem(listItem) { - const { item } = listItem; + const { item: { colorBase, lines, title, url } } = listItem; + + // XXX The value of title cannot be undefined; otherwise, react-native + // will throw a TypeError: Cannot read property of undefined. While it's + // difficult to get an undefined title and very likely requires the + // execution of incorrect source code, it is undesirable to break the + // whole app because of an undefined string. + if (typeof title === 'undefined') { + return null; + } return ( - { item.title.substr(0, 1).toUpperCase() } + { title.substr(0, 1).toUpperCase() } @@ -239,11 +248,9 @@ class NavigateSectionList extends Component { styles.listItemText, styles.listItemTitle ] }> - { item.title } + { title } - { - this._renderItemLines(item.lines) - } + { this._renderItemLines(lines) } @@ -255,9 +262,9 @@ class NavigateSectionList extends Component { /** * Renders a single line from the additional lines. * - * @private * @param {string} line - The line text. * @param {number} index - The index of the line. + * @private * @returns {React$Node} */ _renderItemLine(line, index) { @@ -275,32 +282,26 @@ class NavigateSectionList extends Component { ); } - _renderItemLines: (Array) => Array; + _renderItemLines: Array => Array; /** * Renders the additional item lines, if any. * - * @private * @param {Array} lines - The lines to render. + * @private * @returns {Array} */ _renderItemLines(lines) { - if (lines && lines.length) { - return lines.map((line, index) => - this._renderItemLine(line, index) - ); - } - - return null; + return lines && lines.length ? lines.map(this._renderItemLine) : null; } - _renderListEmptyComponent: () => Object + _renderListEmptyComponent: () => Object; /** * Renders a component to display when the list is empty. * - * @private * @param {Object} section - The section being rendered. + * @private * @returns {React$Node} */ _renderListEmptyComponent() { @@ -322,13 +323,13 @@ class NavigateSectionList extends Component { return null; } - _renderSection: Object => Object + _renderSection: Object => Object; /** * Renders a section title. * - * @private * @param {Object} section - The section being rendered. + * @private * @returns {React$Node} */ _renderSection(section) { diff --git a/react/features/calendar-sync/components/MeetingList.native.js b/react/features/calendar-sync/components/MeetingList.native.js index 6f3a1acce..dfa5fcbf7 100644 --- a/react/features/calendar-sync/components/MeetingList.native.js +++ b/react/features/calendar-sync/components/MeetingList.native.js @@ -83,7 +83,7 @@ class MeetingList extends Component { } /** - * Implements React Component's componentWillReceiveProps function. + * Implements React Component's componentWillReceiveProps. * * @inheritdoc */ @@ -98,7 +98,7 @@ class MeetingList extends Component { } /** - * Implements the React Components's render method. + * Implements the React Components's render. * * @inheritdoc */ @@ -115,7 +115,7 @@ class MeetingList extends Component { ); } - _getRenderListEmptyComponent: () => Object + _getRenderListEmptyComponent: () => Object; /** * Returns a list empty component if a custom one has to be rendered instead @@ -147,7 +147,7 @@ class MeetingList extends Component { return null; } - _onPress: string => Function + _onPress: string => Function; /** * Handles the list's navigate action. @@ -160,7 +160,7 @@ class MeetingList extends Component { this.props.dispatch(appNavigate(url)); } - _onRefresh: () => void + _onRefresh: () => void; /** * Callback to execute when the list is doing a pull-to-refresh. @@ -172,7 +172,7 @@ class MeetingList extends Component { this.props.dispatch(refreshCalendar(true)); } - _toDisplayableItem: Object => Object + _toDisplayableItem: Object => Object; /** * Creates a displayable object from an event. @@ -193,7 +193,7 @@ class MeetingList extends Component { }; } - _toDisplayableList: () => Array + _toDisplayableList: () => Array; /** * Transforms the event list to a displayable list with sections. @@ -204,18 +204,10 @@ class MeetingList extends Component { _toDisplayableList() { const { _eventList, t } = this.props; const now = Date.now(); - const nowSection = NavigateSectionList.createSection( - t('calendarSync.now'), - 'now' - ); - const nextSection = NavigateSectionList.createSection( - t('calendarSync.next'), - 'next' - ); - const laterSection = NavigateSectionList.createSection( - t('calendarSync.later'), - 'later' - ); + const { createSection } = NavigateSectionList; + const nowSection = createSection(t('calendarSync.now'), 'now'); + const nextSection = createSection(t('calendarSync.next'), 'next'); + const laterSection = createSection(t('calendarSync.later'), 'later'); for (const event of _eventList) { const displayableEvent = this._toDisplayableItem(event); @@ -224,7 +216,7 @@ class MeetingList extends Component { nowSection.data.push(displayableEvent); } else if (event.startDate > now) { if (nextSection.data.length - && nextSection.data[0].startDate !== event.startDate) { + && nextSection.data[0].startDate !== event.startDate) { laterSection.data.push(displayableEvent); } else { nextSection.data.push(displayableEvent); @@ -247,7 +239,7 @@ class MeetingList extends Component { return sectionList; } - _toDateString: Object => string + _toDateString: Object => string; /** * Generates a date (interval) string for a given event. diff --git a/react/features/calendar-sync/middleware.js b/react/features/calendar-sync/middleware.js index ceecaffdf..7fb23ee18 100644 --- a/react/features/calendar-sync/middleware.js +++ b/react/features/calendar-sync/middleware.js @@ -102,9 +102,8 @@ function _ensureCalendarAccess(promptForPermission, dispatch) { * @returns {Promise} */ function _ensureDefaultServer({ dispatch, getState }) { - const state = getState(); const defaultURL - = parseURIString(state['features/app'].app._getDefaultURL()); + = parseURIString(getState()['features/app'].app._getDefaultURL()); dispatch(addKnownDomain(defaultURL.host)); } @@ -164,7 +163,7 @@ function _fetchCalendarEntries( } /** - * Retreives a jitsi URL from an event if present. + * Retrieves a Jitsi Meet URL from an event if present. * * @param {Object} event - The event to parse. * @param {Array} knownDomains - The known domain names. @@ -219,7 +218,7 @@ export function _isCalendarEnabled() { } /** - * Retreives the domain name of a room upon join and stores it in the known + * Retrieves the domain name of a room upon join and stores it in the known * domain list, if not present yet. * * @param {Object} store - The redux store. diff --git a/react/features/recent-list/components/RecentList.native.js b/react/features/recent-list/components/RecentList.native.js index 57a62f5f3..5cc4cb130 100644 --- a/react/features/recent-list/components/RecentList.native.js +++ b/react/features/recent-list/components/RecentList.native.js @@ -78,7 +78,7 @@ class RecentList extends Component { ); } - _onPress: string => Function + _onPress: string => Function; /** * Handles the list's navigate action. @@ -93,7 +93,7 @@ class RecentList extends Component { dispatch(appNavigate(url)); } - _toDisplayableItem: Object => Object + _toDisplayableItem: Object => Object; /** * Creates a displayable list item of a recent list entry. @@ -121,7 +121,7 @@ class RecentList extends Component { }; } - _toDisplayableList: () => Array + _toDisplayableList: () => Array; /** * Transforms the history list to a displayable list @@ -132,18 +132,12 @@ class RecentList extends Component { */ _toDisplayableList() { const { _recentList, t } = this.props; - const todaySection = NavigateSectionList.createSection( - t('recentList.today'), - 'today' - ); - const yesterdaySection = NavigateSectionList.createSection( - t('recentList.yesterday'), - 'yesterday' - ); - const earlierSection = NavigateSectionList.createSection( - t('recentList.earlier'), - 'earlier' - ); + const { createSection } = NavigateSectionList; + const todaySection = createSection(t('recentList.today'), 'today'); + const yesterdaySection + = createSection(t('recentList.yesterday'), 'yesterday'); + const earlierSection + = createSection(t('recentList.earlier'), 'earlier'); const today = new Date().toDateString(); const yesterdayDate = new Date(); @@ -182,7 +176,7 @@ class RecentList extends Component { return displayableList; } - _toDateString: number => string + _toDateString: number => string; /** * Generates a date string for the item. @@ -203,7 +197,7 @@ class RecentList extends Component { return m.format('lll'); } - _toDurationString: number => string + _toDurationString: number => string; /** * Generates a duration string for the item. @@ -226,8 +220,8 @@ class RecentList extends Component { * * @param {Object} state - The redux state. * @returns {{ - * _defaultServerURL: string, - * _recentList: Array + * _defaultServerURL: string, + * _recentList: Array * }} */ export function _mapStateToProps(state: Object) {