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",
|
"version": "0.0.1",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bootstrap-icons": "^1.9.1",
|
"bootstrap-icons": "^1.9.1",
|
||||||
"nookies": "^2.5.2"
|
"nookies": "^2.5.2",
|
||||||
|
"webworker": "^0.8.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/adapter-auto": "next",
|
"@sveltejs/adapter-auto": "next",
|
||||||
|
|
@ -2358,6 +2359,14 @@
|
||||||
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
|
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/whatwg-url": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
||||||
|
|
@ -3981,6 +3990,11 @@
|
||||||
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
|
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
|
||||||
"dev": true
|
"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": {
|
"whatwg-url": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,8 @@
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"bootstrap-icons": "^1.9.1",
|
||||||
"nookies": "^2.5.2",
|
"nookies": "^2.5.2",
|
||||||
"bootstrap-icons": "^1.9.1"
|
"webworker": "^0.8.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,20 @@
|
||||||
|
|
||||||
|
<!-- ---------------------------------------------------------------- -->
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en" data-theme="emerald">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
|
<meta name="theme-color" content="#1e88e5">
|
||||||
<link rel="icon" href="../src/resources/images/logo2.svg" />
|
<link rel="icon" href="../src/resources/images/logo2.svg" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="color-scheme" content="dark light">
|
||||||
<link rel="manifest" href="../static/manifest.json">
|
<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%
|
%sveltekit.head%
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div>%sveltekit.body%</div>
|
<div>%sveltekit.body%</div>
|
||||||
|
|
||||||
<script>
|
|
||||||
if('serviceworker' in navigator){
|
|
||||||
navigator.serviceworker.register('./service-worker.js');
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
<!-- ---------------------------------------------------------------- -->
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,6 @@
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
notes = await noteRepo.getNotes();
|
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 newTitle = "New Note";
|
||||||
const newNote = await addNote(newTitle);
|
const newNote = await addNote(newTitle);
|
||||||
noteRepo.currentNoteId = newNote.id;
|
noteRepo.currentNoteId = newNote.id;
|
||||||
console.log(newNote.id);
|
|
||||||
window.location = "/editor";
|
window.location = "/editor";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,13 +35,14 @@
|
||||||
*/
|
*/
|
||||||
function deleteNotePrompt(note) {
|
function deleteNotePrompt(note) {
|
||||||
const reallyDelete = confirm("Do you really want to delete this Note?");
|
const reallyDelete = confirm("Do you really want to delete this Note?");
|
||||||
|
//TODO: custom confirm popup
|
||||||
if (reallyDelete) {
|
if (reallyDelete) {
|
||||||
deleteNote(note);
|
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
|
* @param note The note to be deleted
|
||||||
*/
|
*/
|
||||||
function deleteNote(note) {
|
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
|
* @param note The note the user clicked on
|
||||||
*/
|
*/
|
||||||
function onNoteLiClick(note) {
|
function onNoteLiClick(note) {
|
||||||
|
noteRepo.currentNoteId = note.id;
|
||||||
window.location = "/editor";
|
window.location = "/editor";
|
||||||
note.lastViewed = new Date();
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -102,7 +98,7 @@
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="offset-md-4 col-md-4">
|
<div class="offset-md-4 col-md-4">
|
||||||
{#if notes}
|
{#if notes?.length > 0}
|
||||||
<!-- Notes listing -->
|
<!-- Notes listing -->
|
||||||
<ul>
|
<ul>
|
||||||
{#each notes as note}
|
{#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(
|
/// <reference lib="webworker" />
|
||||||
({request}) => request.destination === 'image',
|
|
||||||
new workbox.strategies.CacheFirst()
|
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",
|
"lang": "en",
|
||||||
"theme_color": "#ff6600",
|
"dir": "/",
|
||||||
"name": "Pomelo Note",
|
"name": "Pomelo Note",
|
||||||
"short_name": "Pomelo",
|
"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": "/",
|
"start_url": "/",
|
||||||
"icons": [
|
"icons": [
|
||||||
{
|
{
|
||||||
|
|
@ -30,5 +37,6 @@
|
||||||
"type": "image\/png",
|
"type": "image\/png",
|
||||||
"density": "2.0"
|
"density": "2.0"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"splash_pages": null
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue