From e880d8d12376b127811a3913e7707cc64bb5fa5c Mon Sep 17 00:00:00 2001 From: NriotHrreion Date: Mon, 10 Jun 2024 08:37:01 +0800 Subject: [PATCH] fix: Mobile mode switching issue & perf: Cancel the preloading of web workers --- src/App.tsx | 12 ++++++++---- src/components/navbar/index.tsx | 8 +------- src/components/sidebar/index.tsx | 3 +-- src/style/adaptation/default.less | 6 ------ src/style/adaptation/mobile.less | 4 ++++ src/style/sidebar.less | 10 +--------- 6 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index c6d384e..852c06c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -5,9 +5,10 @@ import { shortcuts } from "@/global"; import { Mode, RenderedFunction } from "@/types"; import Utils from "@/utils/Utils"; import Storage from "@/utils/Storage"; +import Emitter from "@/utils/Emitter"; import { Axis } from "@/renderer/Graphics"; -import usePreloader from "@/hooks/usePreloader"; +// import usePreloader from "@/hooks/usePreloader"; // Layout import "katex/dist/katex.min.css"; @@ -31,10 +32,13 @@ const App: React.FC = () => { const [functionList, setFunctionList] = useState([]); const [axis, setAxisType] = useState(Axis.CARTESIAN); - usePreloader(new URL("@/workers/graphing.worker.ts", import.meta.url), "script"); - usePreloader(new URL("@/workers/calculating.worker.ts", import.meta.url), "script"); + // usePreloader(new URL("@/workers/graphing.worker.ts", import.meta.url), "script"); + // usePreloader(new URL("@/workers/calculating.worker.ts", import.meta.url), "script"); useEffect(() => { + // Default Mode + new Emitter().emit("switch-mode", new Storage().getItem("ca-mode", Mode.GENERAL) as Mode); + document.body.addEventListener("keydown", (e: KeyboardEvent) => { shortcuts.forEach((shortcut, key) => { if( @@ -74,7 +78,7 @@ const App: React.FC = () => {
- {!Utils.isMobile() && } +
diff --git a/src/components/navbar/index.tsx b/src/components/navbar/index.tsx index 79eb34a..883efd6 100644 --- a/src/components/navbar/index.tsx +++ b/src/components/navbar/index.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useRef } from "react"; +import React, { useRef } from "react"; import Toggle from "@nocp/toggle"; import ModeButton from "@/components/navbar/ModeButton"; @@ -8,7 +8,6 @@ import ConvertingDialog from "@/dialogs/ConvertingDialog"; import SeniorityDialog from "@/dialogs/SeniorityDialog"; import CurrencyDialog from "@/dialogs/CurrencyDialog"; -import Emitter from "@/utils/Emitter"; import Storage from "@/utils/Storage"; import useThemeDetector from "@/hooks/useThemeDetector"; import { Mode, Theme } from "@/types"; @@ -28,11 +27,6 @@ const Navbar: React.FC = () => { new Storage().setItem("ca-theme", isActive ? Theme.LIGHT : Theme.DARK); }; - useEffect(() => { - // default - new Emitter().emit("switch-mode", new Storage().getItem("ca-mode", Mode.GENERAL) as Mode); - }, []); - return ( <>