The tablet ran the phone layout with a half-finished iPad draft on top: two custom sidebars, a leftover overflow menu, split Files/Changes header buttons, and phone-width sheets stretched across a 13" screen. This brings it onto the phone's navigation model and keeps only the differences a large screen earns. - Sessions are a persistent resizable left sidebar; the overflow menu is gone and its destinations moved into that sidebar's footer (connected instance, settings, pending web update) and into the workspace drawer. - The workspace (Changes / Files / Terminal / Notes / MCP) is the phone's drawer everywhere: a resizable right sidebar where the screen can host one (up to 900px) and the full-cover drawer otherwise, with its mounted panes — an open diff, an edited file, an attached terminal — surviving rotation. - Header dropdowns are anchored popovers: the recents switcher mirrors the usage overlay on the left, and its trigger is sized to the title rather than to the free width. - App-level pages (settings, instances, update, an opened plan) render as centered dialogs instead of covering the screen. - Overlays center on the chat column through published insets, so the model and directory pickers no longer sit off-centre; the directory picker also stops overriding the shared width clamp. - Wide chat layout applies to mobile surfaces, where a tablet chat column is finally wide enough for the setting to mean anything. The layout gate is a live size class rather than a device check, so Android tablets and foldables are covered by the same code: - `enabled` when the shortest viewport side is at le sw600dp). The short side is what makes this a size question instead of a device question — a phone reports ~360-430 whichev unfolded book foldable ~600+, and folding shut drops back under it. iPads also answer on identity, since iPadOS hands out od - `roomyForPanels` when landscape and at least 1000px wide, which is what it takes to host the sidebar, the panel and a readabl foldables miss it in BOTH orientations — their long side is barely wider than a tablet's short one — so they keep the portr Every consumer re-decides instead of remembering wha open sidebar closes if the device folds shut under it. iPad behaviour is unchanged: its landscape widths all clear the panel ones do not, exactly as the previous orientation check did. Hardware keyboards are read natively. iOS reports them through GCKeyboard, published to the web layer at document start and kep disconnect and foregrounding; the layer stops inferring once that answers. A single early publish was not enough — the connect no already-attached keyboard fires before the page exists, and GameController can populate late — so the state is re-published across resume. With a keyboard attached the draft screen keeps its starter chips and the composer never collapses; tablets skip the colla Runtimes with no native answer fall back to inferring it from the keyboard bridge, and only ever conclude "hardware" from silen Also: sidebar rows no longer sit on a differently ti footer is no longer clipped by an over-tall content box, the resize handles moved above the panes' own overlays so they can actu now-unreachable overflow menu, fullscreen terminal/MCP/notes surfaces and their locale key are deleted. Device behaviour is unverified — the tablet layout, keyboard bridge and the foldable size class have not been exercised on hardware, and the 600/1000 thresholds are derived fr rather than measured on a foldable.
148 lines
6.3 KiB
TypeScript
148 lines
6.3 KiB
TypeScript
import React from 'react';
|
|
|
|
import { Icon } from '@/components/icon/Icon';
|
|
import { useI18n } from '@/lib/i18n';
|
|
import { cn } from '@/lib/utils';
|
|
import { useDirectoryStore } from '@/stores/useDirectoryStore';
|
|
import { useSessionUIStore } from '@/sync/session-ui-store';
|
|
import { useSession } from '@/sync/sync-context';
|
|
|
|
import { MobileSessionMetadataButton } from './MobileSessionMetadata';
|
|
import { MobileSessionSwitcher } from './MobileSessionSwitcher';
|
|
|
|
export const MobileHeader: React.FC<{
|
|
onOpenSessions: () => void;
|
|
/** Opens the right workspace drawer (Changes / Files / Terminal / Notes / MCP). */
|
|
onOpenWorkspace: () => void;
|
|
/** Tablet: size the title trigger to its text instead of the free width, so
|
|
a wide header doesn't turn the switcher into a full-width tap target. */
|
|
compactTitle?: boolean;
|
|
}> = ({ onOpenSessions, onOpenWorkspace, compactTitle = false }) => {
|
|
const { t } = useI18n();
|
|
const [metadataOpen, setMetadataOpen] = React.useState(false);
|
|
const [switcherOpen, setSwitcherOpen] = React.useState(false);
|
|
const titleRef = React.useRef<HTMLButtonElement>(null);
|
|
const currentDirectory = useDirectoryStore((state) => state.currentDirectory);
|
|
const currentSessionId = useSessionUIStore((state) => state.currentSessionId);
|
|
const currentSessionDirectory = useSessionUIStore(
|
|
React.useCallback((state) => (currentSessionId ? state.getDirectoryForSession(currentSessionId) : null), [currentSessionId]),
|
|
);
|
|
const effectiveDirectory = currentSessionDirectory || currentDirectory;
|
|
const currentSession = useSession(currentSessionId, effectiveDirectory || undefined);
|
|
const isNewSessionDraftOpen = useSessionUIStore((state) => Boolean(state.newSessionDraft?.open));
|
|
|
|
const sessionTitle = currentSession?.title?.trim();
|
|
// Single-line title, desktop-style: session title, or the "New session"
|
|
// placeholder on the draft screen. No project/branch metadata line.
|
|
const primaryLabel = sessionTitle
|
|
|| (currentSessionId ? t('mobile.sessions.untitled') : t('sessions.switcher.draftTitle'));
|
|
|
|
React.useEffect(() => {
|
|
setMetadataOpen(false);
|
|
setSwitcherOpen(false);
|
|
}, [currentSessionId, effectiveDirectory]);
|
|
|
|
const handleOpenSessions = React.useCallback(() => {
|
|
setMetadataOpen(false);
|
|
setSwitcherOpen(false);
|
|
onOpenSessions();
|
|
}, [onOpenSessions]);
|
|
|
|
// The two header popovers are mutually exclusive.
|
|
const handleMetadataOpenChange = React.useCallback((value: boolean | ((open: boolean) => boolean)) => {
|
|
setMetadataOpen((current) => {
|
|
const next = typeof value === 'function' ? value(current) : value;
|
|
if (next) setSwitcherOpen(false);
|
|
return next;
|
|
});
|
|
}, []);
|
|
|
|
const toggleSwitcher = React.useCallback(() => {
|
|
setSwitcherOpen((current) => {
|
|
const next = !current;
|
|
if (next) setMetadataOpen(false);
|
|
return next;
|
|
});
|
|
}, []);
|
|
|
|
return (
|
|
<>
|
|
<header
|
|
className="oc-mobile-header relative z-30 flex shrink-0 items-center gap-1 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80"
|
|
style={{ paddingTop: 'var(--oc-safe-area-top, 0px)' }}
|
|
>
|
|
<div className="flex h-[var(--oc-header-height,56px)] w-full items-center gap-1 px-2">
|
|
<button
|
|
type="button"
|
|
className="flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"
|
|
aria-label={t('mobile.sessions.openSheetAria')}
|
|
onClick={handleOpenSessions}
|
|
style={{ touchAction: 'manipulation' }}
|
|
>
|
|
<Icon name="list-unordered" className="size-5" />
|
|
</button>
|
|
|
|
{/* Session title doubles as the recent-sessions switcher trigger. */}
|
|
<button
|
|
ref={titleRef}
|
|
type="button"
|
|
className={cn(
|
|
'flex min-w-0 items-center rounded-lg px-2 py-1.5 text-left transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary',
|
|
compactTitle ? 'shrink' : 'flex-1',
|
|
)}
|
|
aria-label={t('sessions.switcher.openAria')}
|
|
aria-haspopup="dialog"
|
|
aria-expanded={switcherOpen}
|
|
onClick={toggleSwitcher}
|
|
style={{ touchAction: 'manipulation' }}
|
|
>
|
|
<span className="flex min-w-0 items-center gap-1">
|
|
<span className="block min-w-0 truncate typography-ui-label text-foreground">{primaryLabel}</span>
|
|
{/* Discoverability: the chevron marks the title as a disclosure
|
|
trigger and flips while the switcher is open. */}
|
|
<Icon
|
|
name="arrow-down-s"
|
|
className={cn(
|
|
'size-4 shrink-0 text-muted-foreground transition-transform duration-150',
|
|
switcherOpen && 'rotate-180',
|
|
)}
|
|
/>
|
|
</span>
|
|
</button>
|
|
|
|
{/* Compact title: this takes the leftover width so the trailing
|
|
controls stay pinned to the right edge. */}
|
|
{compactTitle ? <div className="min-w-0 flex-1" /> : null}
|
|
|
|
<MobileSessionMetadataButton
|
|
open={metadataOpen}
|
|
onOpenChange={handleMetadataOpenChange}
|
|
currentSessionId={currentSessionId}
|
|
effectiveDirectory={effectiveDirectory}
|
|
isNewSessionDraftOpen={isNewSessionDraftOpen}
|
|
/>
|
|
|
|
<button
|
|
type="button"
|
|
className="flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"
|
|
aria-label={t('mobile.header.openWorkspaceAria')}
|
|
onClick={() => {
|
|
setMetadataOpen(false);
|
|
setSwitcherOpen(false);
|
|
onOpenWorkspace();
|
|
}}
|
|
style={{ touchAction: 'manipulation' }}
|
|
>
|
|
<Icon name="pencil-ruler-2" className="size-5" />
|
|
</button>
|
|
</div>
|
|
</header>
|
|
<MobileSessionSwitcher
|
|
open={switcherOpen}
|
|
onClose={() => setSwitcherOpen(false)}
|
|
anchorRef={titleRef}
|
|
/>
|
|
</>
|
|
);
|
|
};
|