forked from Maxluli/TinderPokemon
fixed all the last big bugs before going to PWA
This commit is contained in:
@@ -62,4 +62,29 @@ function loadFromIndexedDB(storeName) {
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
function ReadFromApi(storename){
|
||||
var requestOptions = {
|
||||
method: 'GET',
|
||||
redirect: 'follow'
|
||||
};
|
||||
|
||||
fetch("https://633bde0df11701a65f69abe8.mockapi.io/api/v1/"+storename+"/", requestOptions)
|
||||
.then(response => response.text())
|
||||
.then(result => {
|
||||
let pokemons = JSON.parse(result);
|
||||
console.log(pokemons)
|
||||
})
|
||||
.catch(error => console.log('error', error));
|
||||
}
|
||||
function DeleteFromApi(storeName,id) {
|
||||
var requestOptions = {
|
||||
method: 'DELETE',
|
||||
redirect: 'follow'
|
||||
};
|
||||
|
||||
fetch("https://633bde0df11701a65f69abe8.mockapi.io/api/v1/"+storeName+"/"+id, requestOptions)
|
||||
.then(response => response.text())
|
||||
.then(result => console.log(result))
|
||||
.catch(error => console.log('error', error));
|
||||
}
|
||||
@@ -58,6 +58,7 @@
|
||||
loadData();
|
||||
}
|
||||
function loadData() {
|
||||
|
||||
loadFromIndexedDB("favorites", 0).then((response) => {
|
||||
var container = document.getElementById("cards");
|
||||
container.innerHTML = "";
|
||||
@@ -85,9 +86,9 @@
|
||||
//alert("bonsoir " + evt.target.id);
|
||||
let id = evt.target.id;
|
||||
removeFromIndexDB("favorites", id);
|
||||
DeleteFromApi("favorites", id);
|
||||
loadData();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</html>
|
||||
10
index.html
10
index.html
@@ -160,7 +160,7 @@
|
||||
}
|
||||
document.getElementById('likeButton').onclick = function () {
|
||||
if (LoadedSuccessfully) {
|
||||
saveToIndexedDB("likes", CurrentPokemon);
|
||||
//saveToIndexedDB("likes", CurrentPokemon);
|
||||
storeToApi("likes",CurrentPokemon);
|
||||
loadNewPokemon();
|
||||
}
|
||||
@@ -173,7 +173,7 @@
|
||||
}
|
||||
document.getElementById('favoriteButton').onclick = function () {
|
||||
if (LoadedSuccessfully) {
|
||||
saveToIndexedDB("favorites", CurrentPokemon);
|
||||
//saveToIndexedDB("favorites", CurrentPokemon);
|
||||
storeToApi("favorites",CurrentPokemon);
|
||||
loadNewPokemon();
|
||||
}
|
||||
@@ -263,7 +263,11 @@
|
||||
|
||||
fetch("https://633bde0df11701a65f69abe8.mockapi.io/api/v1/"+storeName+"/", requestOptions)
|
||||
.then(response => response.text())
|
||||
.then(result => console.log(result))
|
||||
.then(result => {
|
||||
let addedPokemon = JSON.parse(result);
|
||||
console.log(addedPokemon);
|
||||
saveToIndexedDB(storeName,addedPokemon);
|
||||
})
|
||||
.catch(error => console.log('error', error));
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
loadData();
|
||||
}
|
||||
function loadData(){
|
||||
//ReadFromApi("likes").then((response) => {
|
||||
loadFromIndexedDB("likes", 0).then((response) => {
|
||||
var container = document.getElementById("cards");
|
||||
container.innerHTML = "";
|
||||
@@ -90,6 +91,7 @@
|
||||
//alert("bonsoir " + evt.target.id);
|
||||
let id = evt.target.id;
|
||||
removeFromIndexDB("likes", id);
|
||||
DeleteFromApi("likes", id);
|
||||
loadData();
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user