Commit 2d178387 authored by Hedda's avatar Hedda
Browse files

#8 started with async

parent 8e48a7ed
import axios from "axios" import axios from "axios"
import { AsyncStorage } from "react-native";
// Checks what the input is, and returns the correct fetch-URL // Checks what the input is, and returns the correct fetch-URL
// based on the input. // based on the input.
...@@ -35,3 +36,8 @@ export const UpdatePopulatiry =(destinationID, newPopularity) => { ...@@ -35,3 +36,8 @@ export const UpdatePopulatiry =(destinationID, newPopularity) => {
update: { popularity: newPopularity }, update: { popularity: newPopularity },
}) })
} }
export const _updateStorage = async () => {
const response = await AsyncStorage.getItem('favourites')
return await JSON.parse(response) || []
}
...@@ -9,7 +9,8 @@ class Card extends Component { ...@@ -9,7 +9,8 @@ class Card extends Component {
state ={ state ={
data: [], data: [],
dataElement: "", dataElement: "",
visible: false visible: false,
favouriteItems: []
} }
componentWillMount(){ componentWillMount(){
...@@ -26,9 +27,14 @@ class Card extends Component { ...@@ -26,9 +27,14 @@ class Card extends Component {
this.props.showDestination(destinationID); this.props.showDestination(destinationID);
newPop = popularity + 1 newPop = popularity + 1
UpdatePopulatiry(destinationID, newPop); UpdatePopulatiry(destinationID, newPop);
}
addFavourite(destinationID, name){
//this.setState({visible: false})
//Alert.alert(name, "added to favourites")
this.setState({visible: false})
setTimeout(()=>{Alert.alert(name + " was added to favourites")}, 1000)
} }
...@@ -101,7 +107,7 @@ class Card extends Component { ...@@ -101,7 +107,7 @@ class Card extends Component {
title={dataElement.name} title={dataElement.name}
scrolled scrolled
visible={this.state.visible} visible={this.state.visible}
onOk={() => {console.log("OK was pressed"); this.setState({visible: false})}} onOk={() => {console.log("Favourite was pressed"); this.addFavourite(dataElement._id, dataElement.name)}}
onCancel={() => {console.log("Cancel was pressed"); this.setState({visible: false})}} onCancel={() => {console.log("Cancel was pressed"); this.setState({visible: false})}}
> >
<ScrollView contentContainerStyle={styles.scrollViewContainer}> <ScrollView contentContainerStyle={styles.scrollViewContainer}>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment