Skip to content

Commit

Permalink
fix: Mobile mode switching issue & perf: Cancel the preloading of web…
Browse files Browse the repository at this point in the history
… workers
  • Loading branch information
NriotHrreion committed Jun 10, 2024
1 parent d334636 commit e880d8d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 28 deletions.
12 changes: 8 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -31,10 +32,13 @@ const App: React.FC = () => {
const [functionList, setFunctionList] = useState<RenderedFunction[]>([]);
const [axis, setAxisType] = useState<Axis>(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(
Expand Down Expand Up @@ -74,7 +78,7 @@ const App: React.FC = () => {
<main className="calcium" id="calcium-main">
<MainContext.Provider value={{ mode, setMode, functionList, setFunctionList, axis, setAxisType }}>
<AliveScope>
{!Utils.isMobile() && <Navbar />}
<Navbar />
<div className="app">
<Sidebar />
<Calculator />
Expand Down
8 changes: 1 addition & 7 deletions src/components/navbar/index.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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";
Expand All @@ -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 (
<>
<nav className="navbar">
Expand Down
3 changes: 1 addition & 2 deletions src/components/sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ const Sidebar: React.FC = () => {
return (
<aside className={"sidebar-container"+ (sidebarOpen ? " open" : "")} style={!Utils.isMobile() ? { width } : {}}>
{/* Mobile only */}
{Utils.isMobile() && <div className="mobile-control-panel">
{<div className="mobile-control-panel">
<div className="sidebar-title">
<span>Calcium {version}</span>
</div>

<div className="mode-switcher-wrapper">
<div className="mode-switcher-tab-slider" style={{ transform: "translateY("+ mode * 100 +"%)" }}/>
<div className="mode-switcher">
<ModeButton name="通用" mode={Mode.GENERAL}/>
<ModeButton name="图像" mode={Mode.GRAPHING}/>
Expand Down
6 changes: 0 additions & 6 deletions src/style/adaptation/default.less
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
}
}

@media screen and (max-width: 1480px) {
.mode-switcher {
min-width: 50px;
}
}

@media screen and (min-width: 1024px) {
.sidebar-container {
min-width: 315px;
Expand Down
4 changes: 4 additions & 0 deletions src/style/adaptation/mobile.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
display: block !important;
}
main {
nav.navbar {
display: none;
}
.app {
border-top: none !important;
aside {
Expand All @@ -21,6 +24,7 @@
}
}
.mobile-control-panel {
display: block;
width: 100%;
height: 100%;
border: none;
Expand Down
10 changes: 1 addition & 9 deletions src/style/sidebar.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
flex-direction: row;
.border-line(top);
.mobile-control-panel {
display: flex;
display: none;
flex-direction: column;
justify-content: space-between;
width: 65px;
Expand All @@ -18,14 +18,6 @@
}
.mode-switcher-wrapper {
position: relative;
.mode-switcher-tab-slider {
position: absolute;
left: 0;
width: 3px;
height: 33%;
background-color: var(--ca-blue4);
transition: transform .15s ease;
}
.mode-switcher {
font-size: 0;
.mode-button-container {
Expand Down

1 comment on commit e880d8d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.