Skip to content

Commit

Permalink
Merge pull request #62 from shadmazumder/hotfix-offline-data
Browse files Browse the repository at this point in the history
Hotfix offline data- on Hold. Please do not merge.
  • Loading branch information
shadmazumder authored Feb 2, 2018
2 parents 4c1f6ca + 37a60a1 commit 1f703f7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 59 deletions.
7 changes: 6 additions & 1 deletion app/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,17 @@ export function getBookCharacterList (charUrlList) {
let connectionManger = new ConnectionManager ();
connectionManger.getCharacterDetailsWith (characterUrl).then (
resp => {
if (resp.data && resp.data != null) {
if (resp.status == 200 && resp.data && resp.data != null) {
characterList.push (resp.data);
dispatch ({
type: ACTION_TYPES.SINGLE_BOOK_CHAR_LIST,
payload: characterList,
});
} else {
dispatch ({
type: ACTION_TYPES.SINGLE_BOOK_CHAR_LIST,
payload: null,
});
}
},
error => {
Expand Down
4 changes: 2 additions & 2 deletions app/containers/BookCharacterList.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class BookCharacterList extends React.Component {
}

render() {
if (this.props.characters.length == 0) {
if (this.props.characters && this.props.characters.length == 0) {
return (
<Spinner
visible={true}
textContent={"Loading..."}
textContent={"Loading ..."}
textStyle={{ color: '#FFF' }}
/>
)
Expand Down
9 changes: 4 additions & 5 deletions app/containers/BookDetailScreen.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React, { Component } from 'react';
import { StyleSheet } from 'react-native';
import { Text, View } from 'react-native';
import { View } from 'react-native';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';

import DetailComponent from '../components/DetailComponent';
import { getBookCharacterList, resetBookCharacters } from '../actions';

import CharacterList from './BookCharacterList';
Expand All @@ -16,13 +15,13 @@ class HouseDetails extends Component {
}

render() {
this.props.getCharacterList(this.props.book.characters)
this.props.getCharacterList(this.props.book.characters)
return (
<View style={styles.container}>
<CharacterList
navScreen = 'BookCharacter'
navScreen='BookCharacter'
navigation={this.props.navigation}
headline = {"Characters"}
headline={"Characters"}
/>
</View>
);
Expand Down
91 changes: 40 additions & 51 deletions app/containers/BookScreen.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,67 @@
import React, {Component} from 'react';
import {StyleSheet, Alert} from 'react-native';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import React, { Component } from 'react';
import { StyleSheet, Alert } from 'react-native';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import Spinner from 'react-native-loading-spinner-overlay';

import ContainerList from '../components/ListComponent';
import BasicListItem from '../components/BasicListItem';

import {getAllBooks, setBook} from '../actions/index';
import ConnectionManager from '../services/ConnectionManager';
import { getAllBooks, setBook } from '../actions/index';

class BookScreen extends React.Component {

renderListItem = item => {
return <BasicListItem
item={item}
title = {item.name}
subTitle = {`${item.publisher}, ${item.country}`}
onPress={this.itemOnPress}
/>;
};
renderListItem = item => {
return <BasicListItem
item={item}
title={item.name}
subTitle={`${item.publisher}, ${item.country}`}
onPress={this.itemOnPress}
/>;
};

listItemKeyExtractor = item => {
return item.url
}
listItemKeyExtractor = item => {
return item.url
}

itemOnPress = (item) => {
if (ConnectionManager.isInternetConnected) {
this.props.setBook(item)
this.props.navigation.navigate('BookDetails', item);
}else {
Alert.alert (
'No Internet!!',
'Please enable your internet connection to view this',
[{text: 'OK', onPress: () => {}}],
{cancelable: false}
);
}

}
itemOnPress = (item) => {
this.props.setBook(item);
this.props.navigation.navigate('BookDetails', item);
}

componentDidMount () {
this.props.getAllBooks ();
componentDidMount() {
this.props.getAllBooks();
}

render () {
render() {
if (this.props.books && this.props.books.length == 0) {
return (
<Spinner
visible={true}
textContent={'Loading...'}
textStyle={{color: '#FFF'}}
textStyle={{ color: '#FFF' }}
/>
);
}
return (
<ContainerList
containerStyle={styles.container}
items={this.props.books}
listItem={this.renderListItem}
keyExtractor={this.listItemKeyExtractor}
/>
);
}
return (
<ContainerList
containerStyle={styles.container}
items={this.props.books}
listItem={this.renderListItem}
keyExtractor={this.listItemKeyExtractor}
/>
);
}
}

function mapToStateProps (state) {
function mapToStateProps(state) {
return {
books: state.books,
};
}

function mapDispatchToProps (dispatch) {
return bindActionCreators (
function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
getAllBooks: getAllBooks,
setBook: setBook,
Expand All @@ -82,9 +71,9 @@ function mapDispatchToProps (dispatch) {
}

const styles = StyleSheet.create({
container: {
flex: 1,
}
container: {
flex: 1,
}
});

export default connect (mapToStateProps, mapDispatchToProps) (BookScreen);
export default connect(mapToStateProps, mapDispatchToProps)(BookScreen);

0 comments on commit 1f703f7

Please sign in to comment.