From 396133893e651b11af83b7b398e86bb6de25a771 Mon Sep 17 00:00:00 2001
From: hamster1963 <1410514192@qq.com>
Date: Fri, 6 Dec 2024 23:47:27 +0800
Subject: [PATCH] fix: remove pwa deps
---
src/App.tsx | 2 --
src/components/ReloadPrompt.tsx | 49 ---------------------------------
src/vite-env.d.ts | 27 ------------------
vite.config.ts | 4 +--
4 files changed, 1 insertion(+), 81 deletions(-)
delete mode 100644 src/components/ReloadPrompt.tsx
delete mode 100644 src/vite-env.d.ts
diff --git a/src/App.tsx b/src/App.tsx
index e2abea1..ea1ed0b 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -6,7 +6,6 @@ import Server from "./pages/Server";
import ServerDetail from "./pages/ServerDetail";
import NotFound from "./pages/NotFound";
import ErrorPage from "./pages/ErrorPage";
-import ReloadPrompt from "./components/ReloadPrompt";
const App: React.FC = () => {
return (
@@ -21,7 +20,6 @@ const App: React.FC = () => {
} />
-
diff --git a/src/components/ReloadPrompt.tsx b/src/components/ReloadPrompt.tsx
deleted file mode 100644
index e20371c..0000000
--- a/src/components/ReloadPrompt.tsx
+++ /dev/null
@@ -1,49 +0,0 @@
-import { useRegisterSW } from "virtual:pwa-register/react";
-import { useTranslation } from "react-i18next";
-import { toast } from "sonner";
-
-function ReloadPrompt() {
- const { t } = useTranslation();
-
- const {
- needRefresh: [needRefresh, setNeedRefresh],
- updateServiceWorker,
- } = useRegisterSW({
- onRegisteredSW(swUrl) {
- console.log(
- `SW Registered: ${swUrl} (Version: ${import.meta.env.VITE_GIT_HASH})`,
- );
- },
- onRegisterError(error) {
- console.log("SW registration error", error);
- },
- onOfflineReady() {
- toast.success(t("pwa.offlineReady"));
- },
- });
-
- const close = () => {
- setNeedRefresh(false);
- };
-
- const update = () => {
- updateServiceWorker(true);
- };
-
- if (!needRefresh) {
- return null;
- }
-
- toast.message(`${t("pwa.newContent")} (${import.meta.env.VITE_GIT_HASH})`, {
- action: {
- label: t("pwa.reload"),
- onClick: () => update(),
- },
- onDismiss: close,
- duration: Infinity,
- });
-
- return null;
-}
-
-export default ReloadPrompt;
diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts
deleted file mode 100644
index bdae67f..0000000
--- a/src/vite-env.d.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-///
-
-declare module "virtual:pwa-register/react" {
- import type { Dispatch, SetStateAction } from "react";
-
- export interface RegisterSWOptions {
- immediate?: boolean;
- onNeedRefresh?: () => void;
- onOfflineReady?: () => void;
- onRegistered?: (
- registration: ServiceWorkerRegistration | undefined,
- ) => void;
- onRegisteredSW?: (
- swScriptUrl: string,
- registration: ServiceWorkerRegistration | undefined,
- ) => void;
- onRegisterError?: (error) => void;
- }
-
- export interface RegisterSWHook {
- needRefresh: [boolean, Dispatch>];
- offlineReady: [boolean, Dispatch>];
- updateServiceWorker: (reloadPage?: boolean) => Promise;
- }
-
- export function useRegisterSW(options?: RegisterSWOptions): RegisterSWHook;
-}
diff --git a/vite.config.ts b/vite.config.ts
index f1d7e09..1e83ace 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -19,9 +19,7 @@ export default defineConfig({
define: {
"import.meta.env.VITE_GIT_HASH": JSON.stringify(getGitHash()),
},
- plugins: [
- react(),
- ],
+ plugins: [react()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),