diff --git a/src/App.scss b/src/App.scss index 879e886..47b330a 100644 --- a/src/App.scss +++ b/src/App.scss @@ -204,15 +204,4 @@ outline: none; } } -} - - -.alert-global { - position: absolute; - right: 7px; - top: 7px; -} - -#alert-new-version-available { - display: none; } \ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index e6fd9a6..9fa7ec6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -16,8 +16,7 @@ import Container from 'react-bootstrap/Container'; import Tab from 'react-bootstrap/Tab'; import Nav from 'react-bootstrap/Nav'; import Collapse from 'react-bootstrap/Collapse'; -import Alert from 'react-bootstrap/Alert'; -import { List, ExclamationTriangle } from 'react-bootstrap-icons'; +import { List } from 'react-bootstrap-icons'; type AppProps = {} @@ -290,14 +289,6 @@ class App extends React.Component { - -    - A new version of TacoTab is available! window.location.reload()}>Click to reload. - - diff --git a/src/ServiceWorkerWrapper.tsx b/src/ServiceWorkerWrapper.tsx new file mode 100644 index 0000000..92b6ea6 --- /dev/null +++ b/src/ServiceWorkerWrapper.tsx @@ -0,0 +1,35 @@ +import React, { useState, useEffect } from 'react'; +import * as serviceWorker from './serviceWorker'; +import Alert from 'react-bootstrap/Alert'; +import { ExclamationTriangle } from 'react-bootstrap-icons'; + + +export const ServiceWorkerWrapper = () => { + const [showReload, setShowReload] = useState(false); + const [waitingWorker, setWaitingWorker] = useState(null); + + const onSWUpdate = (registration: ServiceWorkerRegistration) => { + setShowReload(true); + setWaitingWorker(registration.waiting); + }; + + useEffect(() => { + serviceWorker.register({ onUpdate: onSWUpdate }); + }, []); + + const reloadPage = () => { + waitingWorker?.postMessage({ type: 'SKIP_WAITING' }); + setShowReload(false); + window.location.reload(true); + } + + return ( + +    + A new version of TacoTab is available! Click to reload. + + ); +} \ No newline at end of file diff --git a/src/home/Settings.tsx b/src/home/Settings.tsx index d32318f..deefa1f 100644 --- a/src/home/Settings.tsx +++ b/src/home/Settings.tsx @@ -265,6 +265,7 @@ class Settings extends React.PureComponent {

New in version 0.4.3:

    +
  • General: from now on, when a new update to TacoTab is available, a message will tell you and let you reload
  • General: in text fields, pressing 'Enter' now submits your input rather than entering a newline
  • General: if a form can't be submitted, for example because you left crucial fields empty, the app will now give you feedback
  • General: many performance improvements, especially around editing text fields
  • diff --git a/src/index.scss b/src/index.scss index 228a742..049b752 100644 --- a/src/index.scss +++ b/src/index.scss @@ -451,4 +451,12 @@ form.was-validated { .modal-content { box-shadow: $heavy; border: none; +} + + +// Alert styling +.alert-global { + position: absolute; + right: 7px; + top: 7px; } \ No newline at end of file diff --git a/src/index.tsx b/src/index.tsx index cb90a01..44b8ddf 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -3,23 +3,13 @@ import ReactDOM from 'react-dom'; import './custom.scss'; import './index.scss'; import App from './App'; -import * as serviceWorker from './serviceWorker'; +import { ServiceWorkerWrapper } from './ServiceWorkerWrapper'; + ReactDOM.render( + , document.getElementById('root') ); - -serviceWorker.register(); - -// serviceWorker.register({ -// onUpdate: (registration: ServiceWorkerRegistration) => { -// document.getElementById("alert-new-version-available")?.classList.add("show"); -// if( registration && registration.waiting ) { -// registration.waiting.postMessage({type: 'SKIP_WAITING '}); -// } -// window.location.reload(true); -// } -// });