aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src
diff options
context:
space:
mode:
Diffstat (limited to 'FrontEnd/src')
-rw-r--r--FrontEnd/src/index.tsx1
-rw-r--r--FrontEnd/src/service-worker.tsx105
-rw-r--r--FrontEnd/src/sw.ts64
3 files changed, 0 insertions, 170 deletions
diff --git a/FrontEnd/src/index.tsx b/FrontEnd/src/index.tsx
index 2affb277..f14cfa8e 100644
--- a/FrontEnd/src/index.tsx
+++ b/FrontEnd/src/index.tsx
@@ -1,7 +1,6 @@
import "regenerator-runtime";
import "core-js/modules/es.promise";
import "core-js/modules/es.array.iterator";
-import "pepjs";
import React from "react";
import { createRoot } from "react-dom/client";
diff --git a/FrontEnd/src/service-worker.tsx b/FrontEnd/src/service-worker.tsx
deleted file mode 100644
index e4af54e1..00000000
--- a/FrontEnd/src/service-worker.tsx
+++ /dev/null
@@ -1,105 +0,0 @@
-import React from "react";
-import { useTranslation } from "react-i18next";
-
-import { pushAlert } from "./services/alert";
-
-import Button from "./views/common/button/Button";
-
-if (import.meta.env.PROD && "serviceWorker" in navigator) {
- let isThisTriggerUpgrade = false;
-
- const upgradeSuccessLocalStorageKey = "TIMELINE_UPGRADE_SUCCESS";
-
- if (window.localStorage.getItem(upgradeSuccessLocalStorageKey)) {
- pushAlert({
- message: "serviceWorker.upgradeSuccess",
- type: "success",
- });
- window.localStorage.removeItem(upgradeSuccessLocalStorageKey);
- }
-
- void import("workbox-window").then(({ Workbox, messageSW }) => {
- const wb = new Workbox("/sw.js");
- let registration: ServiceWorkerRegistration | undefined;
-
- // externalactivated is not usable but I still use its name.
- wb.addEventListener("controlling", () => {
- const upgradeReload = (): void => {
- window.localStorage.setItem(upgradeSuccessLocalStorageKey, "true");
- window.location.reload();
- };
-
- if (isThisTriggerUpgrade) {
- upgradeReload();
- } else {
- const Message: React.FC = () => {
- const { t } = useTranslation();
- return (
- <>
- {t("serviceWorker.externalActivatedPrompt")}
- <Button
- text="serviceWorker.reloadNow"
- color="success"
- onClick={upgradeReload}
- />
- </>
- );
- };
-
- pushAlert({
- customMessage: <Message />,
- dismissTime: "never",
- type: "primary",
- });
- }
- });
-
- wb.addEventListener("activated", (event) => {
- if (!event.isUpdate) {
- pushAlert({
- message: "serviceWorker.availableOffline",
- type: "success",
- });
- }
- });
-
- // Add an event listener to detect when the registered
- // service worker has installed but is waiting to activate.
- wb.addEventListener("waiting", (): void => {
- const upgrade = (): void => {
- isThisTriggerUpgrade = true;
- if (registration && registration.waiting) {
- // Send a message to the waiting service worker,
- // instructing it to activate.
- // Note: for this to work, you have to add a message
- // listener in your service worker. See below.
- void messageSW(registration.waiting, { type: "SKIP_WAITING" });
- }
- };
-
- const UpgradeMessage: React.FC = () => {
- const { t } = useTranslation();
- return (
- <>
- {t("serviceWorker.upgradePrompt")}
- <Button
- text="serviceWorker.upgradeNow"
- color="success"
- onClick={upgrade}
- />
- </>
- );
- };
-
- pushAlert({
- customMessage: <UpgradeMessage />,
- dismissTime: "never",
- type: "success",
- });
- });
-
- void wb.register().then((reg) => {
- registration = reg;
- });
- });
-}
diff --git a/FrontEnd/src/sw.ts b/FrontEnd/src/sw.ts
deleted file mode 100644
index a43ff9e5..00000000
--- a/FrontEnd/src/sw.ts
+++ /dev/null
@@ -1,64 +0,0 @@
-/// <reference lib="webworker" />
-
-import { precacheAndRoute, matchPrecache } from "workbox-precaching";
-import { registerRoute, setDefaultHandler } from "workbox-routing";
-import {
- NetworkFirst,
- NetworkOnly,
- StaleWhileRevalidate,
-} from "workbox-strategies";
-import { CacheableResponsePlugin } from "workbox-cacheable-response";
-import { ExpirationPlugin } from "workbox-expiration";
-
-declare let self: ServiceWorkerGlobalScope;
-
-self.addEventListener("message", (event) => {
- if (event.data && (event.data as { type: string }).type === "SKIP_WAITING") {
- void self.skipWaiting();
- }
-});
-
-precacheAndRoute(self.__WB_MANIFEST);
-
-const networkOnly = new NetworkOnly();
-
-registerRoute(new RegExp("/swagger/?.*"), new NetworkOnly());
-
-registerRoute(new RegExp("/api/token/?.*"), new NetworkOnly());
-registerRoute(new RegExp("/api/search/?.*"), new NetworkOnly());
-
-registerRoute(
- new RegExp("/api/users/.+/avatar"),
- new StaleWhileRevalidate({
- cacheName: "avatars",
- plugins: [
- new CacheableResponsePlugin({
- statuses: [200],
- }),
- new ExpirationPlugin({
- maxAgeSeconds: 60 * 60 * 24 * 30 * 3, // 3 months
- }),
- ],
- })
-);
-
-registerRoute(
- new RegExp("/api/?.*"),
- new NetworkFirst({
- plugins: [
- new CacheableResponsePlugin({
- statuses: [200],
- }),
- ],
- })
-);
-
-setDefaultHandler((options) => {
- const { request } = options;
-
- if (request instanceof Request && request.destination === "document")
- return matchPrecache("/index.html").then((r) =>
- r == null ? Response.error() : r
- );
- else return networkOnly.handle(options);
-});