feat: reactive isMobileScreen

This commit is contained in:
Yidadaa
2023-04-20 23:20:25 +08:00
parent 2390da1165
commit 55281ed548
4 changed files with 34 additions and 18 deletions

View File

@@ -17,7 +17,7 @@ import LoadingIcon from "../icons/three-dots.svg";
import CloseIcon from "../icons/close.svg";
import { useChatStore } from "../store";
import { getCSSVar, isMobileScreen } from "../utils";
import { getCSSVar, useMobileScreen } from "../utils";
import Locale from "../locales";
import { Chat } from "./chat";
@@ -103,17 +103,14 @@ function useDragSideBar() {
window.addEventListener("mousemove", handleMouseMove.current);
window.addEventListener("mouseup", handleMouseUp.current);
};
const isMobileScreen = useMobileScreen();
useEffect(() => {
if (isMobileScreen()) {
return;
}
document.documentElement.style.setProperty(
"--sidebar-width",
`${limit(chatStore.config.sidebarWidth ?? 300)}px`,
);
}, [chatStore.config.sidebarWidth]);
const sideBarWidth = isMobileScreen
? "100vw"
: `${limit(chatStore.config.sidebarWidth ?? 300)}px`;
document.documentElement.style.setProperty("--sidebar-width", sideBarWidth);
}, [chatStore.config.sidebarWidth, isMobileScreen]);
return {
onDragMouseDown,
@@ -148,6 +145,7 @@ function _Home() {
// drag side bar
const { onDragMouseDown } = useDragSideBar();
const isMobileScreen = useMobileScreen();
useSwitchTheme();
@@ -158,7 +156,7 @@ function _Home() {
return (
<div
className={`${
config.tightBorder && !isMobileScreen()
config.tightBorder && !isMobileScreen
? styles["tight-container"]
: styles.container
}`}