Skip to content

Commit

Permalink
feat: basic pwa
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 committed Jan 30, 2024
1 parent d23afec commit f72457d
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build/esbuild-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const typescriptEntries = [
// "src/authenticated/authenticated.ts"
];
const cssEntries = ["static/style/style.css"];
const entries = [...typescriptEntries, ...cssEntries];
const entries = [...typescriptEntries, ...cssEntries, "static/manifest.json", "static/favicon.svg"];

export const esBuildContext: esbuild.BuildOptions = {
define: createEnvDefines(["SUPABASE_URL", "SUPABASE_KEY"]),
Expand Down
2 changes: 2 additions & 0 deletions src/home/home.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { pwa } from "../progressive-web-app";
pwa();
import { grid } from "../the-grid";
import { authentication } from "./authentication";
import { fetchAndDisplayPreviewsFromCache } from "./fetch-github/fetch-and-display-previews";
Expand Down
30 changes: 30 additions & 0 deletions src/progressive-web-app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export function pwa() {
self.addEventListener("install", (event: InstallEvent) => {
event.waitUntil(
caches.open("v1").then((cache) => {
return cache.addAll(["/", "/dist/src/home/home.js", "/style/style.css", "/style/inverted-style.css", "/favicon.svg"]);
})
);
});

self.addEventListener("fetch", (event: FetchEvent) => {
event.respondWith(
caches.match(event.request).then((response) => {
return response || fetch(event.request);
})
);
});

if ("serviceWorker" in navigator) {
window.addEventListener("load", () => {
navigator.serviceWorker.register("/sw.js").then(
(registration) => {
console.log("ServiceWorker registration successful with scope: ", registration.scope);
},
(err) => {
console.log("ServiceWorker registration failed: ", err);
}
);
});
}
}
5 changes: 5 additions & 0 deletions static/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html lang="en">
<head>

<meta charset="UTF-8" />
<title>DevPool Directory | Ubiquity DAO</title>

Expand Down Expand Up @@ -29,6 +30,10 @@
<meta property="og:url" content="https://work.ubq.fi" />
<meta property="twitter:domain" content="work.ubq.fi" />
<meta property="twitter:url" content="https://work.ubq.fi" />

<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no, viewport-fit=cover" />
<link rel="manifest" href="/manifest.json">

</head>
<body>
<background><div id="grid"></div></background>
Expand Down
17 changes: 17 additions & 0 deletions static/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "DevPool Directory | Ubiquity DAO",
"short_name": "DevPool Directory",
"description": "View and sort through all of the available work within the DevPool network.",
"start_url": "/",
"display": "standalone",
"background_color": "#000410",
"theme_color": "#000410",
"icons": [
{
"src": "/favicon.svg",
"sizes": "any",
"type": "image/svg+xml",
"purpose": "any maskable"
}
]
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/* Language and Environment */
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
"lib": ["DOM", "ESNext"] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
Expand Down

0 comments on commit f72457d

Please sign in to comment.