updated some pwa files (not working)
removed unnecessary code in listing refactored function comments
This commit is contained in:
parent
22396d1a00
commit
7abdbe605b
6 changed files with 153 additions and 57 deletions
|
|
@ -1,19 +1,20 @@
|
|||
|
||||
<!-- ---------------------------------------------------------------- -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html lang="en" data-theme="emerald">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="theme-color" content="#1e88e5">
|
||||
<link rel="icon" href="../src/resources/images/logo2.svg" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<link rel="manifest" href="../static/manifest.json">
|
||||
<meta name="color-scheme" content="dark light">
|
||||
<link rel="manifest" href="manifest.json">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="mobile-web-app-capable" content="yes" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
%sveltekit.head%
|
||||
</head>
|
||||
<body>
|
||||
<div>%sveltekit.body%</div>
|
||||
|
||||
<script>
|
||||
if('serviceworker' in navigator){
|
||||
navigator.serviceworker.register('./service-worker.js');
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
<!-- ---------------------------------------------------------------- -->
|
||||
|
||||
|
|
|
|||
|
|
@ -8,10 +8,6 @@
|
|||
|
||||
onMount(async () => {
|
||||
notes = await noteRepo.getNotes();
|
||||
notes.forEach(note => {
|
||||
note.lastViewed = new Date(note.lastViewed);
|
||||
});
|
||||
console.log(notes);
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
@ -21,7 +17,6 @@
|
|||
const newTitle = "New Note";
|
||||
const newNote = await addNote(newTitle);
|
||||
noteRepo.currentNoteId = newNote.id;
|
||||
console.log(newNote.id);
|
||||
window.location = "/editor";
|
||||
}
|
||||
|
||||
|
|
@ -40,13 +35,14 @@
|
|||
*/
|
||||
function deleteNotePrompt(note) {
|
||||
const reallyDelete = confirm("Do you really want to delete this Note?");
|
||||
//TODO: custom confirm popup
|
||||
if (reallyDelete) {
|
||||
deleteNote(note);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the note from the "notes" Array
|
||||
* Deletes the note from the "notes" Array and the database
|
||||
* @param note The note to be deleted
|
||||
*/
|
||||
function deleteNote(note) {
|
||||
|
|
@ -71,12 +67,12 @@
|
|||
}
|
||||
|
||||
/**
|
||||
* Handles a click on a note list element
|
||||
* Sets the currentNoteId and redirects to the editor
|
||||
* @param note The note the user clicked on
|
||||
*/
|
||||
function onNoteLiClick(note) {
|
||||
noteRepo.currentNoteId = note.id;
|
||||
window.location = "/editor";
|
||||
note.lastViewed = new Date();
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
@ -102,7 +98,7 @@
|
|||
|
||||
<div class="row">
|
||||
<div class="offset-md-4 col-md-4">
|
||||
{#if notes}
|
||||
{#if notes?.length > 0}
|
||||
<!-- Notes listing -->
|
||||
<ul>
|
||||
{#each notes as note}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,82 @@
|
|||
importScripts('https://storage.googleapis.com/workbos-cdn/releases/6.0.2/workbox-sw.js');
|
||||
|
||||
workbox.routing.registerRoute(
|
||||
({request}) => request.destination === 'image',
|
||||
new workbox.strategies.CacheFirst()
|
||||
);
|
||||
/// <reference lib="webworker" />
|
||||
|
||||
import { build, files, version } from '$service-worker';
|
||||
|
||||
const worker = ServiceWorkerGlobalScope;
|
||||
// const FILES = cache + version;
|
||||
|
||||
const to_cache = build.concat(files);
|
||||
const staticAssets = new Set(to_cache);
|
||||
|
||||
worker.addEventListener('install', (event) => {
|
||||
event.waitUntil(
|
||||
caches
|
||||
.open(FILES)
|
||||
.then((cache) => cache.addAll(to_cache))
|
||||
.then(() => {
|
||||
worker.skipWaiting();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
worker.addEventListener('activate', (event) => {
|
||||
event.waitUntil(
|
||||
caches.keys().then(async (keys) => {
|
||||
// delete old caches
|
||||
for (const key of keys) {
|
||||
if (key !== FILES) await caches.delete(key);
|
||||
}
|
||||
|
||||
worker.clients.claim();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Fetch the asset from the network and store it in the cache.
|
||||
* Fall back to the cache if the user is offline.
|
||||
*/
|
||||
async function fetchAndCache(request) {
|
||||
const cache = await caches.open(offline + version);
|
||||
|
||||
try {
|
||||
const response = await fetch(request);
|
||||
cache.put(request, response.clone());
|
||||
return response;
|
||||
} catch (err) {
|
||||
const response = await cache.match(request);
|
||||
if (response) return response;
|
||||
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
worker.addEventListener('fetch', (event) => {
|
||||
if (event.request.method !== 'GET' || event.request.headers.has('range')) return;
|
||||
|
||||
const url = new URL(event.request.url);
|
||||
|
||||
// don't try to handle e.g. data: URIs
|
||||
const isHttp = url.protocol.startsWith('http');
|
||||
const isDevServerRequest =
|
||||
url.hostname === self.location.hostname && url.port !== self.location.port;
|
||||
const isStaticAsset = url.host === self.location.host && staticAssets.has(url.pathname);
|
||||
const skipBecauseUncached = event.request.cache === 'only-if-cached' && !isStaticAsset;
|
||||
|
||||
if (isHttp && !isDevServerRequest && !skipBecauseUncached) {
|
||||
event.respondWith(
|
||||
(async () => {
|
||||
// always serve static files and bundler-generated assets from cache.
|
||||
// if your application has other URLs with data that will never change,
|
||||
// set this variable to true for them and they will only be fetched once.
|
||||
const cachedAsset = isStaticAsset && (await caches.match(event.request));
|
||||
|
||||
return cachedAsset || fetchAndCache(event.request);
|
||||
})()
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue