diff --git a/src/components/AppLayout.tsx b/src/components/AppLayout.tsx index 74d39325..223b777c 100644 --- a/src/components/AppLayout.tsx +++ b/src/components/AppLayout.tsx @@ -27,14 +27,7 @@ export function AppLayout({ const navigate = useNavigate(); const isMobile = useIsMobile(); - const [isSidebarVisible, setIsSidebarVisible] = useState(() => { - // On mobile, always start hidden - if (typeof window !== 'undefined' && window.innerWidth < 768) { - return false; - } - // On desktop, we'll set the initial state after projects load - return false; // Default to closed initially - }); + const [isSidebarVisible, setIsSidebarVisible] = useState(!isMobile); // Track if we've set the initial state based on projects const [hasSetInitialState, setHasSetInitialState] = useState(false); diff --git a/src/components/SettingsLayout.tsx b/src/components/SettingsLayout.tsx index 67164694..8762ace4 100644 --- a/src/components/SettingsLayout.tsx +++ b/src/components/SettingsLayout.tsx @@ -48,13 +48,7 @@ export function SettingsLayout() { const projectsManager = useProjectsManager(); const [_projects, setProjects] = useState([]); - const [isSidebarVisible, setIsSidebarVisible] = useState(() => { - // On mobile, always start hidden - if (typeof window !== 'undefined' && window.innerWidth < 768) { - return false; - } - return false; // Default to closed initially - }); + const [isSidebarVisible, setIsSidebarVisible] = useState(!isMobile); const [hasSetInitialState, setHasSetInitialState] = useState(false); const loadProjects = useCallback(async () => { diff --git a/src/hooks/useIsMobile.tsx b/src/hooks/useIsMobile.tsx index 2b0fe1df..0fae2179 100644 --- a/src/hooks/useIsMobile.tsx +++ b/src/hooks/useIsMobile.tsx @@ -1,19 +1,19 @@ -import * as React from "react" +import { useEffect, useState } from "react" -const MOBILE_BREAKPOINT = 768 +const MOBILE_BREAKPOINT = 768; -export function useIsMobile() { - const [isMobile, setIsMobile] = React.useState(undefined) +export function useIsMobile(): boolean { + const [isMobile, setIsMobile] = useState(window.innerWidth < MOBILE_BREAKPOINT); - React.useEffect(() => { - const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`) + useEffect(() => { + const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`); const onChange = () => { - setIsMobile(window.innerWidth < MOBILE_BREAKPOINT) + setIsMobile(window.innerWidth < MOBILE_BREAKPOINT); } - mql.addEventListener("change", onChange) - setIsMobile(window.innerWidth < MOBILE_BREAKPOINT) - return () => mql.removeEventListener("change", onChange) - }, []) + mql.addEventListener("change", onChange); + setIsMobile(window.innerWidth < MOBILE_BREAKPOINT); + return () => mql.removeEventListener("change", onChange); + }, []); - return !!isMobile + return !!isMobile; } diff --git a/src/pages/ProjectView.tsx b/src/pages/ProjectView.tsx index ac5ce99e..2561832e 100644 --- a/src/pages/ProjectView.tsx +++ b/src/pages/ProjectView.tsx @@ -39,17 +39,11 @@ export function ProjectView() { const chatPaneRef = useRef(null); const navigate = useNavigate(); const isMobile = useIsMobile(); - const { fs: browserFS } = useFS(); + const { fs } = useFS(); const { user } = useCurrentUser(); const { config } = useAppContext(); const { toast } = useToast(); - const [isSidebarVisible, setIsSidebarVisible] = useState(() => { - // Check if we're on mobile immediately to set correct initial state - if (typeof window !== 'undefined') { - return window.innerWidth >= 768; // Desktop starts open, mobile starts closed - } - return false; // Default to closed for SSR - }); + const [isSidebarVisible, setIsSidebarVisible] = useState(!isMobile); // Keep-alive functionality to prevent tab throttling during AI processing const { updateMetadata } = useKeepAlive({ @@ -83,14 +77,14 @@ export function ProjectView() { }, [loadProject]); const runBuild = async () => { - if (isBuildLoading || !project || !browserFS) return; + if (isBuildLoading || !project) return; setIsBuildLoading(true); updateMetadata('Shakespeare', `Building ${project.name}...`); try { const result = await buildProject({ - fs: browserFS, + fs, projectPath: `/projects/${project.id}`, domParser: new DOMParser(), }); @@ -104,7 +98,7 @@ export function ProjectView() { }; const runDeploy = async () => { - if (isDeployLoading || !project || !browserFS) return; + if (isDeployLoading || !project) return; // Check if user is logged in if (!user || !user.signer) { @@ -123,7 +117,7 @@ export function ProjectView() { const result = await deployProject({ projectId: project.id, deployServer: config.deployServer, - fs: browserFS, + fs, projectPath: `/projects/${project.id}`, signer: user.signer, });