Skip to content

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.

feat: Remember the AI bar open state (#2500)

Oleg Isonene902fc25d49b
diff --git a/apps/builder/app/builder/features/ai/ai-command-bar.tsx b/apps/builder/app/builder/features/ai/ai-command-bar.tsx
index ce837cbbe6..2f07172983 100644
--- a/apps/builder/app/builder/features/ai/ai-command-bar.tsx
+++ b/apps/builder/app/builder/features/ai/ai-command-bar.tsx
@@ -1,6 +1,5 @@
/* eslint-disable import/no-internal-modules */
import formatDistance from "date-fns/formatDistance";
-import { useStore } from "@nanostores/react";
import {
AutogrowTextArea,
Box,
@@ -37,7 +36,6 @@ import {
} from "react";
import {
$collaborativeInstanceSelector,
- $isAiCommandBarVisible,
selectedInstanceSelectorStore,
selectedPageStore,
} from "~/shared/nano-states";
@@ -75,15 +73,14 @@ export const AiCommandBar = ({ isPreviewMode }: { isPreviewMode: boolean }) => {
const [prompts, setPrompts] = useState<string[]>(initialPrompts);
const [clientSettings, setClientSetting, isClientSettingsLoaded] =
useClientSettings();
- const open = isClientSettingsLoaded && clientSettings.isAiMenuOpen;
- const setOpen = useEffectEvent((value: boolean) =>
+ const isMenuOpen = isClientSettingsLoaded && clientSettings.isAiMenuOpen;
+ const setIsMenuOpen = useEffectEvent((value: boolean) =>
setClientSetting("isAiMenuOpen", value)
);
const [isAudioTranscribing, setIsAudioTranscribing] = useState(false);
const [isAiRequesting, setIsAiRequesting] = useState(false);
const abortController = useRef<AbortController>();
- const isAiCommandBarVisible = useStore($isAiCommandBarVisible);
const recordButtonRef = useRef<HTMLButtonElement>(null);
const guardIdRef = useRef(0);
const { enableCanvasPointerEvents, disableCanvasPointerEvents } =
@@ -286,7 +283,10 @@ export const AiCommandBar = ({ isPreviewMode }: { isPreviewMode: boolean }) => {
selectPrompt();
};
- if (isAiCommandBarVisible === false) {
+ if (
+ isClientSettingsLoaded === false ||
+ clientSettings.isAiCommandBarVisible === false
+ ) {
return;
}
@@ -364,8 +364,8 @@ export const AiCommandBar = ({ isPreviewMode }: { isPreviewMode: boolean }) => {
}}
>
<CommandBar
- open={open}
- onOpenChange={setOpen}
+ open={isMenuOpen}
+ onOpenChange={setIsMenuOpen}
content={
<CommandBarContent
prompts={prompts}
diff --git a/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx b/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx
index 9d3a9208e9..9b6b5388fd 100644
--- a/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx
+++ b/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx
@@ -8,10 +8,7 @@ import {
Tooltip,
} from "@webstudio-is/design-system";
import { useSubscribe, type Publish } from "~/shared/pubsub";
-import {
- $dragAndDropState,
- $isAiCommandBarVisible,
-} from "~/shared/nano-states";
+import { $dragAndDropState } from "~/shared/nano-states";
import { panels } from "./panels";
import type { TabName } from "./types";
import { useClientSettings } from "~/builder/shared/client-settings";
@@ -32,9 +29,8 @@ export const SidebarLeft = ({ publish }: SidebarLeftProps) => {
const dragAndDropState = useStore($dragAndDropState);
const [activeTab, setActiveTab] = useState<TabName>("none");
const { TabContent } = activeTab === "none" ? none : panels[activeTab];
- const [clientSettings] = useClientSettings();
const [helpIsOpen, setHelpIsOpen] = useState(false);
- const isAiCommandBarVisible = useStore($isAiCommandBarVisible);
+ const [clientSettings, setClientSetting] = useClientSettings();
useSubscribe("clickCanvas", () => {
setActiveTab("none");
@@ -76,7 +72,10 @@ export const SidebarLeft = ({ publish }: SidebarLeftProps) => {
"anyValueNotInTabName" /* !!! This button does not have active state, use impossible tab value !!! */
}
onClick={() => {
- $isAiCommandBarVisible.set(!isAiCommandBarVisible);
+ setClientSetting(
+ "isAiCommandBarVisible",
+ clientSettings.isAiCommandBarVisible === true ? false : true
+ );
}}
>
<AiIcon />
diff --git a/apps/builder/app/builder/shared/client-settings/settings.ts b/apps/builder/app/builder/shared/client-settings/settings.ts
index 800789de1b..2c83b85c35 100644
--- a/apps/builder/app/builder/shared/client-settings/settings.ts
+++ b/apps/builder/app/builder/shared/client-settings/settings.ts
@@ -8,6 +8,7 @@ import { z } from "zod";
export const zSettings = z.object({
navigatorLayout: z.enum(["docked", "undocked"]).default("undocked"),
isAiMenuOpen: z.boolean().default(true),
+ isAiCommandBarVisible: z.boolean().default(true),
});
export type Settings = z.infer<typeof zSettings>;
diff --git a/apps/builder/app/shared/nano-states/nano-states.ts b/apps/builder/app/shared/nano-states/nano-states.ts
index 92d50af3fd..4d8094eb0b 100644
--- a/apps/builder/app/shared/nano-states/nano-states.ts
+++ b/apps/builder/app/shared/nano-states/nano-states.ts
@@ -327,5 +327,3 @@ export type DragAndDropState = {
export const $dragAndDropState = atom<DragAndDropState>({
isDragging: false,
});
-
-export const $isAiCommandBarVisible = atom<boolean>(true);