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
16
frontend/svelte/package-lock.json
generated
16
frontend/svelte/package-lock.json
generated
|
|
@ -9,7 +9,8 @@
|
|||
"version": "0.0.1",
|
||||
"dependencies": {
|
||||
"bootstrap-icons": "^1.9.1",
|
||||
"nookies": "^2.5.2"
|
||||
"nookies": "^2.5.2",
|
||||
"webworker": "^0.8.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-auto": "next",
|
||||
|
|
@ -2358,6 +2359,14 @@
|
|||
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/webworker": {
|
||||
"version": "0.8.4",
|
||||
"resolved": "https://registry.npmjs.org/webworker/-/webworker-0.8.4.tgz",
|
||||
"integrity": "sha512-zzsVxtHf+mCn0WuYLarSWfRGmX7JiYKkKvso5FYC7rJ9G8svwGQA5a51Sjq9D2c/rKVU6U/kyBcaI7gUTVlsJg==",
|
||||
"engines": {
|
||||
"node": ">=0.4.3"
|
||||
}
|
||||
},
|
||||
"node_modules/whatwg-url": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
||||
|
|
@ -3981,6 +3990,11 @@
|
|||
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
|
||||
"dev": true
|
||||
},
|
||||
"webworker": {
|
||||
"version": "0.8.4",
|
||||
"resolved": "https://registry.npmjs.org/webworker/-/webworker-0.8.4.tgz",
|
||||
"integrity": "sha512-zzsVxtHf+mCn0WuYLarSWfRGmX7JiYKkKvso5FYC7rJ9G8svwGQA5a51Sjq9D2c/rKVU6U/kyBcaI7gUTVlsJg=="
|
||||
},
|
||||
"whatwg-url": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@
|
|||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"bootstrap-icons": "^1.9.1",
|
||||
"nookies": "^2.5.2",
|
||||
"bootstrap-icons": "^1.9.1"
|
||||
"webworker": "^0.8.4"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
})()
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,16 @@
|
|||
|
||||
{
|
||||
"background_color": "#ffffff",
|
||||
"theme_color": "#ff6600",
|
||||
"lang": "en",
|
||||
"dir": "/",
|
||||
"name": "Pomelo Note",
|
||||
"short_name": "Pomelo",
|
||||
"display": "minimal-ui",
|
||||
"description": "Best Note App",
|
||||
"theme_color": "#000",
|
||||
"background_color": "#000",
|
||||
"display": "standalone",
|
||||
"orientation": "portrait",
|
||||
"prefer_related_applications": false,
|
||||
"scope": "/",
|
||||
"start_url": "/",
|
||||
"icons": [
|
||||
{
|
||||
|
|
@ -30,5 +37,6 @@
|
|||
"type": "image\/png",
|
||||
"density": "2.0"
|
||||
}
|
||||
]
|
||||
],
|
||||
"splash_pages": null
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue