Add split-view mobile workspace layout

- Enable adaptive sidebar navigation on wide mobile windows
- Keep compact single-pane behavior on phones
- Extract and test shared thread grouping and layout logic

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex authored and Julius Marminge committed 2026-06-26 17:08:18 -07:00
1 parent 6245c547c2
commit 80d2b26d94
13 files changed
+623 -79

No files matched your search

+1 -1
View File
@@ -64,7 +64,7 @@ const config: ExpoConfig = {
runtimeVersion: {
policy: process.env.MOBILE_VERSION_POLICY ?? "appVersion",
},
orientation: "portrait",
orientation: "default",
icon: "./assets/icon.png",
userInterfaceStyle: "automatic",
updates: {
+30 -27
View File
@@ -26,6 +26,7 @@ import {
useClerkSettingsSheetDetent,
} from "../features/cloud/ClerkSettingsSheetDetent";
import { useAgentNotificationNavigation } from "../features/agent-awareness/notificationNavigation";
import { AdaptiveWorkspaceLayout } from "../features/layout/AdaptiveWorkspaceLayout";
import { useThemeColor } from "../lib/useThemeColor";
function AppNavigator() {
@@ -92,33 +93,35 @@ function AppNavigatorContent() {
backgroundColor={String(statusBarBg)}
translucent
/>
<Stack screenOptions={{ headerShown: false }}>
<Stack.Screen
name="index"
options={{
contentStyle: { backgroundColor: "transparent" },
headerShown: true,
headerTransparent: true,
headerShadowVisible: false,
}}
/>
<Stack.Screen
name="settings"
listeners={{ transitionEnd: handleSettingsTransitionEnd }}
options={settingsSheetScreenOptions}
/>
<Stack.Screen name="connections" options={connectionSheetScreenOptions} />
<Stack.Screen name="new" options={newTaskScreenOptions} />
<Stack.Screen
name="threads/[environmentId]/[threadId]"
options={{
animation: "slide_from_right",
contentStyle: { backgroundColor: "transparent" },
gestureEnabled: true,
headerShown: false,
}}
/>
</Stack>
<AdaptiveWorkspaceLayout>
<Stack screenOptions={{ headerShown: false }}>
<Stack.Screen
name="index"
options={{
contentStyle: { backgroundColor: "transparent" },
headerShown: true,
headerTransparent: true,
headerShadowVisible: false,
}}
/>
<Stack.Screen
name="settings"
listeners={{ transitionEnd: handleSettingsTransitionEnd }}
options={settingsSheetScreenOptions}
/>
<Stack.Screen name="connections" options={connectionSheetScreenOptions} />
<Stack.Screen name="new" options={newTaskScreenOptions} />
<Stack.Screen
name="threads/[environmentId]/[threadId]"
options={{
animation: "slide_from_right",
contentStyle: { backgroundColor: "transparent" },
gestureEnabled: true,
headerShown: false,
}}
/>
</Stack>
</AdaptiveWorkspaceLayout>
</>
);
}
+20 -1
View File
@@ -10,7 +10,7 @@ import {
} from "@t3tools/contracts";
import * as Arr from "effect/Array";
import * as Order from "effect/Order";
import { useRouter } from "expo-router";
import { Stack, useRouter } from "expo-router";
import { useCallback, useMemo, useState } from "react";
import { useProjects, useThreadShells } from "../state/entities";
@@ -21,6 +21,8 @@ import { HomeScreen } from "../features/home/HomeScreen";
import { HomeHeader } from "../features/home/HomeHeader";
import type { HomeProjectSortOrder } from "../features/home/homeThreadList";
import { useThreadListActions } from "../features/home/useThreadListActions";
import { useAdaptiveWorkspaceLayout } from "../features/layout/AdaptiveWorkspaceLayout";
import { WorkspaceEmptyDetail } from "../features/layout/WorkspaceEmptyDetail";
interface HomeListOptions {
readonly selectedEnvironmentId: EnvironmentId | null;
@@ -32,6 +34,7 @@ interface HomeListOptions {
/* ─── Route screen ───────────────────────────────────────────────────── */
export default function HomeRouteScreen() {
const { layout } = useAdaptiveWorkspaceLayout();
const projects = useProjects();
const threads = useThreadShells();
const { state: catalogState } = useWorkspaceState();
@@ -80,6 +83,22 @@ export default function HomeRouteScreen() {
setListOptions((current) => ({ ...current, projectGroupingMode }));
}, []);
if (layout.usesSplitView) {
return (
<>
<Stack.Screen
options={{
headerShown: true,
headerTransparent: true,
headerShadowVisible: false,
headerTitle: "",
}}
/>
<WorkspaceEmptyDetail />
</>
);
}
return (
<>
<HomeHeader
@@ -0,0 +1,65 @@
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
import { useGlobalSearchParams, useRouter } from "expo-router";
import { createContext, use, useMemo, type ReactNode } from "react";
import { useWindowDimensions, View } from "react-native";
import { deriveLayout, type Layout } from "../../lib/layout";
import { buildThreadRoutePath } from "../../lib/routes";
import { scopedThreadKey } from "../../lib/scopedEntities";
import { ThreadNavigationSidebar } from "../threads/ThreadNavigationSidebar";
interface AdaptiveWorkspaceContextValue {
readonly layout: Layout;
}
const compactLayout = deriveLayout({ width: 0, height: 0 });
const AdaptiveWorkspaceContext = createContext<AdaptiveWorkspaceContextValue>({
layout: compactLayout,
});
function firstRouteParam(value: string | string[] | undefined): string | null {
return Array.isArray(value) ? (value[0] ?? null) : (value ?? null);
}
export function useAdaptiveWorkspaceLayout(): AdaptiveWorkspaceContextValue {
return use(AdaptiveWorkspaceContext);
}
export function AdaptiveWorkspaceLayout(props: { readonly children: ReactNode }) {
const { width, height } = useWindowDimensions();
const router = useRouter();
const params = useGlobalSearchParams<{
environmentId?: string | string[];
threadId?: string | string[];
}>();
const layout = useMemo(() => deriveLayout({ width, height }), [height, width]);
const environmentId = firstRouteParam(params.environmentId);
const threadId = firstRouteParam(params.threadId);
const selectedThreadKey =
environmentId !== null && threadId !== null
? scopedThreadKey(EnvironmentId.make(environmentId), ThreadId.make(threadId))
: null;
const contextValue = useMemo(() => ({ layout }), [layout]);
const handleSelectThread = (thread: EnvironmentThreadShell) => {
router.replace(buildThreadRoutePath(thread));
};
return (
<AdaptiveWorkspaceContext.Provider value={contextValue}>
<View testID="adaptive-workspace-layout" style={{ flex: 1, flexDirection: "row" }}>
{layout.usesSplitView && layout.listPaneWidth !== null ? (
<ThreadNavigationSidebar
width={layout.listPaneWidth}
selectedThreadKey={selectedThreadKey}
onOpenSettings={() => router.push("/settings")}
onSelectThread={handleSelectThread}
onStartNewTask={() => router.push("/new")}
/>
) : null}
<View style={{ flex: 1 }}>{props.children}</View>
</View>
</AdaptiveWorkspaceContext.Provider>
);
}
@@ -0,0 +1,21 @@
import { SymbolView } from "expo-symbols";
import { View } from "react-native";
import { AppText as Text } from "../../components/AppText";
import { useThemeColor } from "../../lib/useThemeColor";
export function WorkspaceEmptyDetail() {
const iconColor = useThemeColor("--color-icon-subtle");
return (
<View className="flex-1 items-center justify-center bg-screen px-10">
<View className="max-w-[360px] items-center gap-3">
<SymbolView name="sidebar.left" size={34} tintColor={iconColor} type="hierarchical" />
<Text className="text-center text-xl font-t3-bold">Select a thread</Text>
<Text className="text-center text-base text-foreground-muted">
Choose a thread from the sidebar or start a new task.
</Text>
</View>
</View>
);
}
@@ -25,6 +25,7 @@ import {
ActivityIndicator,
Image,
Linking,
type LayoutChangeEvent,
Pressable,
ScrollView,
StyleSheet,
@@ -1121,7 +1122,8 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
const foldSettleSecondFrameRef = useRef<number | null>(null);
const disclosureAnchorKeyRef = useRef<string | null>(null);
const previousLatestTurnRef = useRef(props.latestTurn);
const { width: viewportWidth } = useWindowDimensions();
const { width: windowWidth } = useWindowDimensions();
const [viewportWidth, setViewportWidth] = useState(windowWidth);
const [disclosureToggleSettling, setDisclosureToggleSettling] = useState(false);
const [interactionState, setInteractionState] = useState<{
readonly copiedRowId: string | null;
@@ -1147,6 +1149,11 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
const topContentInset = props.contentTopInset ?? insets.top + 44;
const bottomContentInset = props.contentBottomInset ?? 18;
const handleViewportLayout = useCallback((event: LayoutChangeEvent) => {
const nextWidth = Math.round(event.nativeEvent.layout.width);
setViewportWidth((current) => (Math.abs(current - nextWidth) > 1 ? nextWidth : current));
}, []);
const iconSubtleColor = useThemeColor("--color-icon-subtle");
const userBubbleColor = useThemeColor("--color-user-bubble");
const onMarkdownLinkPress = useCallback(
@@ -1451,7 +1458,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
return (
<>
<View style={{ flex: 1 }}>
<View style={{ flex: 1 }} onLayout={handleViewportLayout}>
<KeyboardAwareLegendList
ref={props.listRef}
key={props.threadId}
@@ -8,8 +8,6 @@ import {
useWindowDimensions,
View,
} from "react-native";
import * as Arr from "effect/Array";
import * as Order from "effect/Order";
import { Gesture, GestureDetector } from "react-native-gesture-handler";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import Animated, {
@@ -23,22 +21,11 @@ import { useThemeColor } from "../../lib/useThemeColor";
import { AppText as Text } from "../../components/AppText";
import { StatusPill } from "../../components/StatusPill";
import { useProjects, useThreadShells } from "../../state/entities";
import { groupProjectsByRepository } from "../../lib/repositoryGroups";
import { scopedThreadKey } from "../../lib/scopedEntities";
import { relativeTime } from "../../lib/time";
import { threadStatusTone } from "./threadPresentation";
import { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
const threadActivityOrder = Order.mapInput(
Order.Struct({
activityAt: Order.flip(Order.Number),
title: Order.String,
}),
(thread: EnvironmentThreadShell) => ({
activityAt: new Date(thread.updatedAt ?? thread.createdAt).getTime(),
title: thread.title,
}),
);
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
import { buildThreadNavigationGroups } from "./thread-navigation-groups";
export function ThreadNavigationDrawer(props: {
readonly visible: boolean;
@@ -192,24 +179,9 @@ function ThreadNavigationDrawerContent(props: {
}) {
const projects = useProjects();
const threads = useThreadShells();
const repositoryGroups = useMemo(
() => groupProjectsByRepository({ projects, threads }),
[projects, threads],
);
const groupedThreads = useMemo(
() =>
repositoryGroups.map((group) => {
const threads: EnvironmentThreadShell[] = [];
for (const projectGroup of group.projects) {
threads.push(...projectGroup.threads);
}
return {
key: group.key,
title: group.projects[0]?.project.title ?? group.title,
threads: Arr.sort(threads, threadActivityOrder),
};
}),
[repositoryGroups],
() => buildThreadNavigationGroups({ projects, threads }),
[projects, threads],
);
return (
@@ -0,0 +1,219 @@
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
import { SymbolView } from "expo-symbols";
import { useMemo, useState } from "react";
import { Pressable, ScrollView, StyleSheet, TextInput, View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { AppText as Text } from "../../components/AppText";
import { StatusPill } from "../../components/StatusPill";
import { scopedThreadKey } from "../../lib/scopedEntities";
import { relativeTime } from "../../lib/time";
import { useThemeColor } from "../../lib/useThemeColor";
import { useProjects, useThreadShells } from "../../state/entities";
import { buildThreadNavigationGroups } from "./thread-navigation-groups";
import { threadStatusTone } from "./threadPresentation";
export function ThreadNavigationSidebar(props: {
readonly width: number;
readonly selectedThreadKey: string | null;
readonly onOpenSettings: () => void;
readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
readonly onStartNewTask: () => void;
}) {
const insets = useSafeAreaInsets();
const projects = useProjects();
const threads = useThreadShells();
const [searchQuery, setSearchQuery] = useState("");
const groups = useMemo(
() => buildThreadNavigationGroups({ projects, threads, searchQuery }),
[projects, searchQuery, threads],
);
const backgroundColor = useThemeColor("--color-drawer");
const borderColor = useThemeColor("--color-border");
const foregroundColor = useThemeColor("--color-foreground");
const iconColor = useThemeColor("--color-icon-muted");
const mutedColor = useThemeColor("--color-foreground-muted");
const placeholderColor = useThemeColor("--color-placeholder");
const searchBackgroundColor = useThemeColor("--color-subtle-strong");
const selectedBackgroundColor = useThemeColor("--color-subtle-strong");
const pressedBackgroundColor = useThemeColor("--color-subtle");
return (
<View
testID="thread-navigation-sidebar"
style={{
width: props.width,
backgroundColor,
borderRightColor: borderColor,
borderRightWidth: StyleSheet.hairlineWidth,
paddingTop: insets.top + 8,
}}
>
<View style={styles.header}>
<Text className="flex-1 text-2xl font-t3-bold" numberOfLines={1}>
Threads
</Text>
<Pressable
accessibilityLabel="Open settings"
accessibilityRole="button"
hitSlop={4}
onPress={props.onOpenSettings}
style={({ pressed }) => [
styles.headerButton,
{ backgroundColor: pressed ? pressedBackgroundColor : "transparent" },
]}
>
<SymbolView name="gearshape" size={18} tintColor={iconColor} type="monochrome" />
</Pressable>
<Pressable
accessibilityLabel="New task"
accessibilityRole="button"
hitSlop={4}
onPress={props.onStartNewTask}
style={({ pressed }) => [
styles.headerButton,
{ backgroundColor: pressed ? pressedBackgroundColor : "transparent" },
]}
>
<SymbolView name="square.and.pencil" size={18} tintColor={iconColor} type="monochrome" />
</Pressable>
</View>
<View style={[styles.searchField, { backgroundColor: searchBackgroundColor }]}>
<SymbolView name="magnifyingglass" size={15} tintColor={mutedColor} type="monochrome" />
<TextInput
accessibilityLabel="Search threads"
autoCapitalize="none"
autoCorrect={false}
clearButtonMode="while-editing"
onChangeText={setSearchQuery}
placeholder="Search"
placeholderTextColor={placeholderColor}
returnKeyType="search"
style={[styles.searchInput, { color: foregroundColor }]}
value={searchQuery}
/>
</View>
<ScrollView
contentContainerStyle={{
gap: 18,
paddingHorizontal: 10,
paddingTop: 16,
paddingBottom: Math.max(insets.bottom, 16),
}}
keyboardDismissMode="on-drag"
keyboardShouldPersistTaps="handled"
showsVerticalScrollIndicator={false}
>
{groups.length === 0 ? (
<Text className="px-2 py-4 text-sm text-foreground-muted">
{searchQuery.trim().length > 0 ? "No matching threads" : "No threads yet"}
</Text>
) : (
groups.map((group) => (
<View key={group.key} style={styles.section}>
<Text className="px-2 text-xs font-t3-bold text-foreground-muted" numberOfLines={1}>
{group.title}
</Text>
{group.threads.length === 0 ? (
<Text className="px-2 py-2 text-sm text-foreground-tertiary">No threads yet</Text>
) : (
group.threads.map((thread) => {
const threadKey = scopedThreadKey(thread.environmentId, thread.id);
const selected = threadKey === props.selectedThreadKey;
return (
<Pressable
key={threadKey}
accessibilityLabel={thread.title}
accessibilityRole="button"
accessibilityState={{ selected }}
onPress={() => props.onSelectThread(thread)}
style={({ pressed }) => [
styles.threadRow,
{
backgroundColor: selected
? selectedBackgroundColor
: pressed
? pressedBackgroundColor
: "transparent",
},
]}
>
<View style={styles.threadText}>
<Text className="text-base font-t3-medium" numberOfLines={1}>
{thread.title}
</Text>
<Text className="text-xs text-foreground-muted" numberOfLines={1}>
{relativeTime(thread.updatedAt ?? thread.createdAt)}
</Text>
</View>
<StatusPill {...threadStatusTone(thread)} size="compact" />
</Pressable>
);
})
)}
</View>
))
)}
</ScrollView>
</View>
);
}
const styles = StyleSheet.create({
header: {
minHeight: 48,
paddingLeft: 18,
paddingRight: 8,
flexDirection: "row",
alignItems: "center",
gap: 2,
},
headerButton: {
width: 44,
height: 44,
borderRadius: 12,
alignItems: "center",
justifyContent: "center",
},
searchField: {
height: 36,
marginTop: 6,
marginHorizontal: 14,
paddingLeft: 10,
paddingRight: 5,
borderRadius: 10,
flexDirection: "row",
alignItems: "center",
gap: 7,
},
searchInput: {
flex: 1,
height: 36,
paddingVertical: 0,
paddingHorizontal: 0,
fontFamily: "DMSans_400Regular",
fontSize: 15,
},
section: {
gap: 4,
},
threadRow: {
minHeight: 58,
borderRadius: 10,
paddingHorizontal: 10,
paddingVertical: 8,
flexDirection: "row",
alignItems: "center",
gap: 8,
},
threadText: {
minWidth: 0,
flex: 1,
gap: 2,
},
});
@@ -1,5 +1,5 @@
import { Stack, useLocalSearchParams, useRouter } from "expo-router";
import { useCallback, useMemo, useState } from "react";
import { useCallback, useEffect, useMemo, useState } from "react";
import * as Option from "effect/Option";
import { EnvironmentId, type ProjectScript } from "@t3tools/contracts";
import { projectScriptCwd, projectScriptRuntimeEnv } from "@t3tools/shared/projectScripts";
@@ -47,6 +47,7 @@ import { useSelectedThreadWorktree } from "../../state/use-selected-thread-workt
import { useThreadComposerState } from "../../state/use-thread-composer-state";
import { threadEnvironment } from "../../state/threads";
import { projectThreadContentPresentation } from "./threadContentPresentation";
import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
function firstRouteParam(value: string | string[] | undefined): string | null {
if (Array.isArray(value)) {
@@ -61,6 +62,7 @@ function OpeningThreadLoadingScreen() {
}
export function ThreadRouteScreen() {
const { layout } = useAdaptiveWorkspaceLayout();
const { state: workspaceState } = useWorkspaceState();
const { connectionState } = useRemoteConnectionStatus();
const { onReconnectEnvironment } = useRemoteConnections();
@@ -145,8 +147,16 @@ export function ThreadRouteScreen() {
const gitActionProgress = useGitActionProgress(gitActionProgressTarget);
const handleOpenDrawer = useCallback(() => {
setDrawerVisible(true);
}, []);
if (!layout.usesSplitView) {
setDrawerVisible(true);
}
}, [layout.usesSplitView]);
useEffect(() => {
if (layout.usesSplitView) {
setDrawerVisible(false);
}
}, [layout.usesSplitView]);
const handleOpenConnectionEditor = useCallback(() => {
void router.push("/connections");
@@ -328,6 +338,7 @@ export function ThreadRouteScreen() {
headerStyle: { backgroundColor: "transparent" },
headerShadowVisible: false,
headerTintColor: iconColor,
headerBackVisible: !layout.usesSplitView,
headerBackTitle: "",
headerTitle: () => (
<Pressable
@@ -405,6 +416,7 @@ export function ThreadRouteScreen() {
projectWorkspaceRoot={selectedThreadProject?.workspaceRoot ?? null}
threadCwd={selectedThreadCwd}
selectedThreadQueueCount={composer.selectedThreadQueueCount}
layoutVariant={layout.variant}
onOpenDrawer={handleOpenDrawer}
onOpenConnectionEditor={handleOpenConnectionEditor}
onChangeDraftMessage={composer.onChangeDraftMessage}
@@ -424,15 +436,17 @@ export function ThreadRouteScreen() {
onSubmitUserInput={requests.onSubmitUserInput}
/>
<ThreadNavigationDrawer
visible={drawerVisible}
selectedThreadKey={selectedThreadKey}
onClose={() => setDrawerVisible(false)}
onSelectThread={(thread) => {
router.replace(buildThreadRoutePath(thread));
}}
onStartNewTask={() => router.push("/new")}
/>
{layout.usesSplitView ? null : (
<ThreadNavigationDrawer
visible={drawerVisible}
selectedThreadKey={selectedThreadKey}
onClose={() => setDrawerVisible(false)}
onSelectThread={(thread) => {
router.replace(buildThreadRoutePath(thread));
}}
onStartNewTask={() => router.push("/new")}
/>
)}
</View>
</>
);
@@ -0,0 +1,94 @@
import type {
EnvironmentProject,
EnvironmentThreadShell,
} from "@t3tools/client-runtime/state/shell";
import { EnvironmentId, ProjectId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";
import { buildThreadNavigationGroups } from "./thread-navigation-groups";
const environmentId = EnvironmentId.make("environment-1");
function makeProject(input: Pick<EnvironmentProject, "id" | "title">): EnvironmentProject {
return {
environmentId,
workspaceRoot: `/workspaces/${input.id}`,
repositoryIdentity: null,
defaultModelSelection: null,
scripts: [],
createdAt: "2026-06-01T00:00:00.000Z",
updatedAt: "2026-06-01T00:00:00.000Z",
...input,
};
}
function makeThread(
input: Pick<EnvironmentThreadShell, "id" | "projectId" | "title"> &
Partial<EnvironmentThreadShell>,
): EnvironmentThreadShell {
return {
environmentId,
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
runtimeMode: "full-access",
interactionMode: "default",
branch: null,
worktreePath: null,
latestTurn: null,
createdAt: "2026-06-01T00:00:00.000Z",
updatedAt: "2026-06-01T00:00:00.000Z",
archivedAt: null,
session: null,
latestUserMessageAt: null,
hasPendingApprovals: false,
hasPendingUserInput: false,
hasActionableProposedPlan: false,
...input,
};
}
describe("buildThreadNavigationGroups", () => {
const project = makeProject({ id: ProjectId.make("project-1"), title: "T3 Code" });
const threads = [
makeThread({
id: ThreadId.make("older"),
projectId: project.id,
title: "Fix reconnect flow",
updatedAt: "2026-06-02T00:00:00.000Z",
}),
makeThread({
id: ThreadId.make("newer"),
projectId: project.id,
title: "Build adaptive sidebar",
updatedAt: "2026-06-03T00:00:00.000Z",
}),
];
it("sorts each group by recent activity", () => {
expect(
buildThreadNavigationGroups({ projects: [project], threads })[0]?.threads.map(
(thread) => thread.id,
),
).toEqual(["newer", "older"]);
});
it("matches thread titles without dropping their group", () => {
const groups = buildThreadNavigationGroups({
projects: [project],
threads,
searchQuery: "reconnect",
});
expect(groups).toHaveLength(1);
expect(groups[0]?.threads.map((thread) => thread.id)).toEqual(["older"]);
});
it("keeps every thread when the project title matches", () => {
expect(
buildThreadNavigationGroups({
projects: [project],
threads,
searchQuery: "t3 code",
})[0]?.threads.map((thread) => thread.id),
).toEqual(["newer", "older"]);
});
});
@@ -0,0 +1,63 @@
import type {
EnvironmentProject,
EnvironmentThreadShell,
} from "@t3tools/client-runtime/state/shell";
import * as Arr from "effect/Array";
import * as Order from "effect/Order";
import { groupProjectsByRepository } from "../../lib/repositoryGroups";
export interface ThreadNavigationGroup {
readonly key: string;
readonly title: string;
readonly threads: ReadonlyArray<EnvironmentThreadShell>;
}
const threadActivityOrder = Order.mapInput(
Order.Struct({
activityAt: Order.flip(Order.Number),
title: Order.String,
}),
(thread: EnvironmentThreadShell) => ({
activityAt: new Date(thread.updatedAt ?? thread.createdAt).getTime(),
title: thread.title,
}),
);
export function buildThreadNavigationGroups(input: {
readonly projects: ReadonlyArray<EnvironmentProject>;
readonly threads: ReadonlyArray<EnvironmentThreadShell>;
readonly searchQuery?: string;
}): ReadonlyArray<ThreadNavigationGroup> {
const query = input.searchQuery?.trim().toLocaleLowerCase() ?? "";
return groupProjectsByRepository(input).flatMap((group) => {
const threads = Arr.sort(
group.projects.flatMap((projectGroup) => projectGroup.threads),
threadActivityOrder,
);
const title = group.projects[0]?.project.title ?? group.title;
const groupMatches =
query.length === 0 ||
title.toLocaleLowerCase().includes(query) ||
group.title.toLocaleLowerCase().includes(query) ||
group.projects.some((projectGroup) =>
projectGroup.project.title.toLocaleLowerCase().includes(query),
);
const matchingThreads = groupMatches
? threads
: threads.filter((thread) => thread.title.toLocaleLowerCase().includes(query));
if (query.length > 0 && matchingThreads.length === 0) {
return [];
}
return [
{
key: group.key,
title,
threads: matchingThreads,
},
];
});
}
+51
View File
@@ -0,0 +1,51 @@
import { describe, expect, it } from "vite-plus/test";
import { deriveLayout, SPLIT_LAYOUT_MIN_HEIGHT, SPLIT_LAYOUT_MIN_WIDTH } from "./layout";
describe("deriveLayout", () => {
it.each([
{ name: "small iPhone portrait", width: 375, height: 667 },
{ name: "large iPhone portrait", width: 430, height: 932 },
{ name: "small iPhone landscape", width: 667, height: 375 },
{ name: "large iPhone landscape", width: 932, height: 430 },
{ name: "short wide window", width: 1_024, height: 599 },
{ name: "narrow tall window", width: 719, height: 1_024 },
])("keeps a $name in the compact shell", ({ width, height }) => {
expect(deriveLayout({ width, height })).toEqual({
variant: "compact",
usesSplitView: false,
listPaneWidth: null,
shellPadding: 0,
});
});
it.each([
{ name: "small tablet portrait", width: 744, height: 1_133 },
{ name: "tablet landscape", width: 1_024, height: 768 },
{ name: "large resizable window", width: 1_366, height: 1_024 },
{ name: "foldable-sized window", width: 800, height: 700 },
])("uses the split shell for a $name", ({ width, height }) => {
expect(deriveLayout({ width, height })).toMatchObject({
variant: "split",
usesSplitView: true,
});
});
it("switches only after both space requirements are met", () => {
expect(
deriveLayout({ width: SPLIT_LAYOUT_MIN_WIDTH, height: SPLIT_LAYOUT_MIN_HEIGHT }).variant,
).toBe("split");
expect(
deriveLayout({ width: SPLIT_LAYOUT_MIN_WIDTH - 1, height: SPLIT_LAYOUT_MIN_HEIGHT }).variant,
).toBe("compact");
expect(
deriveLayout({ width: SPLIT_LAYOUT_MIN_WIDTH, height: SPLIT_LAYOUT_MIN_HEIGHT - 1 }).variant,
).toBe("compact");
});
it("keeps the sidebar within usable native-column bounds", () => {
expect(deriveLayout({ width: 720, height: 1_000 }).listPaneWidth).toBe(280);
expect(deriveLayout({ width: 1_024, height: 768 }).listPaneWidth).toBe(328);
expect(deriveLayout({ width: 1_600, height: 1_000 }).listPaneWidth).toBe(380);
});
});
+20 -4
View File
@@ -2,6 +2,19 @@ function clamp(value: number, min: number, max: number): number {
return Math.min(Math.max(value, min), max);
}
/**
* Use available space, not device or orientation labels, to choose the shell.
*
* The height floor deliberately keeps every current iPhone in the compact shell
* when it rotates to landscape, while still allowing iPad and foldable-sized
* windows to adopt the persistent sidebar as they resize.
*/
export const SPLIT_LAYOUT_MIN_WIDTH = 720;
export const SPLIT_LAYOUT_MIN_HEIGHT = 600;
const SPLIT_SIDEBAR_MIN_WIDTH = 280;
const SPLIT_SIDEBAR_MAX_WIDTH = 380;
export type LayoutVariant = "compact" | "split";
export interface Layout {
@@ -13,8 +26,7 @@ export interface Layout {
export function deriveLayout(input: { readonly width: number; readonly height: number }): Layout {
const { width, height } = input;
const shortestEdge = Math.min(width, height);
const wideEnoughForSplit = width >= 900 || (width >= 700 && shortestEdge >= 700);
const wideEnoughForSplit = width >= SPLIT_LAYOUT_MIN_WIDTH && height >= SPLIT_LAYOUT_MIN_HEIGHT;
if (!wideEnoughForSplit) {
return {
@@ -28,7 +40,11 @@ export function deriveLayout(input: { readonly width: number; readonly height: n
return {
variant: "split",
usesSplitView: true,
listPaneWidth: clamp(Math.round(width * 0.34), 320, 420),
shellPadding: width >= 1180 ? 20 : 14,
listPaneWidth: clamp(
Math.round(width * 0.32),
SPLIT_SIDEBAR_MIN_WIDTH,
SPLIT_SIDEBAR_MAX_WIDTH,
),
shellPadding: 0,
};
}