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

#8 started with async

parent 8e48a7ed
import axios from "axios"
import { AsyncStorage } from "react-native";
// Checks what the input is, and returns the correct fetch-URL
// based on the input.
......@@ -35,3 +36,8 @@ export const UpdatePopulatiry =(destinationID, 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 {
state ={
data: [],
dataElement: "",
visible: false
visible: false,
favouriteItems: []
}
componentWillMount(){
......@@ -26,9 +27,14 @@ class Card extends Component {
this.props.showDestination(destinationID);
newPop = popularity + 1
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 {
title={dataElement.name}
scrolled
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})}}
>
<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