Updated service workers and disabled FCM SW IO-195

This commit is contained in:
Patrick Fic
2021-02-24 11:18:40 -08:00
parent 19207013e2
commit d646ba4525
3 changed files with 59 additions and 68 deletions

View File

@@ -1,15 +1,17 @@
import { AlertOutlined } from "@ant-design/icons";
import { Button, notification } from "antd";
import Dinero from "dinero.js";
import i18n from "i18next";
import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import { BrowserRouter } from "react-router-dom";
import { PersistGate } from "redux-persist/integration/react";
import AppContainer from "./App/App.container";
import "./App/registerServiceWorker.component";
import LoadingSpinner from "./components/loading-spinner/loading-spinner.component";
import "./index.css";
import { persistor, store } from "./redux/store";
//import * as serviceWorker from "./serviceWorker"; //This is registered in a separate component to track notifications.
import * as serviceWorker from "./serviceWorker";
import "./translations/i18n";
import "./utils/CleanAxios";
@@ -33,4 +35,35 @@ ReactDOM.render(
document.getElementById("root")
);
//serviceWorker.register();
const onServiceWorkerUpdate = (registration) => {
console.log("onServiceWorkerUpdate", registration);
const key = `open${Date.now()}`;
const btn = (
<Button
type="primary"
onClick={async () => {
if (registration && registration.waiting) {
await registration.unregister();
// Makes Workbox call skipWaiting()
registration.waiting.postMessage({ type: "SKIP_WAITING" });
// Once the service worker is unregistered, we can reload the page to let
// the browser download a fresh copy of our app (invalidating the cache)
window.location.reload();
}
}}
>
{i18n.t("general.actions.refresh")}
</Button>
);
notification.open({
icon: <AlertOutlined />,
message: i18n.t("general.messages.newversiontitle"),
description: i18n.t("general.messages.newversionmessage"),
duration: 0,
btn,
key,
});
};
serviceWorker.register({ onUpdate: onServiceWorkerUpdate });