fix(web): prevent composer controls overlap on narrow windows (make plan sidebar responsive) (#1198)
This commit is contained in:
1 parent
3e07f5a6a4
commit
19d47408a5
5 files changed
+75
-40
No files matched your search
@@ -92,6 +92,8 @@ import { useTheme } from "../hooks/useTheme";
|
||||
import { useTurnDiffSummaries } from "../hooks/useTurnDiffSummaries";
|
||||
import { useCommandPaletteStore } from "../commandPaletteStore";
|
||||
import { buildTemporaryWorktreeBranchName } from "@t3tools/shared/git";
|
||||
import { useMediaQuery } from "../hooks/useMediaQuery";
|
||||
import { RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY } from "../rightPanelLayout";
|
||||
import { BranchToolbar } from "./BranchToolbar";
|
||||
import { resolveShortcutCommand, shortcutLabelForCommand } from "../keybindings";
|
||||
import PlanSidebar from "./PlanSidebar";
|
||||
@@ -171,6 +173,7 @@ import {
|
||||
} from "~/rpc/serverState";
|
||||
import { sanitizeThreadErrorMessage } from "~/rpc/transportError";
|
||||
import { retainThreadDetailSubscription } from "../environments/runtime/service";
|
||||
import { RightPanelSheet } from "./RightPanelSheet";
|
||||
|
||||
const IMAGE_ONLY_BOOTSTRAP_PROMPT =
|
||||
"[User attached one or more images without additional text. Respond using the conversation context and the attached image(s).]";
|
||||
@@ -675,6 +678,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
const [pendingUserInputQuestionIndexByRequestId, setPendingUserInputQuestionIndexByRequestId] =
|
||||
useState<Record<string, number>>({});
|
||||
const [planSidebarOpen, setPlanSidebarOpen] = useState(false);
|
||||
const shouldUsePlanSidebarSheet = useMediaQuery(RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY);
|
||||
// Tracks whether the user explicitly dismissed the sidebar for the active turn.
|
||||
const planSidebarDismissedForTurnRef = useRef<string | null>(null);
|
||||
// When set, the thread-change reset effect will open the sidebar instead of closing it.
|
||||
@@ -1897,6 +1901,11 @@ export default function ChatView(props: ChatViewProps) {
|
||||
return !open;
|
||||
});
|
||||
}, [activePlan?.turnId, sidebarProposedPlan?.turnId]);
|
||||
const closePlanSidebar = useCallback(() => {
|
||||
setPlanSidebarOpen(false);
|
||||
planSidebarDismissedForTurnRef.current =
|
||||
activePlan?.turnId ?? sidebarProposedPlan?.turnId ?? "__dismissed__";
|
||||
}, [activePlan?.turnId, sidebarProposedPlan?.turnId]);
|
||||
|
||||
const persistThreadSettingsForNextTurn = useCallback(
|
||||
async (input: {
|
||||
@@ -3394,7 +3403,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
{/* end chat column */}
|
||||
|
||||
{/* Plan sidebar */}
|
||||
{planSidebarOpen ? (
|
||||
{planSidebarOpen && !shouldUsePlanSidebarSheet ? (
|
||||
<PlanSidebar
|
||||
activePlan={activePlan}
|
||||
activeProposedPlan={sidebarProposedPlan}
|
||||
@@ -3403,12 +3412,8 @@ export default function ChatView(props: ChatViewProps) {
|
||||
markdownCwd={gitCwd ?? undefined}
|
||||
workspaceRoot={activeWorkspaceRoot}
|
||||
timestampFormat={timestampFormat}
|
||||
onClose={() => {
|
||||
setPlanSidebarOpen(false);
|
||||
// Track that the user explicitly dismissed for this turn so auto-open won't fight them.
|
||||
planSidebarDismissedForTurnRef.current =
|
||||
activePlan?.turnId ?? sidebarProposedPlan?.turnId ?? "__dismissed__";
|
||||
}}
|
||||
mode="sidebar"
|
||||
onClose={closePlanSidebar}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
@@ -3430,6 +3435,21 @@ export default function ChatView(props: ChatViewProps) {
|
||||
onAddTerminalContext={addTerminalContextToDraft}
|
||||
/>
|
||||
))}
|
||||
{shouldUsePlanSidebarSheet ? (
|
||||
<RightPanelSheet open={planSidebarOpen} onClose={closePlanSidebar}>
|
||||
<PlanSidebar
|
||||
activePlan={activePlan}
|
||||
activeProposedPlan={sidebarProposedPlan}
|
||||
label={planSidebarLabel}
|
||||
environmentId={environmentId}
|
||||
markdownCwd={gitCwd ?? undefined}
|
||||
workspaceRoot={activeWorkspaceRoot}
|
||||
timestampFormat={timestampFormat}
|
||||
mode="sheet"
|
||||
onClose={closePlanSidebar}
|
||||
/>
|
||||
</RightPanelSheet>
|
||||
) : null}
|
||||
|
||||
{expandedImage && (
|
||||
<ExpandedImageDialog preview={expandedImage} onClose={closeExpandedImage} />
|
||||
|
||||
@@ -59,6 +59,7 @@ interface PlanSidebarProps {
|
||||
markdownCwd: string | undefined;
|
||||
workspaceRoot: string | undefined;
|
||||
timestampFormat: TimestampFormat;
|
||||
mode?: "sheet" | "sidebar";
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
@@ -70,6 +71,7 @@ const PlanSidebar = memo(function PlanSidebar({
|
||||
markdownCwd,
|
||||
workspaceRoot,
|
||||
timestampFormat,
|
||||
mode = "sidebar",
|
||||
onClose,
|
||||
}: PlanSidebarProps) {
|
||||
const [proposedPlanExpanded, setProposedPlanExpanded] = useState(false);
|
||||
@@ -123,7 +125,14 @@ const PlanSidebar = memo(function PlanSidebar({
|
||||
}, [environmentId, planMarkdown, workspaceRoot]);
|
||||
|
||||
return (
|
||||
<div className="flex h-full w-[340px] shrink-0 flex-col border-l border-border/70 bg-card/50">
|
||||
<div
|
||||
className={cn(
|
||||
"flex min-h-0 flex-col bg-card/50",
|
||||
mode === "sidebar"
|
||||
? "h-full w-[340px] shrink-0 border-l border-border/70"
|
||||
: "h-full w-full",
|
||||
)}
|
||||
>
|
||||
{/* Header */}
|
||||
<div className="flex h-12 shrink-0 items-center justify-between border-b border-border/60 px-3">
|
||||
<div className="flex items-center gap-2">
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { type ReactNode } from "react";
|
||||
|
||||
import { RIGHT_PANEL_SHEET_CLASS_NAME } from "../rightPanelLayout";
|
||||
import { Sheet, SheetPopup } from "./ui/sheet";
|
||||
|
||||
export function RightPanelSheet(props: {
|
||||
children: ReactNode;
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
return (
|
||||
<Sheet
|
||||
open={props.open}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) {
|
||||
props.onClose();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<SheetPopup
|
||||
side="right"
|
||||
showCloseButton={false}
|
||||
keepMounted
|
||||
className={RIGHT_PANEL_SHEET_CLASS_NAME}
|
||||
>
|
||||
{props.children}
|
||||
</SheetPopup>
|
||||
</Sheet>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export const RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY = "(max-width: 1180px)";
|
||||
export const RIGHT_PANEL_SHEET_CLASS_NAME = "w-[min(88vw,820px)] max-w-[820px] p-0";
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createFileRoute, retainSearchParams, useNavigate } from "@tanstack/react-router";
|
||||
import { Suspense, lazy, type ReactNode, useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { Suspense, lazy, useCallback, useEffect, useMemo, useState } from "react";
|
||||
|
||||
import ChatView from "../components/ChatView";
|
||||
import { threadHasStarted } from "../components/ChatView.logic";
|
||||
@@ -17,45 +17,19 @@ import {
|
||||
stripDiffSearchParams,
|
||||
} from "../diffRouteSearch";
|
||||
import { useMediaQuery } from "../hooks/useMediaQuery";
|
||||
import { RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY } from "../rightPanelLayout";
|
||||
import { selectEnvironmentState, selectThreadExistsByRef, useStore } from "../store";
|
||||
import { createThreadSelectorByRef } from "../storeSelectors";
|
||||
import { resolveThreadRouteRef, buildThreadRouteParams } from "../threadRoutes";
|
||||
import { Sheet, SheetPopup } from "../components/ui/sheet";
|
||||
import { RightPanelSheet } from "../components/RightPanelSheet";
|
||||
import { Sidebar, SidebarInset, SidebarProvider, SidebarRail } from "~/components/ui/sidebar";
|
||||
|
||||
const DiffPanel = lazy(() => import("../components/DiffPanel"));
|
||||
const DIFF_INLINE_LAYOUT_MEDIA_QUERY = "(max-width: 1180px)";
|
||||
const DIFF_INLINE_SIDEBAR_WIDTH_STORAGE_KEY = "chat_diff_sidebar_width";
|
||||
const DIFF_INLINE_DEFAULT_WIDTH = "clamp(28rem,48vw,44rem)";
|
||||
const DIFF_INLINE_SIDEBAR_MIN_WIDTH = 26 * 16;
|
||||
const COMPOSER_COMPACT_MIN_LEFT_CONTROLS_WIDTH_PX = 208;
|
||||
|
||||
const DiffPanelSheet = (props: {
|
||||
children: ReactNode;
|
||||
diffOpen: boolean;
|
||||
onCloseDiff: () => void;
|
||||
}) => {
|
||||
return (
|
||||
<Sheet
|
||||
open={props.diffOpen}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) {
|
||||
props.onCloseDiff();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<SheetPopup
|
||||
side="right"
|
||||
showCloseButton={false}
|
||||
keepMounted
|
||||
className="w-[min(88vw,820px)] max-w-[820px] p-0"
|
||||
>
|
||||
{props.children}
|
||||
</SheetPopup>
|
||||
</Sheet>
|
||||
);
|
||||
};
|
||||
|
||||
const DiffLoadingFallback = (props: { mode: DiffPanelMode }) => {
|
||||
return (
|
||||
<DiffPanelShell mode={props.mode} header={<DiffPanelHeaderSkeleton />}>
|
||||
@@ -192,7 +166,7 @@ function ChatThreadRouteView() {
|
||||
const serverThreadStarted = threadHasStarted(serverThread);
|
||||
const environmentHasAnyThreads = environmentHasServerThreads || environmentHasDraftThreads;
|
||||
const diffOpen = search.diff === "1";
|
||||
const shouldUseDiffSheet = useMediaQuery(DIFF_INLINE_LAYOUT_MEDIA_QUERY);
|
||||
const shouldUseDiffSheet = useMediaQuery(RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY);
|
||||
const currentThreadKey = threadRef ? `${threadRef.environmentId}:${threadRef.threadId}` : null;
|
||||
const [diffPanelMountState, setDiffPanelMountState] = useState(() => ({
|
||||
threadKey: currentThreadKey,
|
||||
@@ -293,9 +267,9 @@ function ChatThreadRouteView() {
|
||||
routeKind="server"
|
||||
/>
|
||||
</SidebarInset>
|
||||
<DiffPanelSheet diffOpen={diffOpen} onCloseDiff={closeDiff}>
|
||||
<RightPanelSheet open={diffOpen} onClose={closeDiff}>
|
||||
{shouldRenderDiffContent ? <LazyDiffPanel mode="sheet" /> : null}
|
||||
</DiffPanelSheet>
|
||||
</RightPanelSheet>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user