Skip to content

Commit

Permalink
Service worker using rescript and Cache fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-emeks committed Apr 27, 2024
1 parent 6bfd899 commit 5218dec
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 32 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# sensum

## v1.1.2
* ServiceWorker written in rescript
* Refresh cache using the service worker (see if it works)
* Use Standalone as default mode for PWA

## v1.0.0
* Display app version
* Calculate gas cost for a sensation + UI changes
Expand Down
2 changes: 1 addition & 1 deletion sensum-pwa/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sensum-pwa",
"private": true,
"version": "1.0.0",
"version": "1.1.2",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
18 changes: 0 additions & 18 deletions sensum-pwa/src/ServiceWorker.js

This file was deleted.

19 changes: 19 additions & 0 deletions sensum-pwa/src/ServiceWorker.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// NOTE: To debug this module in the navigator use: yarn build && yarn preview

type entry = {
url: string,
revision: string
}

@module("workbox-precaching") external precacheAndRoute: array<entry> => unit = "precacheAndRoute"

@module("workbox-precaching") external cleanupOutdatedCaches: unit => unit = "cleanupOutdatedCaches"

@scope("self") external entries: array<entry> = "__WB_MANIFEST"

// Ref. https://developer.chrome.com/docs/workbox/modules/workbox-precaching
// self.__WB_MANIFEST contains the cacheable entries listed by VitePWA pluggin
precacheAndRoute(entries)

// clean old assets
cleanupOutdatedCaches()
20 changes: 11 additions & 9 deletions sensum-pwa/src/core/ui/navbar/Core_Ui_Navbar.res
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,28 @@ module DefaultRightComponent = {
}

@scope("import.meta.env") @val external appVersion: string = "APP_VERSION"
@scope("window.location") @val external reloadPage: bool => unit = "reload"

@react.component
let make = (~rightComponent: React.element=<DefaultRightComponent />) => {

let onClick = event => {
ReactEvent.Mouse.preventDefault(event)
RescriptReactRouter.replace("/dsensum")
reloadPage(true)
}

// FIXME: Make it responsive!
<header
className="border-purple-900 border-b-2 flex justify-between">
<div className="flex flex-row items-baseline">
<div className="flex flex-row items-baseline group relative">
<h1 className="pl-2 text-xl lg:text-4xl text-purple-50">
{"δensum"->React.string}
</h1>
<button onClick>
<h1 className="pl-2 text-xl lg:text-4xl text-purple-50">
{"δensum"->React.string}
</h1>
<a className="pl-2 text-sm lg:text-md text-purple-50" >
{`(v${appVersion})`->React.string}
</a>
</button>
<a className="pl-2 text-sm lg:text-md text-purple-50" >
{`(v${appVersion})`->React.string}
</a>
</div>
{rightComponent}
</header>
Expand Down
2 changes: 1 addition & 1 deletion sensum-pwa/src/pages/notFound/Pages_NotFound.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
let make = () => {
let onClick = event => {
ReactEvent.Mouse.preventDefault(event)
RescriptReactRouter.replace("/dsensum")
RescriptReactRouter.replace("/dsensum/")
}
<div className="bg-black flex flex-col h-screen overflow-hidden">
<Core.Ui.Navbar />
Expand Down
7 changes: 4 additions & 3 deletions sensum-pwa/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ export default defineConfig({
registerType: 'autoUpdate', // Vs Prompt for new content
srcDir: 'src',
base: '/dsensum/',
filename: 'ServiceWorker.js',
filename: 'ServiceWorker.bs.js',
manifest: {
id: "d-sensum",
name: 'd-sensum',
short_name: 'δensum',
// https://developer.mozilla.org/en-US/docs/Web/Manifest/display_override#values
display_override: ["minimal-ui", "browser"],
display: "minimal-ui",
display_override: ["standalone", "minimal-ui", "browser"],
display: "standalone",
start_url: '/dsensum/',
description: 'mysterious app',
theme_color: '#4B3968',
Expand Down

0 comments on commit 5218dec

Please sign in to comment.