Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
IT2810-H19
Teams
Team 10
Prosjekt 4
Commits
2d178387
Commit
2d178387
authored
Nov 12, 2019
by
Hedda
Browse files
#8
started with async
parent
8e48a7ed
Changes
3
Hide whitespace changes
Inline
Side-by-side
frontend/api/fetchers.js
View file @
2d178387
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
)
||
[]
}
frontend/components/Cards/HomeCard.js
View file @
2d178387
...
...
@@ -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
}
>
...
...
frontend/components/Favourite.js
0 → 100644
View file @
2d178387
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment