@@ -225,7 +229,7 @@ const ConversationView = () => {
-
+
);
};
diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index 55f7e61..c702f02 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -2,8 +2,7 @@ import { NextPage } from "next";
import Head from "next/head";
import dynamic from "next/dynamic";
import Script from "next/script";
-import React, { useEffect } from "react";
-import { ResponsiveWidth, useLayoutStore } from "@/store";
+import React from "react";
// Use dynamic import to avoid page hydrated.
// reference: https://github.com/pmndrs/zustand/issues/1145#issuecomment-1316431268
@@ -18,25 +17,6 @@ const QueryDrawer = dynamic(() => import("@/components/QueryDrawer"), {
});
const IndexPage: NextPage = () => {
- const layoutStore = useLayoutStore();
-
- useEffect(() => {
- const handleWindowResize = () => {
- if (window.innerWidth < ResponsiveWidth.lg) {
- layoutStore.toggleSidebar(false);
- } else {
- layoutStore.toggleSidebar(true);
- }
- };
-
- handleWindowResize();
- window.addEventListener("resize", handleWindowResize);
-
- return () => {
- window.removeEventListener("resize", handleWindowResize);
- };
- }, []);
-
return (
@@ -53,17 +33,9 @@ const IndexPage: NextPage = () => {
SQL Chat
-
- layoutStore.toggleSidebar(e.target.checked)}
- />
-
- {/* Render sidebar after chatview to prevent z-index problem */}
+
+
diff --git a/src/store/layout.ts b/src/store/layout.ts
index 675905f..52574ff 100644
--- a/src/store/layout.ts
+++ b/src/store/layout.ts
@@ -4,16 +4,18 @@ import { create } from "zustand";
// reference: https://tailwindcss.com/docs/responsive-design
export enum ResponsiveWidth {
sm = 640,
- lg = 1024,
}
interface LayoutState {
showSidebar: boolean;
+ isMobileView: boolean;
toggleSidebar: (show?: boolean) => void;
+ setIsMobileView: (value: boolean) => void;
}
export const useLayoutStore = create()((set) => ({
showSidebar: true,
+ isMobileView: false,
toggleSidebar: (show) => {
if (isUndefined(show)) {
set((state) => ({
@@ -27,4 +29,10 @@ export const useLayoutStore = create()((set) => ({
}));
}
},
+ setIsMobileView: (value) => {
+ set((state) => ({
+ ...state,
+ isMobileView: value,
+ }));
+ },
}));