Skip to content

Commit

Permalink
Merge pull request #410 from evoluhq/changeset-release/main
Browse files Browse the repository at this point in the history
[ci] release
  • Loading branch information
steida authored May 22, 2024
2 parents 4715664 + 2d9ae4b commit 60f95b2
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 63 deletions.
5 changes: 0 additions & 5 deletions .changeset/brown-pugs-punch.md

This file was deleted.

8 changes: 4 additions & 4 deletions examples/vite-react-pwa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ If you are developing a production application, we recommend updating the config
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
ecmaVersion: "latest",
sourceType: "module",
project: ["./tsconfig.json", "./tsconfig.node.json"],
tsconfigRootDir: __dirname,
},
}
};
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
Expand Down
18 changes: 9 additions & 9 deletions examples/vite-react-pwa/pwa-assets.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
defineConfig,
minimal2023Preset as preset,
} from '@vite-pwa/assets-generator/config'
defineConfig,
minimal2023Preset as preset,
} from "@vite-pwa/assets-generator/config";

export default defineConfig({
headLinkOptions: {
preset: '2023',
},
preset,
images: ['public/favicon.svg'],
})
headLinkOptions: {
preset: "2023",
},
preset,
images: ["public/favicon.svg"],
});
87 changes: 50 additions & 37 deletions examples/vite-react-pwa/src/PWABadge.tsx
Original file line number Diff line number Diff line change
@@ -1,77 +1,90 @@
import './PWABadge.css'
import "./PWABadge.css";

import { useRegisterSW } from 'virtual:pwa-register/react'
import { useRegisterSW } from "virtual:pwa-register/react";

function PWABadge() {
// check for updates every hour
const period = 60 * 60 * 1000
const period = 60 * 60 * 1000;

const {
offlineReady: [offlineReady, setOfflineReady],
needRefresh: [needRefresh, setNeedRefresh],
updateServiceWorker,
} = useRegisterSW({
onRegisteredSW(swUrl, r) {
if (period <= 0) return
if (r?.active?.state === 'activated') {
registerPeriodicSync(period, swUrl, r)
}
else if (r?.installing) {
r.installing.addEventListener('statechange', (e) => {
const sw = e.target as ServiceWorker
if (sw.state === 'activated')
registerPeriodicSync(period, swUrl, r)
})
if (period <= 0) return;
if (r?.active?.state === "activated") {
registerPeriodicSync(period, swUrl, r);
} else if (r?.installing) {
r.installing.addEventListener("statechange", (e) => {
const sw = e.target as ServiceWorker;
if (sw.state === "activated") registerPeriodicSync(period, swUrl, r);
});
}
},
})
});

function close() {
setOfflineReady(false)
setNeedRefresh(false)
setOfflineReady(false);
setNeedRefresh(false);
}

return (
<div className="PWABadge" role="alert" aria-labelledby="toast-message">
{ (offlineReady || needRefresh)
&& (
{(offlineReady || needRefresh) && (
<div className="PWABadge-toast">
<div className="PWABadge-message">
{ offlineReady
? <span id="toast-message">App ready to work offline</span>
: <span id="toast-message">New content available, click on reload button to update.</span>}
{offlineReady ? (
<span id="toast-message">App ready to work offline</span>
) : (
<span id="toast-message">
New content available, click on reload button to update.
</span>
)}
</div>
<div className="PWABadge-buttons">
{ needRefresh && <button className="PWABadge-toast-button" onClick={() => updateServiceWorker(true)}>Reload</button> }
<button className="PWABadge-toast-button" onClick={() => close()}>Close</button>
{needRefresh && (
<button
className="PWABadge-toast-button"
onClick={() => updateServiceWorker(true)}
>
Reload
</button>
)}
<button className="PWABadge-toast-button" onClick={() => close()}>
Close
</button>
</div>
</div>
)}
</div>
)
);
}

export default PWABadge
export default PWABadge;

/**
* This function will register a periodic sync check every hour, you can modify the interval as needed.
* This function will register a periodic sync check every hour, you can modify
* the interval as needed.
*/
function registerPeriodicSync(period: number, swUrl: string, r: ServiceWorkerRegistration) {
if (period <= 0) return
function registerPeriodicSync(
period: number,
swUrl: string,
r: ServiceWorkerRegistration,
) {
if (period <= 0) return;

setInterval(async () => {
if ('onLine' in navigator && !navigator.onLine)
return
if ("onLine" in navigator && !navigator.onLine) return;

const resp = await fetch(swUrl, {
cache: 'no-store',
cache: "no-store",
headers: {
'cache': 'no-store',
'cache-control': 'no-cache',
cache: "no-store",
"cache-control": "no-cache",
},
})
});

if (resp?.status === 200)
await r.update()
}, period)
if (resp?.status === 200) await r.update();
}, period);
}
12 changes: 6 additions & 6 deletions examples/vite-react-pwa/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.tsx";
import "./index.css";

ReactDOM.createRoot(document.getElementById('root')!).render(
ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
);
6 changes: 6 additions & 0 deletions packages/evolu-common-web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @evolu/common-web

## 8.0.5

### Patch Changes

- 48089be: Update SQLite

## 8.0.4

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/evolu-common-web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@evolu/common-web",
"version": "8.0.4",
"version": "8.0.5",
"description": "Common code for Evolu libraries targeting web",
"keywords": [
"evolu",
Expand Down
2 changes: 1 addition & 1 deletion packages/evolu-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"peerDependencies": {
"@evolu/common": "^5.1.2",
"@evolu/common-react": "^8.0.5",
"@evolu/common-web": "^8.0.4",
"@evolu/common-web": "^8.0.5",
"react-dom": "^18.2.0"
},
"publishConfig": {
Expand Down

0 comments on commit 60f95b2

Please sign in to comment.