diff --git a/apps/mobile/src/features/review/ReviewCommentComposerSheet.tsx b/apps/mobile/src/features/review/ReviewCommentComposerSheet.tsx index 5d613082f3..65255c14ff 100644 --- a/apps/mobile/src/features/review/ReviewCommentComposerSheet.tsx +++ b/apps/mobile/src/features/review/ReviewCommentComposerSheet.tsx @@ -238,17 +238,18 @@ export function ReviewCommentComposerSheet() { Comment - - + + diff --git a/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx b/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx index b73e874169..e58489ee1f 100644 --- a/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx +++ b/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx @@ -1,14 +1,33 @@ import { useRouter } from "expo-router"; +import { SymbolView } from "expo-symbols"; import { TextInputWrapper } from "expo-paste-input"; -import { useCallback, useEffect, useMemo } from "react"; -import { View } from "react-native"; -import { KeyboardStickyView, useKeyboardState } from "react-native-keyboard-controller"; +import { + type ComponentProps, + type ReactNode, + useCallback, + useEffect, + useMemo, + useRef, + useState, +} from "react"; +import { + InteractionManager, + Pressable, + ScrollView, + View, + useColorScheme, + type LayoutChangeEvent, + type NativeScrollEvent, + type NativeSyntheticEvent, + type TextInput as RNTextInput, +} from "react-native"; +import { KeyboardAvoidingView, useKeyboardState } from "react-native-keyboard-controller"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { useThemeColor } from "../../lib/useThemeColor"; import { EnvironmentId, type ModelSelection } from "@t3tools/contracts"; -import { AppTextInput as TextInput } from "../../components/AppText"; +import { AppText as Text, AppTextInput as TextInput } from "../../components/AppText"; import { ComposerAttachmentStrip } from "../../components/ComposerAttachmentStrip"; import { ControlPill, ControlPillMenu } from "../../components/ControlPill"; import { ProviderIcon } from "../../components/ProviderIcon"; @@ -22,6 +41,9 @@ import { NewTaskSheetHeader } from "./NewTaskSheetHeader"; import { branchBadgeLabel, useNewTaskFlow } from "./new-task-flow-provider"; import { useProjectActions } from "./use-project-actions"; +const TOOLBAR_FADE_WIDTH = 18; +const TOOLBAR_SCROLL_EPSILON = 4; + function withModelSelectionOption( selection: ModelSelection, id: string, @@ -34,6 +56,61 @@ function withModelSelectionOption( }; } +function formatTitleCase(value: string): string { + return value.length === 0 ? value : `${value.charAt(0).toUpperCase()}${value.slice(1)}`; +} + +function formatWorkspaceLabel(input: { + readonly workspaceMode: string; + readonly currentBranchName: string | null; + readonly selectedBranchName: string | null; +}): string { + const branchName = input.selectedBranchName ?? input.currentBranchName; + if (input.workspaceMode === "worktree") { + return branchName ? `New worktree · ${branchName}` : "New worktree"; + } + return branchName ? `Current · ${branchName}` : "Current checkout"; +} + +function NewTaskToolbarTrigger(props: { + readonly icon?: ComponentProps["name"]; + readonly iconNode?: ReactNode; + readonly label?: string; + readonly accessibilityLabel?: string; + readonly onPress?: () => void; + readonly showChevron?: boolean; +}) { + const iconColor = useThemeColor("--color-icon"); + + return ( + + {props.iconNode ? ( + {props.iconNode} + ) : props.icon ? ( + + ) : null} + {props.label ? ( + + {props.label} + + ) : null} + {props.showChevron === false ? null : ( + + )} + + ); +} + export function NewTaskDraftScreen(props: { readonly initialProjectRef?: { readonly environmentId?: string; @@ -45,11 +122,20 @@ export function NewTaskDraftScreen(props: { const flow = useNewTaskFlow(); const router = useRouter(); const insets = useSafeAreaInsets(); + const colorScheme = useColorScheme(); const isKeyboardVisible = useKeyboardState((state) => state.isVisible); const controlsBottomPadding = isKeyboardVisible ? 8 : Math.max(insets.bottom, 10); const { logicalProjects, selectedProject, setProject } = flow; + const promptInputRef = useRef(null); + const [toolbarMetrics, setToolbarMetrics] = useState({ + contentWidth: 0, + offsetX: 0, + viewportWidth: 0, + }); const borderColor = useThemeColor("--color-border"); + const sheetFadeOpaque = colorScheme === "dark" ? "rgba(14,14,14,0.98)" : "rgba(242,242,247,0.98)"; + const sheetFadeTransparent = colorScheme === "dark" ? "rgba(14,14,14,0)" : "rgba(242,242,247,0)"; useEffect(() => { if (props.initialProjectRef?.environmentId && props.initialProjectRef?.projectId) { @@ -93,6 +179,24 @@ export function NewTaskDraftScreen(props: { void flow.loadBranches(); }, [flow, selectedProject]); + useEffect(() => { + if (!selectedProject) { + return; + } + + let focusFrame: ReturnType | null = null; + const interaction = InteractionManager.runAfterInteractions(() => { + focusFrame = requestAnimationFrame(() => promptInputRef.current?.focus()); + }); + + return () => { + interaction.cancel(); + if (focusFrame !== null) { + cancelAnimationFrame(focusFrame); + } + }; + }, [selectedProject]); + const environmentMenuActions = useMemo( () => flow.environments.map((environment) => ({ @@ -231,10 +335,10 @@ export function NewTaskDraftScreen(props: { { id: "workspace:mode", title: "Mode", - subtitle: flow.workspaceMode === "local" ? "Local" : "Worktree", + subtitle: flow.workspaceMode === "local" ? "Current checkout" : "New worktree", subactions: (["local", "worktree"] as const).map((value) => ({ id: `workspace:mode:${value}`, - title: value === "local" ? "Local" : "Worktree", + title: value === "local" ? "Current checkout" : "New worktree", state: flow.workspaceMode === value ? ("on" as const) : undefined, })), }, @@ -253,6 +357,56 @@ export function NewTaskDraftScreen(props: { flow.workspaceMode, ]); + const selectedEnvironmentLabel = + flow.environments.find( + (environment) => environment.environmentId === flow.selectedEnvironmentId, + )?.environmentLabel ?? "Environment"; + const currentBranchName = + flow.availableBranches.find((branch) => branch.current)?.name ?? + flow.availableBranches.find((branch) => branch.isDefault)?.name ?? + null; + const configurationLabel = useMemo(() => { + const parts = [ + formatTitleCase(flow.effort), + flow.fastMode ? "Fast" : null, + flow.contextWindow !== "1M" ? flow.contextWindow : null, + ].filter((part): part is string => Boolean(part)); + return parts.length > 0 ? parts.join(" · ") : "Configuration"; + }, [flow.contextWindow, flow.effort, flow.fastMode]); + const workspaceLabel = useMemo( + () => + formatWorkspaceLabel({ + currentBranchName, + selectedBranchName: flow.selectedBranchName, + workspaceMode: flow.workspaceMode, + }), + [currentBranchName, flow.selectedBranchName, flow.workspaceMode], + ); + const toolbarScrollEdges = useMemo(() => { + const maxOffset = Math.max(0, toolbarMetrics.contentWidth - toolbarMetrics.viewportWidth); + return { + showLeftFade: toolbarMetrics.offsetX > TOOLBAR_SCROLL_EPSILON, + showRightFade: toolbarMetrics.offsetX < maxOffset - TOOLBAR_SCROLL_EPSILON, + }; + }, [toolbarMetrics]); + const handleToolbarLayout = useCallback((event: LayoutChangeEvent) => { + const viewportWidth = event.nativeEvent.layout.width; + setToolbarMetrics((current) => + current.viewportWidth === viewportWidth ? current : { ...current, viewportWidth }, + ); + }, []); + const handleToolbarContentSizeChange = useCallback((contentWidth: number) => { + setToolbarMetrics((current) => + current.contentWidth === contentWidth ? current : { ...current, contentWidth }, + ); + }, []); + const handleToolbarScroll = useCallback((event: NativeSyntheticEvent) => { + const offsetX = event.nativeEvent.contentOffset.x; + setToolbarMetrics((current) => + Math.abs(current.offsetX - offsetX) < 1 ? current : { ...current, offsetX }, + ); + }, []); + function handleModelMenuAction(event: string) { if (!event.startsWith("model:")) { return; @@ -408,24 +562,27 @@ export function NewTaskDraftScreen(props: { } /> - - void handleNativePaste(payload)} - style={{ flex: 1 }} - > - - - + + + void handleNativePaste(payload)} + style={{ flex: 1, minHeight: 0 }} + > + + + - ) : null} - - void handlePickImages()} /> - handleModelMenuAction(nativeEvent.event)} - > - - } - /> - - handleOptionsMenuAction(nativeEvent.event)} - > - - - handleEnvironmentMenuAction(nativeEvent.event)} - > - - - handleWorkspaceMenuAction(nativeEvent.event)} - > - - + + + + void handlePickImages()} /> + handleModelMenuAction(nativeEvent.event)} + > + + } + label={flow.selectedModelOption?.label ?? "Model"} + /> + + handleOptionsMenuAction(nativeEvent.event)} + > + + + + handleEnvironmentMenuAction(nativeEvent.event) + } + > + + + handleWorkspaceMenuAction(nativeEvent.event)} + > + + + + {toolbarScrollEdges.showLeftFade ? ( + + ) : null} + {toolbarScrollEdges.showRightFade ? ( + + ) : null} + void handleStart()} variant="primary" disabled={ @@ -488,7 +705,7 @@ export function NewTaskDraftScreen(props: { /> - + ); }