Skip to content

Commit

Permalink
Yes, the PWA works.
Browse files Browse the repository at this point in the history
  • Loading branch information
zgoda committed Nov 9, 2021
1 parent dd204d0 commit 933c761
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 86 deletions.
2 changes: 1 addition & 1 deletion src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { ReloadPrompt } from './components/reloadprompt';
export function App() {
return (
<>
<ReloadPrompt />
<Header />
<Calculator />
<Footer />
<ReloadPrompt />
</>
);
}
2 changes: 1 addition & 1 deletion src/components/calculator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function Calculator() {
useEffect(() => {
setSelectedItem(items[0]);
setTableType(TableType.MODERN);
}, [items, tables]);
}, [items]);

const showResultsPanel = () => setResultsVisible(!resultsVisible);

Expand Down
8 changes: 8 additions & 0 deletions src/components/reloadprompt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"text": {
"offlineReady": "Aplikacja gotowa do pracy offline",
"contentRefresh": "Dostępna jest nowa wersja aplikacji, kliknij guzik \"Przeładuj\" aby ją odświeżyć",
"reloadButton": "Przeładuj",
"closeButton": "Zamknij"
}
}
47 changes: 47 additions & 0 deletions src/components/reloadprompt.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { useRegisterSW } from 'virtual:pwa-register/react';

import { text } from './reloadprompt.json';

export function ReloadPrompt() {
const {
offlineReady: [offlineReady, setOfflineReady],
needRefresh: [needRefresh, setNeedRefresh],
updateServiceWorker,
} = useRegisterSW({
onRegistered(r) {
console.log(`SW Registered: ${r}`);
},
onRegisterError(error) {
console.log('SW registration error', error);
},
});

const close = () => {
setOfflineReady(false);
setNeedRefresh(false);
};

return (
<>
{(offlineReady || needRefresh) && (
<section>
{offlineReady ? <p>{text.offlineReady}</p> : <p>{text.contentRefresh}</p>}
<div class="grid">
{needRefresh && (
<div>
<button class="autowidth" onClick={() => updateServiceWorker(true)}>
{text.reloadButton}
</button>
</div>
)}
<div>
<button class="autowidth" onClick={() => close()}>
{text.closeButton}
</button>
</div>
</div>
</section>
)}
</>
);
}
32 changes: 0 additions & 32 deletions src/components/reloadprompt.module.css

This file was deleted.

52 changes: 0 additions & 52 deletions src/components/reloadprompt.tsx

This file was deleted.

4 changes: 4 additions & 0 deletions src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ footer > div.grid > div {
color: darkgoldenrod;
font-weight: bold;
}

.autowidth {
width: auto;
}

0 comments on commit 933c761

Please sign in to comment.