diff --git a/index.html b/index.html index a6ea1436f..2ba59d87d 100644 --- a/index.html +++ b/index.html @@ -79,5 +79,22 @@ + + diff --git a/langs/en.json b/langs/en.json index ea7b69579..34870673c 100644 --- a/langs/en.json +++ b/langs/en.json @@ -280,6 +280,7 @@ "browseNearby": "Browse nearby images...", "confirm": "The selected image shows {title()}", "hasMatchingPicture": "Does a picture match the object? Select it below", + "loadMore": "Load more images", "loading": "Loading nearby images...", "noImageSelected": "Select an image to link it to the object", "nothingFound": "No nearby images found...", diff --git a/package-lock.json b/package-lock.json index e64e522b9..9dda0520c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "GPL", "dependencies": { "@babel/preset-env": "7.13.8", + "@parcel/service-worker": "^2.5.0", "@turf/buffer": "^6.5.0", "@turf/collect": "^6.5.0", "@turf/distance": "^6.5.0", @@ -1393,6 +1394,19 @@ "node": ">= 6.0.0" } }, + "node_modules/@parcel/service-worker": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@parcel/service-worker/-/service-worker-2.5.0.tgz", + "integrity": "sha512-4kcY3uG/ureZqWf89N2QcW0MjBtNxvZrJEp3uTbaRaNgwYfyqebXW2eKtgKixsGLFMOV2rvEUoiDScMAZSBXOg==", + "engines": { + "node": ">= 12.0.0", + "parcel": "^2.5.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, "node_modules/@parcel/utils": { "version": "1.11.0", "resolved": "https://registry.npmjs.org/@parcel/utils/-/utils-1.11.0.tgz", @@ -17716,6 +17730,11 @@ "strip-ansi": "^4.0.0" } }, + "@parcel/service-worker": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@parcel/service-worker/-/service-worker-2.5.0.tgz", + "integrity": "sha512-4kcY3uG/ureZqWf89N2QcW0MjBtNxvZrJEp3uTbaRaNgwYfyqebXW2eKtgKixsGLFMOV2rvEUoiDScMAZSBXOg==" + }, "@parcel/utils": { "version": "1.11.0", "resolved": "https://registry.npmjs.org/@parcel/utils/-/utils-1.11.0.tgz", diff --git a/package.json b/package.json index 137980198..aee80b785 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "gittag": "ts-node scripts/printVersion.ts | bash", "lint": "tslint --project . -c tslint.json '**.ts' ", "clean:tests": "(find . -type f -name \"*.doctest.ts\" | xargs rm)", - "clean": "rm -rf .cache/ && (find *.html | grep -v \"\\(404\\|index\\|land\\|test\\|preferences\\|customGenerator\\|professional\\|automaton\\|import_helper\\|import_viewer\\|theme\\).html\" | xargs rm) && (ls | grep \"^index_[a-zA-Z_-]\\+\\.ts$\" | xargs rm) && (ls | grep \".*.webmanifest$\" | grep -v \"manifest.webmaifest\" | xargs rm)", + "clean": "rm -rf .cache/ && (find *.html | grep -v \"\\(404\\|index\\|land\\|test\\|preferences\\|customGenerator\\|professional\\|automaton\\|import_helper\\|import_viewer\\|theme\\).html\" | xargs rm) && (ls | grep \"^index_[a-zA-Z_-]\\+\\.ts$\" | xargs rm) && (ls | grep \".*.webmanifest$\" | grep -v \"manifest.webmanifest\" | xargs rm)", "generate:dependency-graph": "node_modules/.bin/depcruise --exclude \"^node_modules\" --output-type dot Logic/State/MapState.ts > dependencies.dot && dot dependencies.dot -T svg -o dependencies.svg && rm dependencies.dot", "script": "ts-node", "merge-translations": "git remote update weblate ; git merge weblate/master" @@ -57,6 +57,7 @@ "license": "GPL", "dependencies": { "@babel/preset-env": "7.13.8", + "@parcel/service-worker": "^2.5.0", "@turf/buffer": "^6.5.0", "@turf/collect": "^6.5.0", "@turf/distance": "^6.5.0", diff --git a/service-worker.js b/service-worker.js new file mode 100644 index 000000000..23aadf886 --- /dev/null +++ b/service-worker.js @@ -0,0 +1,57 @@ +import {manifest, version} from '@parcel/service-worker'; + +async function install() { + console.log("Installing service worker!") + const cache = await caches.open(version); + console.log("Manifest file", manifest) + // await cache.addAll(manifest); + /* await cache.add({ + cache: "force-cache", + url: "http://4.bp.blogspot.com/-_vTDmo_fSTw/T3YTV0AfGiI/AAAAAAAAAX4/Zjh2HaoU5Zo/s1600/beautiful%2Bkitten.jpg", + destination: "image", + })//*/ +} + +addEventListener('install', e => e.waitUntil(install())); + +async function activate() { + console.log("Activating service worker") + /*self.registration.showNotification("SW started", { + actions: [{ + action: "OK", + title: "Some action" + }] + })*/ + const keys = await caches.keys(); + await Promise.all( + keys.map(key => key !== version && caches.delete(key)) + ); +} + +addEventListener('activate', e => e.waitUntil(activate())); + +self.addEventListener('fetch', (event) => { + try { + + if (event.request.url === "http://127.0.0.1:1234/somedata") { + console.log("Sending hi to 'somedata'") + event.respondWith(new Response("Service worker is active")) + return + } + const origin = new URL(self.origin) + const requestUrl = new URL(event.request.url) + console.log("Testing cache", origin.host, requestUrl.host, origin.host === requestUrl.host) + if (origin.host !== requestUrl.host) { + event.respondWith(fetch(event.request)); + return + } + event.respondWith( + caches.match(event.request).then(function (response) { + return response || fetch(event.request); + }), + ); + } catch (e) { + console.error("CRASH IN SW:", e) + event.respondWith(fetch(event.request)); + } +}); diff --git a/test.html b/test.html index 1ec543f93..93f49dc0d 100644 --- a/test.html +++ b/test.html @@ -24,6 +24,21 @@ - + diff --git a/test.ts b/test.ts index 815c72ddb..479e4d9be 100644 --- a/test.ts +++ b/test.ts @@ -1,19 +1,14 @@ -import {SelectOneNearbyImage} from "./UI/Popup/NearbyImages"; -import Minimap from "./UI/Base/Minimap"; -import MinimapImplementation from "./UI/Base/MinimapImplementation"; -import {VariableUiElement} from "./UI/Base/VariableUIElement"; -import Loc from "./Models/Loc"; -import {UIEventSource} from "./Logic/UIEventSource"; +import {FixedUiElement} from "./UI/Base/FixedUiElement"; +import Img from "./UI/Base/Img"; +import { Utils } from "./Utils"; -MinimapImplementation.initialize() -const map = Minimap.createMiniMap({ - location: new UIEventSource({ - lon: 3.22457, - lat: 51.20876, - zoom: 18 +new FixedUiElement("Hi").AttachTo("maindiv") + +window.setTimeout(() => { + new FixedUiElement("Loading...").AttachTo("maindiv") +// new Img("http://4.bp.blogspot.com/-_vTDmo_fSTw/T3YTV0AfGiI/AAAAAAAAAX4/Zjh2HaoU5Zo/s1600/beautiful%2Bkitten.jpg").AttachTo("maindiv") + Utils.download("http://127.0.0.1:1234/somedata").then(data => { + console.log("Got ", data) + return new FixedUiElement(data).AttachTo("extradiv"); }) -}) -map.AttachTo("extradiv") -map.SetStyle("height: 500px") - -new VariableUiElement(map.location.map( loc => new SelectOneNearbyImage( {...loc, radius: 50}))).AttachTo("maindiv") \ No newline at end of file +}, 1000) diff --git a/theme.html b/theme.html index 82d445aa6..14bb5a91b 100644 --- a/theme.html +++ b/theme.html @@ -87,5 +87,22 @@ + +