The app is now officially a PWA

This commit is contained in:
maxluli
2022-10-11 11:10:31 +02:00
parent cb8162214f
commit d23eb50fb3
6 changed files with 46 additions and 14 deletions

View File

@@ -0,0 +1,14 @@
{
"name": "Tinder for pokemons 2022",
"short_name": "Pokinder",
"start_url": "/es2-2022-2023/rhmr/PokemonTinder/index.html",
"id": "/es2-2022-2023/rhmr/PokemonTinder/index.html",
"display": "fullscreen",
"icons": [
{
"src": "/es2-2022-2023/rhmr/PokemonTinder/assets/img/Icon2.png",
"sizes": "144x144",
"type": "image/png"
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 297 B

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,3 @@
[ZoneTransfer]
ZoneId=3
HostUrl=https://www.piskelapp.com/

BIN
assets/img/Icon2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -19,7 +19,24 @@
<title>Tinder Pokemon</title>
<link rel="icon" type="image/x-icon" href="assets/img/Icon.ico">
<link rel="manifest" href="assets/JsStuff/manifest.webmanifest">
</head>
<script>
if ('serviceWorker' in navigator) {
// Register a service worker hosted at the root of the
// site using the default scope.
navigator.serviceWorker.register('/es2-2022-2023/rhmr/PokemonTinder/sw.js').then(
(registration) => {
console.log('Service worker registration succeeded:', registration)
},
/*catch*/(error) => {
console.log('Service worker registration failed:', error)
}
)
} else {
console.log('Service workers are not supported.')
}
</script>
<body id="main">
<div class="d-grid gap-2 text-center">
@@ -30,15 +47,6 @@
<h2>Home</h2>
</div>
</div>
<!---
<div class="container">
<div class="card p-2 text-center">
<div class="card-body">
This definitely is an AD
</div>
</div>
</div>
-->
<div class="container">
<div class="card p-2">
<img id="pokemonImage" style="image-rendering: pixelated;"
@@ -161,7 +169,7 @@
document.getElementById('likeButton').onclick = function () {
if (LoadedSuccessfully) {
//saveToIndexedDB("likes", CurrentPokemon);
storeToApi("likes",CurrentPokemon);
storeToApi("likes", CurrentPokemon);
loadNewPokemon();
}
};
@@ -174,7 +182,7 @@
document.getElementById('favoriteButton').onclick = function () {
if (LoadedSuccessfully) {
//saveToIndexedDB("favorites", CurrentPokemon);
storeToApi("favorites",CurrentPokemon);
storeToApi("favorites", CurrentPokemon);
loadNewPokemon();
}
}
@@ -242,7 +250,7 @@
);
}
//This code... you wont believe it... its still not mine HAHAHAHAHA but now its from postman
function storeToApi(storeName,pokemon) {
function storeToApi(storeName, pokemon) {
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");
@@ -261,12 +269,12 @@
redirect: 'follow'
};
fetch("https://633bde0df11701a65f69abe8.mockapi.io/api/v1/"+storeName+"/", requestOptions)
fetch("https://633bde0df11701a65f69abe8.mockapi.io/api/v1/" + storeName + "/", requestOptions)
.then(response => response.text())
.then(result => {
let addedPokemon = JSON.parse(result);
console.log(addedPokemon);
saveToIndexedDB(storeName,addedPokemon);
saveToIndexedDB(storeName, addedPokemon);
})
.catch(error => console.log('error', error));
}

7
sw.js Normal file
View File

@@ -0,0 +1,7 @@
// This code executes in its own worker or thread
self.addEventListener("install", event => {
console.log("Service worker installed");
});
self.addEventListener("activate", event => {
console.log("Service worker activated");
});