Skip to content

Commit

Permalink
SW update available message implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
rayoverweij committed Aug 4, 2020
1 parent f6c3a02 commit c94b35c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 34 deletions.
11 changes: 0 additions & 11 deletions src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,4 @@
outline: none;
}
}
}


.alert-global {
position: absolute;
right: 7px;
top: 7px;
}

#alert-new-version-available {
display: none;
}
11 changes: 1 addition & 10 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -290,14 +289,6 @@ class App extends React.Component<AppProps, AppState> {
</Tab.Container>
</Container>

<Alert
variant="primary"
className="alert-global"
id="alert-new-version-available">
<ExclamationTriangle />&nbsp;&nbsp;
A new version of TacoTab is available! <Alert.Link onClick={() => window.location.reload()}>Click to reload.</Alert.Link>
</Alert>

<SetupScreen
init={this.state.init}
initializeTournament={this.initializeTournament} />
Expand Down
35 changes: 35 additions & 0 deletions src/ServiceWorkerWrapper.tsx
Original file line number Diff line number Diff line change
@@ -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<ServiceWorker | null>(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 (
<Alert
show={showReload}
variant="primary"
className="alert-global">
<ExclamationTriangle />&nbsp;&nbsp;
A new version of TacoTab is available! <Alert.Link onClick={reloadPage}>Click to reload.</Alert.Link>
</Alert>
);
}
1 change: 1 addition & 0 deletions src/home/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ class Settings extends React.PureComponent<SettingsProps, SettingsState> {
<p>
New in version 0.4.3:
<ul>
<li>General: from now on, when a new update to TacoTab is available, a message will tell you and let you reload</li>
<li>General: in text fields, pressing 'Enter' now submits your input rather than entering a newline</li>
<li>General: if a form can't be submitted, for example because you left crucial fields empty, the app will now give you feedback</li>
<li>General: many performance improvements, especially around editing text fields</li>
Expand Down
8 changes: 8 additions & 0 deletions src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -451,4 +451,12 @@ form.was-validated {
.modal-content {
box-shadow: $heavy;
border: none;
}


// Alert styling
.alert-global {
position: absolute;
right: 7px;
top: 7px;
}
16 changes: 3 additions & 13 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<React.StrictMode>
<ServiceWorkerWrapper />
<App />
</React.StrictMode>,
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);
// }
// });

0 comments on commit c94b35c

Please sign in to comment.