Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
wait until we read the setting from local storage
Oleg Isonen347630110ef8
diff --git a/apps/designer/app/designer/designer.tsx b/apps/designer/app/designer/designer.tsxindex dfb5a0b616..290c935224 100644--- a/apps/designer/app/designer/designer.tsx+++ b/apps/designer/app/designer/designer.tsx@@ -1,5 +1,9 @@import { useCallback } from "react";-import { useSubscribe, usePublish } from "@webstudio-is/react-sdk";+import {+ useSubscribe,+ usePublish,+ type Publish,+} from "@webstudio-is/react-sdk";import { type Project, type Asset } from "@webstudio-is/prisma-client";import type { Config } from "~/config";import type {@@ -68,6 +72,13 @@ const useSubscribeSyncStatus = () => {useSubscribe<"syncStatus", SyncStatus>("syncStatus", setValue);};+const useNavigatorLayout = () => {+ // We need to render the detached state only once the setting was actually loaded from local storage.+ // Otherwise we may show the detached state because its the default and then hide it immediately.+ const [clientSettings, _, isLoaded] = useClientSettings();+ return isLoaded ? clientSettings.navigatorLayout : "attached";+};+type SidePanelProps = {children: JSX.Element | Array<JSX.Element>;isPreviewMode: boolean;@@ -126,6 +137,8 @@ type ChromeWrapperProps = {isPreviewMode: boolean;};+const PANEL_WIDTH = "240px";+const getChromeLayout = ({isPreviewMode,navigatorLayout,@@ -146,7 +159,7 @@ const getChromeLayout = ({if (navigatorLayout === "detached") {return {- gridTemplateColumns: "auto 240px 1fr 240px",+ gridTemplateColumns: `auto ${PANEL_WIDTH} 1fr ${PANEL_WIDTH}`,gridTemplateAreas: `"header header header header""sidebar navigator main inspector"@@ -156,7 +169,7 @@ const getChromeLayout = ({}return {- gridTemplateColumns: "auto 1fr 240px",+ gridTemplateColumns: `auto 1fr ${PANEL_WIDTH}`,gridTemplateAreas: `"header header header""sidebar main inspector"@@ -166,10 +179,10 @@ const getChromeLayout = ({};const ChromeWrapper = ({ children, isPreviewMode }: ChromeWrapperProps) => {- const [clientSettings] = useClientSettings();+ const navigatorLayout = useNavigatorLayout();const gridLayout = getChromeLayout({isPreviewMode,- navigatorLayout: clientSettings.navigatorLayout,+ navigatorLayout,});return (@@ -187,6 +200,24 @@ const ChromeWrapper = ({ children, isPreviewMode }: ChromeWrapperProps) => {);};+type NavigatorPanelProps = { publish: Publish; isPreviewMode: boolean };++const NavigatorPanel = ({ publish, isPreviewMode }: NavigatorPanelProps) => {+ const navigatorLayout = useNavigatorLayout();++ if (navigatorLayout === "attached") {+ return null;+ }++ return (+ <SidePanel gridArea="navigator" isPreviewMode={isPreviewMode}>+ <Box css={{ borderRight: "1px solid $slate7", width: PANEL_WIDTH }}>+ <Navigator publish={publish} isClosable={false} />+ </Box>+ </SidePanel>+ );+};+type DesignerProps = {config: Config;project: Project;@@ -205,7 +236,6 @@ export const Designer = ({ config, project, assets }: DesignerProps) => {const onRefReadCanvasWidth = useUpdateCanvasWidth();const { onRef: onRefReadCanvas, onTransitionEnd } = useReadCanvasRect();const [dragAndDropState] = useDragAndDropState();- const [clientSettings] = useClientSettings();const iframeRefCallback = useCallback((ref) => {@@ -245,13 +275,7 @@ export const Designer = ({ config, project, assets }: DesignerProps) => {<SidePanel gridArea="sidebar" isPreviewMode={isPreviewMode}><SidebarLeft assets={assets} publish={publish} /></SidePanel>- {clientSettings.navigatorLayout === "detached" ? (- <SidePanel gridArea="navigator" isPreviewMode={isPreviewMode}>- <Box css={{ borderRight: "1px solid $slate7", width: 240 }}>- <Navigator publish={publish} isClosable={false} />- </Box>- </SidePanel>- ) : null}+ <NavigatorPanel publish={publish} isPreviewMode={isPreviewMode} /><SidePanelgridArea="inspector"isPreviewMode={isPreviewMode}diff --git a/apps/designer/app/designer/shared/client-settings/settings.ts b/apps/designer/app/designer/shared/client-settings/settings.tsindex 98a52786f5..c051c246bf 100644--- a/apps/designer/app/designer/shared/client-settings/settings.ts+++ b/apps/designer/app/designer/shared/client-settings/settings.ts@@ -1,4 +1,4 @@-import { useEffect } from "react";+import { useEffect, useState } from "react";import { createValueContainer, useValue } from "react-nano-state";import { sentryException } from "~/shared/sentry";import * as config from "./config";@@ -68,10 +68,15 @@ export const setSetting = (name: Name, value: Value) => {const settingsContainer = createValueContainer<Settings>(defaultSettings);-export const useClientSettings = (): [Settings, typeof setSetting] => {+export const useClientSettings = (): [Settings, typeof setSetting, boolean] => {const [settings, setSettings] = useValue(settingsContainer);+ // We need to know if the settings were loaded from local storage.+ // E.g. to decide if we should wait till the actual setting is loaded or use the default.+ const [isLoaded, setIsLoaded] = useState(false);+useEffect(() => {setSettings(read());+ setIsLoaded(true);}, [setSettings]);const setSettingValue = (name: Name, value: Value) => {@@ -79,5 +84,5 @@ export const useClientSettings = (): [Settings, typeof setSetting] => {setSettings({ ...settings, [name]: value });setSetting(name, value);};- return [settings, setSettingValue];+ return [settings, setSettingValue, isLoaded];};