Skip to content

Commit 605c74b

Browse files
Improve mobile chat layout and add responsive sidebar primitives
- add reusable `ui/sidebar` and `ui/tooltip` components for responsive navigation - optimize chat header/composer spacing and mobile-safe touch targets - add sidebar trigger in chat header and hide desktop-only controls on small screens - make session hydration reconnects silent to reduce unnecessary connecting state flicker
1 parent 2880ef8 commit 605c74b

10 files changed

Lines changed: 964 additions & 69 deletions

File tree

‎apps/web/src/components/BranchToolbar.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export default function BranchToolbar({
182182
if (!activeThread || !activeProject) return null;
183183

184184
return (
185-
<div className="mx-auto flex w-full max-w-3xl items-center justify-between px-5 pb-3 pt-1">
185+
<div className="mx-auto flex w-full max-w-3xl items-center justify-between px-3 pb-[calc(0.75rem+env(safe-area-inset-bottom))] pt-1 sm:px-5 sm:pb-3">
186186
<div className="flex items-center gap-2">
187187
{envLocked || activeWorktreePath ? (
188188
<span className="border border-transparent px-[calc(--spacing(2)-1px)] text-sm font-medium text-muted-foreground/70 sm:text-xs">

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 93 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ import {
119119
setupProjectScript,
120120
} from "~/projectScripts";
121121
import { Toggle } from "./ui/toggle";
122+
import { SidebarTrigger } from "./ui/sidebar";
122123

123124
function formatMessageMeta(createdAt: string, duration: string | null): string {
124125
if (!duration) return formatTimestamp(createdAt);
@@ -433,6 +434,12 @@ export default function ChatView({ threadId }: ChatViewProps) {
433434
);
434435
const phase = derivePhase(activeThread?.session ?? null);
435436
const isWorking = phase === "running" || isSending || isConnecting || isRevertingCheckpoint;
437+
const canSend =
438+
Boolean(api) &&
439+
Boolean(activeThread) &&
440+
!isSending &&
441+
!isConnecting &&
442+
(prompt.trim().length > 0 || composerImages.length > 0);
436443
const nowIso = new Date(nowTick).toISOString();
437444
const workLogEntries = useMemo(
438445
() => deriveWorkLogEntries(activeThread?.events ?? [], undefined),
@@ -1583,7 +1590,12 @@ export default function ChatView({ threadId }: ChatViewProps) {
15831590
);
15841591

15851592
const ensureSession = useCallback(
1586-
async (cwdOverride?: string): Promise<EnsuredSessionInfo | null> => {
1593+
async (
1594+
cwdOverride?: string,
1595+
options?: {
1596+
silent?: boolean;
1597+
},
1598+
): Promise<EnsuredSessionInfo | null> => {
15871599
if (!api || !activeThread || !activeProject) return null;
15881600
if (activeThread.session && activeThread.session.status !== "closed") {
15891601
const sessionThreadId = activeThread.session.threadId ?? null;
@@ -1606,7 +1618,10 @@ export default function ChatView({ threadId }: ChatViewProps) {
16061618
}
16071619

16081620
const priorCodexThreadId = activeThread.codexThreadId;
1609-
setIsConnecting(true);
1621+
const shouldShowConnectingState = !options?.silent;
1622+
if (shouldShowConnectingState) {
1623+
setIsConnecting(true);
1624+
}
16101625
try {
16111626
const session = await api.providers.startSession({
16121627
provider: "codex",
@@ -1649,7 +1664,9 @@ export default function ChatView({ threadId }: ChatViewProps) {
16491664
});
16501665
return null;
16511666
} finally {
1652-
setIsConnecting(false);
1667+
if (shouldShowConnectingState) {
1668+
setIsConnecting(false);
1669+
}
16531670
}
16541671
},
16551672
[
@@ -1679,7 +1696,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
16791696
}
16801697
checkpointHydrationSessionRequestRef.current.add(requestKey);
16811698
setThreadError(activeThreadId, null);
1682-
void ensureSession().then(
1699+
void ensureSession(undefined, { silent: true }).then(
16831700
() => {
16841701
checkpointHydrationSessionRequestRef.current.delete(requestKey);
16851702
},
@@ -1904,6 +1921,24 @@ export default function ChatView({ threadId }: ChatViewProps) {
19041921
}
19051922
};
19061923

1924+
const triggerSend = () => {
1925+
if (!canSend) return;
1926+
const form = textareaRef.current?.form;
1927+
if (form) {
1928+
if (typeof form.requestSubmit === "function") {
1929+
form.requestSubmit();
1930+
} else {
1931+
const submitEvent = new Event("submit", { bubbles: true, cancelable: true });
1932+
const dispatched = form.dispatchEvent(submitEvent);
1933+
if (!dispatched) {
1934+
return;
1935+
}
1936+
}
1937+
return;
1938+
}
1939+
void onSend({ preventDefault: () => undefined } as FormEvent);
1940+
};
1941+
19071942
const onInterrupt = async () => {
19081943
if (!api || !activeThread?.session) return;
19091944
await api.providers.interruptTurn({
@@ -2047,7 +2082,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
20472082

20482083
if (e.key === "Enter" && !e.shiftKey) {
20492084
e.preventDefault();
2050-
void onSend(e as unknown as FormEvent);
2085+
triggerSend();
20512086
}
20522087
};
20532088
const onToggleWorkGroup = useCallback((groupId: string) => {
@@ -2117,7 +2152,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
21172152
<div className="flex min-h-0 min-w-0 flex-1 flex-col bg-background">
21182153
{/* Top bar */}
21192154
<header
2120-
className={`flex items-center justify-between border-b border-border px-5 ${isElectron ? "drag-region h-[52px]" : "py-3"}`}
2155+
className={`flex items-center justify-between border-b border-border px-3 sm:px-5 ${isElectron ? "drag-region h-[52px]" : "py-3"}`}
21212156
>
21222157
<ChatHeader
21232158
activeThreadId={activeThread.id}
@@ -2151,7 +2186,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
21512186
{/* Messages */}
21522187
<div
21532188
ref={messagesScrollRef}
2154-
className="min-h-0 flex-1 overflow-y-auto px-5 py-4"
2189+
className="min-h-0 flex-1 overflow-y-auto px-3 py-3 sm:px-5 sm:py-4"
21552190
onScroll={onMessagesScroll}
21562191
>
21572192
<MessagesTimeline
@@ -2176,7 +2211,12 @@ export default function ChatView({ threadId }: ChatViewProps) {
21762211
</div>
21772212

21782213
{/* Input bar */}
2179-
<div className={cn("px-5 pt-2", isGitRepo ? "pb-1" : "pb-4")}>
2214+
<div
2215+
className={cn(
2216+
"px-3 pt-2 sm:px-5 max-sm:pb-[calc(0.5rem+env(safe-area-inset-bottom))]",
2217+
isGitRepo ? "pb-1" : "pb-4",
2218+
)}
2219+
>
21802220
<form onSubmit={onSend} className="mx-auto max-w-3xl">
21812221
<div
21822222
className={`group rounded-[20px] border bg-card transition-colors duration-200 focus-within:border-ring ${
@@ -2275,8 +2315,8 @@ export default function ChatView({ threadId }: ChatViewProps) {
22752315
</div>
22762316

22772317
{/* Bottom toolbar */}
2278-
<div className="flex items-center justify-between px-3 pb-3">
2279-
<div className="flex items-center gap-1">
2318+
<div className="flex items-center justify-end px-3 pb-3 sm:justify-between">
2319+
<div className="hidden items-center gap-1 sm:flex">
22802320
{/* Model picker */}
22812321
<ModelPicker model={selectedModel} onModelChange={onModelSelect} />
22822322

@@ -2317,7 +2357,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
23172357
{phase === "running" ? (
23182358
<button
23192359
type="button"
2320-
className="flex h-8 w-8 items-center justify-center rounded-full bg-rose-500/90 text-white transition-all duration-150 hover:bg-rose-500 hover:scale-105"
2360+
className="relative z-10 flex h-10 w-10 touch-manipulation items-center justify-center rounded-full bg-rose-500/90 text-white transition-all duration-150 hover:bg-rose-500 pointer-events-auto sm:h-8 sm:w-8 sm:hover:scale-105"
23212361
onClick={() => void onInterrupt()}
23222362
aria-label="Stop generation"
23232363
>
@@ -2333,11 +2373,10 @@ export default function ChatView({ threadId }: ChatViewProps) {
23332373
</button>
23342374
) : (
23352375
<button
2336-
type="submit"
2337-
className="flex h-8 w-8 items-center justify-center rounded-full bg-primary/90 text-primary-foreground transition-all duration-150 hover:bg-primary hover:scale-105 disabled:opacity-30 disabled:hover:scale-100"
2338-
disabled={
2339-
isSending || isConnecting || (!prompt.trim() && composerImages.length === 0)
2340-
}
2376+
type="button"
2377+
className="relative z-10 flex h-10 w-10 touch-manipulation items-center justify-center rounded-full bg-primary/90 text-primary-foreground transition-all duration-150 hover:bg-primary pointer-events-auto disabled:opacity-30 disabled:hover:scale-100 sm:h-8 sm:w-8 sm:hover:scale-105"
2378+
disabled={!canSend}
2379+
onClick={triggerSend}
23412380
aria-label={
23422381
isConnecting ? "Connecting" : isSending ? "Sending" : "Send message"
23432382
}
@@ -2387,13 +2426,15 @@ export default function ChatView({ threadId }: ChatViewProps) {
23872426
</div>
23882427

23892428
{isGitRepo && (
2390-
<BranchToolbar
2391-
threadId={activeThread.id}
2392-
envMode={envMode}
2393-
onEnvModeChange={onEnvModeChange}
2394-
envLocked={envLocked}
2395-
onComposerFocusRequest={scheduleComposerFocus}
2396-
/>
2429+
<div className="hidden sm:block">
2430+
<BranchToolbar
2431+
threadId={activeThread.id}
2432+
envMode={envMode}
2433+
onEnvModeChange={onEnvModeChange}
2434+
envLocked={envLocked}
2435+
onComposerFocusRequest={scheduleComposerFocus}
2436+
/>
2437+
</div>
23972438
)}
23982439

23992440
{activeThread.terminalOpen && api && activeProject && (
@@ -2497,28 +2538,43 @@ const ChatHeader = memo(function ChatHeader({
24972538
}: ChatHeaderProps) {
24982539
return (
24992540
<>
2500-
<div className="flex min-w-0 flex-1 items-center gap-3">
2501-
<h2 className="truncate text-sm font-medium text-foreground" title={activeThreadTitle}>
2541+
<div className="flex min-w-0 flex-1 items-center gap-2 sm:gap-3">
2542+
<SidebarTrigger className="size-8 md:hidden" />
2543+
<Separator orientation="vertical" className="md:hidden data-[orientation=vertical]:h-4" />
2544+
<h2
2545+
className="truncate text-xs font-medium text-foreground sm:text-sm"
2546+
title={activeThreadTitle}
2547+
>
25022548
{activeThreadTitle}
25032549
</h2>
2504-
{activeProjectName && <Badge variant="outline">{activeProjectName}</Badge>}
2550+
{activeProjectName && (
2551+
<Badge variant="outline" className="hidden sm:inline-flex">
2552+
{activeProjectName}
2553+
</Badge>
2554+
)}
25052555
</div>
2506-
<div className="shrink-0 flex items-center gap-3">
2556+
<div className="shrink-0 flex items-center gap-1.5 sm:gap-3">
25072557
{activeProjectScripts && (
2508-
<ProjectScriptsControl
2509-
scripts={activeProjectScripts}
2510-
keybindings={keybindings}
2511-
preferredScriptId={preferredScriptId}
2512-
onRunScript={onRunProjectScript}
2513-
onAddScript={onAddProjectScript}
2514-
onUpdateScript={onUpdateProjectScript}
2515-
/>
2558+
<div className="hidden md:block">
2559+
<ProjectScriptsControl
2560+
scripts={activeProjectScripts}
2561+
keybindings={keybindings}
2562+
preferredScriptId={preferredScriptId}
2563+
onRunScript={onRunProjectScript}
2564+
onAddScript={onAddProjectScript}
2565+
onUpdateScript={onUpdateProjectScript}
2566+
/>
2567+
</div>
25162568
)}
25172569
{activeProjectName && (
2518-
<OpenInPicker keybindings={keybindings} activeThreadId={activeThreadId} />
2570+
<div className="hidden md:block">
2571+
<OpenInPicker keybindings={keybindings} activeThreadId={activeThreadId} />
2572+
</div>
25192573
)}
25202574
{activeProjectName && (
2521-
<GitActionsControl api={api} gitCwd={gitCwd} activeThreadId={activeThreadId} />
2575+
<div className="hidden md:block">
2576+
<GitActionsControl api={api} gitCwd={gitCwd} activeThreadId={activeThreadId} />
2577+
</div>
25222578
)}
25232579
<Toggle
25242580
pressed={diffOpen}

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ function terminalStatusIndicator(thread: Thread): TerminalStatusIndicator | null
112112
};
113113
}
114114

115-
export default function Sidebar() {
115+
interface SidebarProps {
116+
embedded?: boolean;
117+
}
118+
119+
export default function Sidebar({ embedded = false }: SidebarProps = {}) {
116120
const { state, dispatch } = useStore();
117121
const api = useNativeApi();
118122
const navigate = useNavigate();
@@ -497,8 +501,12 @@ export default function Sidebar() {
497501
};
498502
}, [handleNewThread, keybindings, routeThreadId, state.projects, state.threads]);
499503

504+
const rootClassName = embedded
505+
? "sidebar flex h-full min-h-0 flex-col bg-card"
506+
: "sidebar flex h-full w-[260px] shrink-0 flex-col border-r border-border bg-card max-sm:w-[36vw] max-sm:min-w-[140px] max-sm:max-w-[200px]";
507+
500508
return (
501-
<aside className="sidebar flex h-full w-[260px] shrink-0 flex-col border-r border-border bg-card">
509+
<aside className={rootClassName}>
502510
{/* Branding */}
503511
<div
504512
className={`flex items-center gap-2.5 px-4 ${isElectron ? "drag-region h-[52px] pl-[76px]" : "py-4"}`}
@@ -507,7 +515,7 @@ export default function Sidebar() {
507515
<span className="truncate text-sm font-semibold tracking-tight text-foreground">
508516
T3 <span className="font-normal text-muted-foreground">Code</span>
509517
</span>
510-
<span className="rounded-full bg-muted/50 px-1.5 py-0.5 text-[9px] font-medium uppercase tracking-widest text-muted-foreground/60">
518+
<span className="hidden rounded-full bg-muted/50 px-1.5 py-0.5 text-[9px] font-medium uppercase tracking-widest text-muted-foreground/60 sm:inline-block">
511519
{APP_STAGE_LABEL}
512520
</span>
513521
</div>
@@ -563,7 +571,9 @@ export default function Sidebar() {
563571
<span className="flex-1 truncate text-xs font-medium text-foreground/90">
564572
{project.name}
565573
</span>
566-
<span className="text-[10px] text-muted-foreground/60">{threads.length}</span>
574+
<span className="hidden text-[10px] text-muted-foreground/60 sm:inline">
575+
{threads.length}
576+
</span>
567577
</button>
568578

569579
{/* Threads */}
@@ -627,7 +637,7 @@ export default function Sidebar() {
627637
/>
628638
</span>
629639
)}
630-
<span className="text-[10px] text-muted-foreground/40">
640+
<span className="hidden text-[10px] text-muted-foreground/40 sm:inline">
631641
{formatRelativeTime(thread.createdAt)}
632642
</span>
633643
</div>

0 commit comments

Comments
 (0)