Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsyncStorage added for local caching #52

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dependencies": {
"native-base": "2.2.0",
"prop-types": "^15.5.10",
"react": "16.0.0-alpha.12",
"react": "^16.0.0-alpha.12",
"react-burger-menu": "^2.1.3",
"react-burger-nav": "^2.0.2",
"react-native": "0.45.1",
Expand All @@ -18,6 +18,7 @@
"react-native-material-ui": "^1.12.0",
"react-native-responsive-image": "^2.1.0",
"react-native-spinkit": "^1.1.1",
"react-native-vector-icons": "^4.1.1",
"react-navigation": "^1.0.0-beta.11",
"react-redux": "^5.0.5",
"redux": "^3.7.1",
Expand Down
29 changes: 21 additions & 8 deletions src/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import { FETCHED_DATA, START_FETCHING } from './types';

import {AsyncStorage} from 'react-native';
import Api from '../api/Api';

export const actionFetchData = () => (dispatch) => {
dispatch({ type: START_FETCHING });
Api.getCombinedData(Api.getCategories, Api.getSites, Api.getThumbnail)
.then((data) => {
dispatch({
type: FETCHED_DATA,
payload: data,
});
});
AsyncStorage.getItem('data').then(
(value)=>{
if(value){
dispatch({
type: FETCHED_DATA,
payload: JSON.parse(value),
});
}
else{
Api.getCombinedData(Api.getCategories, Api.getSites, Api.getThumbnail)
.then((data) => {
dispatch({
type: FETCHED_DATA,
payload: data,
});
AsyncStorage.setItem('data', JSON.stringify(data));
});
}
}
);
};
10 changes: 7 additions & 3 deletions src/components/common/BoxItem.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, TouchableHighlight, View, Platform } from 'react-native';
import { StyleSheet, TouchableHighlight, View, Platform, Image } from 'react-native';
import ResponsiveImage from 'react-native-responsive-image';

import { UNKNOWN } from '../../../img/index';
Expand Down Expand Up @@ -33,11 +33,15 @@ class Item extends Component {
return (
<TouchableHighlight onPress={onPress} >
<View style={styles.box} >
<ResponsiveImage
<Image
source={thumbUri}
style={{width:138,height:138}}
/>
{/* <ResponsiveImage
source={thumbUri}
initWidth="138"
initHeight="138"
/>
/> */}
</View>
</TouchableHighlight>
);
Expand Down
19 changes: 11 additions & 8 deletions src/reducers/data_reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ const InitialState = {
};

export default (state = InitialState, action) => {
let result = Object.assign({}, state);
switch (action.type) {
case FETCHED_DATA:
return Object.assign({}, state, {
categories: action.payload,
isFetching: false,
});
return {
...result,
categories: action.payload,
isFetching: false,
};
case START_FETCHING:
return Object.assign({}, state, {
categories: [],
isFetching: true,
});
return {
...result,
categories: [],
isFetching: true,
};
default:
return state;
}
Expand Down