@@ -65,12 +65,12 @@ import type { ChatMessagePart } from "#/api/typesGenerated";
6565import { useProxy } from "#/contexts/ProxyContext" ;
6666import { useAuthenticated } from "#/hooks/useAuthenticated" ;
6767import { useAIGatewayEnabled } from "#/hooks/useEmbeddedMetadata" ;
68- import { useIsBelowLgViewport } from "#/hooks/useIsBelowLgViewport " ;
68+ import { useMediaQuery } from "#/hooks/useMediaQuery " ;
6969import {
7070 getDefaultOrganizationName ,
7171 useDashboard ,
7272} from "#/modules/dashboard/useDashboard" ;
73- import { isMobileViewport } from "#/utils/mobile" ;
73+ import { belowLgViewportMediaQuery , isMobileViewport } from "#/utils/mobile" ;
7474import { pageTitle } from "#/utils/page" ;
7575import { rewriteLocalhostURL } from "#/utils/portForward" ;
7676import { createReconnectingWebSocket } from "#/utils/reconnectingWebSocket" ;
@@ -134,29 +134,6 @@ import {
134134/** localStorage key controlling whether the right panel is visible. */
135135export const RIGHT_PANEL_OPEN_KEY = "agents.right-panel-open" ;
136136
137- /**
138- * Below the `lg` breakpoint, chat and the right panel are mutually
139- * exclusive, so a panel left open on a wide window would hide chat as
140- * soon as the window narrows. This suppresses the panel while narrow
141- * without touching the persisted preference: widening restores the
142- * panel, and an explicit user action (clearSuppression) overrides it.
143- */
144- export function useRightPanelNarrowSuppression ( ) : {
145- suppressed : boolean ;
146- clearSuppression : ( ) => void ;
147- } {
148- const isBelowLg = useIsBelowLgViewport ( ) ;
149- const [ suppressed , setSuppressed ] = useState ( isBelowLg ) ;
150- const [ prevIsBelowLg , setPrevIsBelowLg ] = useState ( isBelowLg ) ;
151- // Render-time state adjustment on breakpoint crossings; see
152- // https://react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes
153- if ( isBelowLg !== prevIsBelowLg ) {
154- setPrevIsBelowLg ( isBelowLg ) ;
155- setSuppressed ( isBelowLg ) ;
156- }
157- return { suppressed, clearSuppression : ( ) => setSuppressed ( false ) } ;
158- }
159-
160137const lastModelConfigIDStorageKey = "agents.last-model-config-id" ;
161138
162139const AGENT_BINDING_REPAIR_POLL_MS = 30_000 ;
@@ -886,15 +863,28 @@ const AgentChatPage: FC = () => {
886863 const [ sidebarPanelPreference , setSidebarPanelPreference ] = useState ( ( ) => {
887864 return localStorage . getItem ( RIGHT_PANEL_OPEN_KEY ) === "true" ;
888865 } ) ;
889- const { suppressed : panelSuppressedOnNarrow , clearSuppression } =
890- useRightPanelNarrowSuppression ( ) ;
866+ // Below the lg breakpoint, chat and the right panel are mutually
867+ // exclusive, so a panel left open on a wide window would hide chat
868+ // as soon as the window narrows. Suppression hides the panel while
869+ // narrow without touching the persisted preference: widening
870+ // restores the panel, and an explicit toggle overrides it.
871+ const isBelowLg = useMediaQuery ( belowLgViewportMediaQuery ) ;
872+ const [ panelSuppressedOnNarrow , setPanelSuppressedOnNarrow ] =
873+ useState ( isBelowLg ) ;
874+ const [ prevIsBelowLg , setPrevIsBelowLg ] = useState ( isBelowLg ) ;
875+ // Render-time state adjustment on breakpoint crossings; see
876+ // https://react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes
877+ if ( isBelowLg !== prevIsBelowLg ) {
878+ setPrevIsBelowLg ( isBelowLg ) ;
879+ setPanelSuppressedOnNarrow ( isBelowLg ) ;
880+ }
891881 // Canonical panel visibility: the persisted preference gated by the
892882 // narrow-viewport suppression. Only this derived value may be
893883 // rendered or handed to children; the raw preference stays local.
894884 const showSidebarPanel = sidebarPanelPreference && ! panelSuppressedOnNarrow ;
895885
896886 const handleSetShowSidebarPanel = ( next : boolean ) => {
897- clearSuppression ( ) ;
887+ setPanelSuppressedOnNarrow ( false ) ;
898888 setSidebarPanelPreference ( next ) ;
899889 localStorage . setItem ( RIGHT_PANEL_OPEN_KEY , String ( next ) ) ;
900890 } ;
0 commit comments