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