diff --git a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx index b1e3d95593..e0634102cb 100644 --- a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx +++ b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx @@ -18,10 +18,8 @@ import { formatElapsed } from "@t3tools/shared/orchestrationTiming"; import * as Haptics from "expo-haptics"; import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react"; import { View, type GestureResponderEvent } from "react-native"; -import { Gesture, GestureDetector } from "react-native-gesture-handler"; import { KeyboardController, KeyboardStickyView } from "react-native-keyboard-controller"; import { useSafeAreaInsets } from "react-native-safe-area-context"; -import { runOnJS } from "react-native-reanimated"; import { AppText as Text } from "../../components/AppText"; import type { ComposerEditorHandle } from "../../components/ComposerEditor"; @@ -73,7 +71,6 @@ export interface ThreadDetailScreenProps { readonly layoutVariant?: LayoutVariant; readonly usesAutomaticContentInsets?: boolean; readonly onHeaderMaterialVisibilityChange?: (visible: boolean) => void; - readonly onOpenDrawer: () => void; readonly onOpenConnectionEditor: () => void; readonly onChangeDraftMessage: (value: string) => void; readonly onPickDraftImages: () => Promise; @@ -208,8 +205,6 @@ const WorkingDurationPill = memo(function WorkingDurationPill(props: { }); export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: ThreadDetailScreenProps) { - const { onOpenDrawer } = props; - const insets = useSafeAreaInsets(); const agentLabel = `${props.selectedThread.modelSelection.instanceId} agent`; const selectedThreadKey = scopedThreadKey(props.environmentId, props.selectedThread.id); @@ -263,38 +258,6 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread [props.serverConfig, selectedInstanceId], ); - const completeDrawerGesture = useCallback(() => { - void Haptics.selectionAsync(); - onOpenDrawer(); - }, [onOpenDrawer]); - - const drawerGestureThreshold = 80; - const headerDrawerGesture = useMemo( - () => - Gesture.Pan() - .enabled(!isSplitLayout) - .hitSlop({ left: 0, width: 40 }) - .activeOffsetX([10, 999]) - .failOffsetY([-24, 24]) - // Fail at touch-down for anything below the header strip. Activating - // there (the y check in onEnd fires too late to matter) swallows the - // left-edge touch and blocks the native back-swipe along the whole - // screen height. - .onTouchesDown((event, stateManager) => { - const touchY = event.allTouches[0]?.y ?? Number.POSITIVE_INFINITY; - if (touchY >= drawerGestureThreshold) { - stateManager.fail(); - } - }) - .onEnd((event) => { - const translationX = Math.max(event.translationX, 0); - if (event.y < drawerGestureThreshold && translationX > 56) { - runOnJS(completeDrawerGesture)(); - } - }), - [completeDrawerGesture, isSplitLayout], - ); - useLayoutEffect(() => { selectedThreadKeyRef.current = selectedThreadKey; }, [selectedThreadKey]); @@ -404,115 +367,113 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread }, []); return ( - - - {showContent ? ( + + {showContent ? ( + + + + ) : ( + + )} + + {/* Floating composer — sticks to keyboard via KeyboardStickyView */} + {showContent ? ( + - + {props.activeWorkStartedAt ? ( + + ) : null} + + {props.activePendingApproval || props.activePendingUserInput ? ( + + {props.activePendingApproval ? ( + + ) : null} + {props.activePendingUserInput ? ( + + ) : null} + + ) : null} + + + - ) : ( - - )} - - {/* Floating composer — sticks to keyboard via KeyboardStickyView */} - {showContent ? ( - - - - {props.activeWorkStartedAt ? ( - - ) : null} - - {props.activePendingApproval || props.activePendingUserInput ? ( - - {props.activePendingApproval ? ( - - ) : null} - {props.activePendingUserInput ? ( - - ) : null} - - ) : null} - - - - - - ) : null} - - + + ) : null} + ); }); diff --git a/apps/mobile/src/features/threads/ThreadNavigationDrawer.tsx b/apps/mobile/src/features/threads/ThreadNavigationDrawer.tsx deleted file mode 100644 index a143c2f183..0000000000 --- a/apps/mobile/src/features/threads/ThreadNavigationDrawer.tsx +++ /dev/null @@ -1,255 +0,0 @@ -import { SymbolView } from "expo-symbols"; -import { useCallback, useEffect, useMemo, useState } from "react"; -import { - type ColorValue, - Modal, - Pressable, - ScrollView, - useWindowDimensions, - View, -} from "react-native"; -import { Gesture, GestureDetector } from "react-native-gesture-handler"; -import { useSafeAreaInsets } from "react-native-safe-area-context"; -import Animated, { - runOnJS, - useAnimatedStyle, - useSharedValue, - withTiming, -} from "react-native-reanimated"; -import { useThemeColor } from "../../lib/useThemeColor"; - -import { AppText as Text } from "../../components/AppText"; -import { StatusPill } from "../../components/StatusPill"; -import { useProjects, useThreadShells } from "../../state/entities"; -import { scopedThreadKey } from "../../lib/scopedEntities"; -import { relativeTime } from "../../lib/time"; -import { resolveThreadStatus } from "./threadPresentation"; -import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell"; -import { buildThreadNavigationGroups } from "./thread-navigation-groups"; - -export function ThreadNavigationDrawer(props: { - readonly visible: boolean; - readonly selectedThreadKey: string | null; - readonly onClose: () => void; - readonly onSelectThread: (thread: EnvironmentThreadShell) => void; - readonly onStartNewTask: () => void; -}) { - const insets = useSafeAreaInsets(); - const { width } = useWindowDimensions(); - const drawerWidth = Math.min(width * 0.84, 360); - const [mounted, setMounted] = useState(props.visible); - const translateX = useSharedValue(-drawerWidth); - const overlayOpacity = useSharedValue(0); - - const backdropColor = useThemeColor("--color-backdrop"); - const drawerBg = useThemeColor("--color-drawer"); - const drawerShadow = useThemeColor("--color-drawer-shadow"); - const primaryForeground = useThemeColor("--color-primary-foreground"); - const borderSubtleColor = useThemeColor("--color-border-subtle"); - - useEffect(() => { - if (props.visible) { - setMounted(true); - translateX.value = withTiming(0, { duration: 240 }); - overlayOpacity.value = withTiming(1, { duration: 220 }); - return; - } - - overlayOpacity.value = withTiming(0, { duration: 180 }); - translateX.value = withTiming(-drawerWidth, { duration: 220 }, (finished) => { - if (finished) { - runOnJS(setMounted)(false); - } - }); - }, [drawerWidth, overlayOpacity, props.visible, translateX]); - - const closeDrawer = useCallback(() => { - props.onClose(); - }, [props]); - - const panGesture = useMemo( - () => - Gesture.Pan() - .activeOffsetX([-12, 12]) - .failOffsetY([-24, 24]) - .onUpdate((event) => { - translateX.value = Math.min(0, event.translationX); - }) - .onEnd((event) => { - const shouldClose = event.translationX < -drawerWidth * 0.2 || event.velocityX < -500; - if (shouldClose) { - runOnJS(closeDrawer)(); - return; - } - - translateX.value = withTiming(0, { duration: 180 }); - }), - [closeDrawer, drawerWidth, translateX], - ); - - const drawerStyle = useAnimatedStyle(() => ({ - transform: [{ translateX: translateX.value }], - })); - - const backdropStyle = useAnimatedStyle(() => ({ - opacity: overlayOpacity.value, - })); - - if (!mounted) { - return null; - } - - return ( - - - - - - - - - Threads - { - props.onClose(); - props.onStartNewTask(); - }} - className="h-11 w-11 items-center justify-center rounded-full bg-primary" - > - - - - - - - - - - ); -} - -function ThreadNavigationDrawerContent(props: { - readonly bottomInset: number; - readonly borderSubtleColor: ColorValue; - readonly selectedThreadKey: string | null; - readonly onClose: () => void; - readonly onSelectThread: (thread: EnvironmentThreadShell) => void; -}) { - const projects = useProjects(); - const threads = useThreadShells(); - const groupedThreads = useMemo( - () => buildThreadNavigationGroups({ projects, threads }), - [projects, threads], - ); - - return ( - - {groupedThreads.map((group) => ( - - - {group.title} - - - - {group.threads.length === 0 ? ( - - No threads yet - - ) : ( - group.threads.map((thread, index) => { - const threadKey = scopedThreadKey(thread.environmentId, thread.id); - const selected = props.selectedThreadKey === threadKey; - const status = resolveThreadStatus(thread); - - return ( - { - props.onSelectThread(thread); - props.onClose(); - }} - style={{ - paddingHorizontal: 16, - paddingVertical: 15, - borderTopWidth: index === 0 ? 0 : 1, - borderTopColor: props.borderSubtleColor, - backgroundColor: selected ? undefined : "transparent", - }} - className={selected ? "bg-subtle" : undefined} - > - - - - {thread.title} - - - {relativeTime(thread.updatedAt ?? thread.createdAt)} - - - {status ? : null} - - - ); - }) - )} - - - ))} - - ); -} diff --git a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx index eb2d013152..27b39c4f1b 100644 --- a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx +++ b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx @@ -1,15 +1,9 @@ import { NativeStackScreenOptions } from "../../native/StackHeader"; -import { - StackActions, - useFocusEffect, - useNavigation, - type StaticScreenProps, -} from "@react-navigation/native"; +import { useFocusEffect, useNavigation, type StaticScreenProps } from "@react-navigation/native"; import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react"; import * as Option from "effect/Option"; import { EnvironmentId, ThreadId, type ProjectScript } from "@t3tools/contracts"; import { projectScriptCwd, projectScriptRuntimeEnv } from "@t3tools/shared/projectScripts"; -import * as Haptics from "expo-haptics"; import { Platform, Pressable, ScrollView, Text as RNText, View } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { useWorkspaceState } from "../../state/workspace"; @@ -50,7 +44,6 @@ import { useThreadGitRightHeaderItems, } from "./ThreadGitControls"; import { GitOverviewSheet } from "./git/GitOverviewSheet"; -import { ThreadNavigationDrawer } from "./ThreadNavigationDrawer"; import { useAtomCommand } from "../../state/use-atom-command"; import { useSelectedThreadGitActions } from "../../state/use-selected-thread-git-actions"; import { useSelectedThreadGitState } from "../../state/use-selected-thread-git-state"; @@ -198,7 +191,6 @@ function ThreadRouteContent( const interruptThreadTurn = useAtomCommand(threadEnvironment.interruptTurn, "thread interrupt"); const navigation = useNavigation(); const params = props.route.params; - const [drawerVisible, setDrawerVisible] = useState(false); const environmentIdRaw = firstRouteParam(params.environmentId); const environmentId = environmentIdRaw ? EnvironmentId.make(environmentIdRaw) : null; const threadId = firstRouteParam(params.threadId); @@ -327,19 +319,6 @@ function ThreadRouteContent( ); const gitActionProgress = useGitActionProgress(gitActionProgressTarget); - const handleOpenDrawer = useCallback(() => { - if (!layout.usesSplitView) { - void Haptics.selectionAsync(); - setDrawerVisible(true); - } - }, [layout.usesSplitView]); - - useEffect(() => { - if (layout.usesSplitView) { - setDrawerVisible(false); - } - }, [layout.usesSplitView]); - const handleOpenGitInspector = useCallback(() => { setInspectorSelection({ routeThreadIdentity, mode: "git" }); showAuxiliaryPane("inspector"); @@ -706,7 +685,6 @@ function ThreadRouteContent( selectedThreadQueueCount={composer.selectedThreadQueueCount} layoutVariant={layout.variant} usesAutomaticContentInsets={usesNativeHeaderGlass} - onOpenDrawer={handleOpenDrawer} onOpenConnectionEditor={handleOpenConnectionEditor} onChangeDraftMessage={composer.onChangeDraftMessage} onPickDraftImages={composer.onPickDraftImages} @@ -724,23 +702,6 @@ function ThreadRouteContent( onChangeUserInputCustomAnswer={requests.onChangeUserInputCustomAnswer} onSubmitUserInput={requests.onSubmitUserInput} /> - - {layout.usesSplitView ? null : ( - setDrawerVisible(false)} - onSelectThread={(thread) => { - navigation.dispatch( - StackActions.replace("Thread", { - environmentId: String(thread.environmentId), - threadId: String(thread.id), - }), - ); - }} - onStartNewTask={() => navigation.navigate("NewTaskSheet", { screen: "NewTask" })} - /> - )} ); diff --git a/apps/mobile/src/features/threads/thread-navigation-groups.test.ts b/apps/mobile/src/features/threads/thread-navigation-groups.test.ts deleted file mode 100644 index 2cfda2f486..0000000000 --- a/apps/mobile/src/features/threads/thread-navigation-groups.test.ts +++ /dev/null @@ -1,111 +0,0 @@ -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 { - 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 & - Partial, -): 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"]); - }); - - it("excludes archived threads from the navigation sidebar", () => { - const archived = makeThread({ - id: ThreadId.make("archived"), - projectId: project.id, - title: "Archived work", - archivedAt: "2026-06-04T00:00:00.000Z", - updatedAt: "2026-06-04T00:00:00.000Z", - }); - - expect( - buildThreadNavigationGroups({ - projects: [project], - threads: [...threads, archived], - })[0]?.threads.map((thread) => thread.id), - ).toEqual(["newer", "older"]); - }); -}); diff --git a/apps/mobile/src/features/threads/thread-navigation-groups.ts b/apps/mobile/src/features/threads/thread-navigation-groups.ts deleted file mode 100644 index 1531f6deb6..0000000000 --- a/apps/mobile/src/features/threads/thread-navigation-groups.ts +++ /dev/null @@ -1,64 +0,0 @@ -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; -} - -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; - readonly threads: ReadonlyArray; - readonly searchQuery?: string; -}): ReadonlyArray { - const query = input.searchQuery?.trim().toLocaleLowerCase() ?? ""; - const activeThreads = input.threads.filter((thread) => thread.archivedAt === null); - - return groupProjectsByRepository({ ...input, threads: activeThreads }).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, - }, - ]; - }); -}