From dcee9d994345b351cf48262e43475cd657f93014 Mon Sep 17 00:00:00 2001 From: Wilson Page Date: Tue, 15 Nov 2016 17:09:31 +0000 Subject: [PATCH] Add missing file for network checks --- lib/utils/index.js | 6 +++ lib/views/item/container.js | 101 ------------------------------------ 2 files changed, 6 insertions(+), 101 deletions(-) create mode 100644 lib/utils/index.js delete mode 100644 lib/views/item/container.js diff --git a/lib/utils/index.js b/lib/utils/index.js new file mode 100644 index 00000000..48ebf4ba --- /dev/null +++ b/lib/utils/index.js @@ -0,0 +1,6 @@ + +export function isNetworkError(err) { + return err.name === 'NetworkError' + || err.message === 'Network request failed' + || err.code.indexOf('NoConnectionError') > -1; +} diff --git a/lib/views/item/container.js b/lib/views/item/container.js deleted file mode 100644 index 598a03c4..00000000 --- a/lib/views/item/container.js +++ /dev/null @@ -1,101 +0,0 @@ -'use strict'; - -/** - * Dependencies - */ - -const debug = require('../../debug')('ItemContainer'); -const actions = require('../../store/actions'); -const getItem = require('../../api/getItem'); -const ReactNative = require('react-native'); -const { connect } = require('react-redux'); -const React = require('react'); -const Item = require('./item'); - -const { - View, - StyleSheet, -} = ReactNative; - -class ItemContainer extends React.Component { - constructor(props) { - super(props); - debug('created'); - } - - componentDidMount() { - if (!this.props.item) return; - - this.fetchData(this.props.itemUrl) - .then(item => { - this.props.setOpenItem(item); - }) - - .catch(e => { - console.log('ERROR', e); - }); - } - - render() { - return ; - } - - renderContent() { - - } -} - -ItemContainer.propTypes = { - navigator: React.PropTypes.object.isRequired, - itemUrl: React.PropTypes.string, - item: React.PropTypes.object, - setOpenItem: React.PropTypes.func, -}; - -const styles = StyleSheet.create({ - root: { - flex: 1, - }, - - content: { - flex: 1, - }, -}); - -/** - * Takes the redux `store` (passed down by - * the parent `Provider`) view and maps - * specific properties onto the App's - * `this.props` object. - * - * This means the app never touches the - * redux store directly and prevents - * hacky code being written. - * - * @param {ReduxStore} store - * @return {Object} - */ -function mapStateToProps(store) { - return { - item: store.openItem, - }; -} - -/** - * Maps the methods exported from `action-creators.js` - * to `this.props.`. - * - * @param {function} dispatch - * @return {Object} - */ -function mapDispatchToProps() { - return { - setOpenItem: actions.setOpenItem, - }; -} - -/** - * Exports - */ - -module.exports = connect(mapStateToProps, mapDispatchToProps)(ItemContainer);