Skip to content

Commit

Permalink
feat(artusx-react): update react app
Browse files Browse the repository at this point in the history
  • Loading branch information
thonatos committed Jun 21, 2024
1 parent da2a912 commit cbc6067
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
1 change: 1 addition & 0 deletions packages/apps/artusx-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"scripts": {
"_build": "tsc && RELOAD_SW=true vite build",
"build": "",
"cy:install": "cypress install",
"cy:open": "cypress open",
"dev": "SW_DEV=true vite",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
Expand Down
16 changes: 4 additions & 12 deletions packages/apps/artusx-react/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { useState } from 'react';
import viteLogo from './assets/vite.svg';
import reactLogo from './assets/react.svg';
import './App.css';

import ReloadPrompt from './ReloadPrompt';
import Counter from './components/Counter';
import ReloadPrompt from './components/ReloadPrompt';

function App() {
const [count, setCount] = useState(0);

return (
<>
<div>
Expand All @@ -18,15 +16,9 @@ function App() {
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React + PWA</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>count is {count}</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<h1>Vite + React + PWA, v1.2</h1>
<Counter />
<p className="read-the-docs">Click on the Vite and React logos to learn more</p>

<ReloadPrompt />
</>
);
Expand Down
13 changes: 13 additions & 0 deletions packages/apps/artusx-react/src/components/Counter/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useState } from 'react';

export default function Counter() {
const [count, setCount] = useState(0);
return (
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>count is {count}</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import './ReloadPrompt.css';
import './index.css';

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

Expand All @@ -13,8 +13,8 @@ function ReloadPrompt() {
needRefresh: [needRefresh, setNeedRefresh],
updateServiceWorker,
} = useRegisterSW({
onRegisteredSW(swUrl: any, r: any) {
console.log(`Service Worker at: ${swUrl}, buildDate: ${buildDate}`);
onRegisteredSW(swUrl: string, r: any) {
console.log(`Service Worker at: ${swUrl}, buildDate: ${buildDate}, reloadSW: ${reloadSW}`);
// @ts-expect-error just ignore
if (reloadSW === 'true') {
r &&
Expand All @@ -24,14 +24,17 @@ function ReloadPrompt() {
}, 20000 /* 20s for testing purposes */);
} else {
// eslint-disable-next-line prefer-template
console.log('SW Registered: ' + r);
console.log('SW Registered', r);
}
},
onRegisterError(error: any) {
console.log('SW registration error', error);
},
});

console.log('offlineReady', offlineReady);
console.log('needRefresh', needRefresh);

const close = () => {
setOfflineReady(false);
setNeedRefresh(false);
Expand Down

0 comments on commit cbc6067

Please sign in to comment.