Refine mobile composer and sheet controls
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
7c7fa6e6c0
commit
1bb073742b
29 files changed
+919
-869
No files matched your search
@@ -10,7 +10,7 @@ import { StatusBar, useColorScheme } from "react-native";
|
||||
import { GestureHandlerRootView } from "react-native-gesture-handler";
|
||||
import { KeyboardProvider } from "react-native-keyboard-controller";
|
||||
import { SafeAreaProvider } from "react-native-safe-area-context";
|
||||
import { useCSSVariable, useResolveClassNames } from "uniwind";
|
||||
import { useResolveClassNames } from "uniwind";
|
||||
|
||||
import { LoadingScreen } from "../components/LoadingScreen";
|
||||
|
||||
@@ -26,7 +26,7 @@ import { useAgentNotificationNavigation } from "../features/agent-awareness/noti
|
||||
function AppNavigator() {
|
||||
const { isLoadingSavedConnection } = useRemoteEnvironmentState();
|
||||
const colorScheme = useColorScheme();
|
||||
const statusBarBg = useCSSVariable("--color-status-bar");
|
||||
const statusBarBg = colorScheme === "dark" ? "#0a0a0a" : "#f2f2f7";
|
||||
const sheetStyle = useResolveClassNames("bg-sheet");
|
||||
useAgentNotificationNavigation();
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import Stack from "expo-router/stack";
|
||||
import { useColorScheme } from "react-native";
|
||||
import { useResolveClassNames } from "uniwind";
|
||||
|
||||
import { useThemeColor } from "../../lib/useThemeColor";
|
||||
|
||||
export const unstable_settings = {
|
||||
anchor: "index",
|
||||
};
|
||||
|
||||
export default function ConnectionsLayout() {
|
||||
const contentStyle = useResolveClassNames("bg-sheet");
|
||||
const connSheetBg = String(useThemeColor("--color-sheet"));
|
||||
const headerTint = String(useThemeColor("--color-icon"));
|
||||
const isDark = useColorScheme() === "dark";
|
||||
const connSheetBg = isDark ? "rgba(14, 14, 14, 0.98)" : "rgba(242, 242, 247, 0.98)";
|
||||
const headerTint = isDark ? "#f5f5f5" : "#262626";
|
||||
|
||||
return (
|
||||
<Stack
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Link, Stack } from "expo-router";
|
||||
import { Stack, useRouter } from "expo-router";
|
||||
import { SymbolView } from "expo-symbols";
|
||||
import type { EnvironmentId } from "@t3tools/contracts";
|
||||
import { useCallback, useState } from "react";
|
||||
import { Pressable, ScrollView, View } from "react-native";
|
||||
import { ScrollView, View } from "react-native";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { useThemeColor } from "../../lib/useThemeColor";
|
||||
|
||||
@@ -18,12 +18,12 @@ export default function ConnectionsRouteScreen() {
|
||||
onRemoveEnvironmentPress,
|
||||
onUpdateEnvironment,
|
||||
} = useRemoteConnections();
|
||||
const router = useRouter();
|
||||
const insets = useSafeAreaInsets();
|
||||
const hasEnvironments = connectedEnvironments.length > 0;
|
||||
const [expandedId, setExpandedId] = useState<EnvironmentId | null>(null);
|
||||
|
||||
const accentColor = useThemeColor("--color-icon-muted");
|
||||
const iconColor = useThemeColor("--color-icon");
|
||||
|
||||
const handleToggle = useCallback((environmentId: EnvironmentId) => {
|
||||
setExpandedId((prev) => (prev === environmentId ? null : environmentId));
|
||||
@@ -34,25 +34,15 @@ export default function ConnectionsRouteScreen() {
|
||||
<Stack.Screen
|
||||
options={{
|
||||
title: "Environments",
|
||||
headerRight: () => (
|
||||
<Link href="/connections/new" asChild>
|
||||
<Pressable
|
||||
accessibilityLabel="Add environment"
|
||||
accessibilityRole="button"
|
||||
className="h-10 w-10 items-center justify-center active:opacity-70"
|
||||
>
|
||||
<SymbolView
|
||||
name="plus"
|
||||
size={18}
|
||||
tintColor={iconColor}
|
||||
type="monochrome"
|
||||
weight="semibold"
|
||||
/>
|
||||
</Pressable>
|
||||
</Link>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Stack.Toolbar placement="right">
|
||||
<Stack.Toolbar.Button
|
||||
icon="plus"
|
||||
onPress={() => router.push("/connections/new")}
|
||||
separateBackground
|
||||
/>
|
||||
</Stack.Toolbar>
|
||||
<ScrollView
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
showsVerticalScrollIndicator={false}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { CameraView, useCameraPermissions } from "expo-camera";
|
||||
import { Stack, useLocalSearchParams, useRouter } from "expo-router";
|
||||
import { SymbolView } from "expo-symbols";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { Alert, Pressable, ScrollView, View } from "react-native";
|
||||
import { Alert, ScrollView, View } from "react-native";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { useThemeColor } from "../../lib/useThemeColor";
|
||||
|
||||
@@ -31,7 +30,6 @@ export default function ConnectionsNewRouteScreen() {
|
||||
const [cameraPermission, requestCameraPermission] = useCameraPermissions();
|
||||
const [scannerLocked, setScannerLocked] = useState(false);
|
||||
|
||||
const textColor = useThemeColor("--color-icon");
|
||||
const placeholderColor = useThemeColor("--color-placeholder");
|
||||
|
||||
const connectDisabled = isSubmitting || hostInput.trim().length === 0;
|
||||
@@ -128,30 +126,21 @@ export default function ConnectionsNewRouteScreen() {
|
||||
<Stack.Screen
|
||||
options={{
|
||||
title: showScanner ? "Scan QR Code" : "Add Environment",
|
||||
headerRight: () => (
|
||||
<Pressable
|
||||
accessibilityLabel={showScanner ? "Close QR scanner" : "Scan pairing QR code"}
|
||||
accessibilityRole="button"
|
||||
className="h-10 w-10 items-center justify-center active:opacity-70"
|
||||
onPress={() => {
|
||||
if (showScanner) {
|
||||
closeScanner();
|
||||
} else {
|
||||
void openScanner();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<SymbolView
|
||||
name={showScanner ? "xmark" : "qrcode.viewfinder"}
|
||||
size={showScanner ? 14 : 18}
|
||||
tintColor={textColor}
|
||||
type="monochrome"
|
||||
weight="semibold"
|
||||
/>
|
||||
</Pressable>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Stack.Toolbar placement="right">
|
||||
<Stack.Toolbar.Button
|
||||
icon={showScanner ? "xmark" : "qrcode.viewfinder"}
|
||||
onPress={() => {
|
||||
if (showScanner) {
|
||||
closeScanner();
|
||||
} else {
|
||||
void openScanner();
|
||||
}
|
||||
}}
|
||||
separateBackground
|
||||
/>
|
||||
</Stack.Toolbar>
|
||||
|
||||
<ScrollView
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Stack, useRouter } from "expo-router";
|
||||
import { useState } from "react";
|
||||
import { Text as RNText, View, useColorScheme } from "react-native";
|
||||
import { useThemeColor } from "../lib/useThemeColor";
|
||||
|
||||
import { buildThreadRoutePath } from "../lib/routes";
|
||||
import { useRemoteCatalog } from "../state/use-remote-catalog";
|
||||
@@ -17,7 +16,7 @@ export default function HomeRouteScreen() {
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
|
||||
const isDark = useColorScheme() === "dark";
|
||||
const iconColor = String(useThemeColor("--color-icon"));
|
||||
const iconColor = isDark ? "#f5f5f5" : "#262626";
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Stack from "expo-router/stack";
|
||||
import { useColorScheme } from "react-native";
|
||||
import { useResolveClassNames } from "uniwind";
|
||||
|
||||
import { NewTaskFlowProvider } from "../../features/threads/new-task-flow-provider";
|
||||
@@ -9,20 +10,41 @@ export const unstable_settings = {
|
||||
|
||||
export default function NewTaskLayout() {
|
||||
const sheetStyle = useResolveClassNames("bg-sheet");
|
||||
const isDark = useColorScheme() === "dark";
|
||||
const sheetBg = isDark ? "rgba(14, 14, 14, 0.98)" : "rgba(242, 242, 247, 0.98)";
|
||||
const headerTint = isDark ? "#f5f5f5" : "#262626";
|
||||
|
||||
return (
|
||||
<NewTaskFlowProvider>
|
||||
<Stack
|
||||
screenOptions={{
|
||||
contentStyle: sheetStyle,
|
||||
headerBackButtonDisplayMode: "minimal",
|
||||
headerLargeTitle: false,
|
||||
headerShadowVisible: false,
|
||||
headerStyle: { backgroundColor: sheetBg },
|
||||
headerTintColor: headerTint,
|
||||
headerTitleStyle: { fontFamily: "DMSans_700Bold" },
|
||||
}}
|
||||
>
|
||||
<Stack.Screen name="index" options={{ animation: "none" }} />
|
||||
<Stack.Screen name="index" options={{ animation: "none", title: "Choose project" }} />
|
||||
<Stack.Screen
|
||||
name="add-project"
|
||||
options={{ animation: "slide_from_right", headerShown: false }}
|
||||
name="add-project/index"
|
||||
options={{ animation: "slide_from_right", title: "New project" }}
|
||||
/>
|
||||
<Stack.Screen name="draft" options={{ animation: "slide_from_right" }} />
|
||||
<Stack.Screen
|
||||
name="add-project/repository"
|
||||
options={{ animation: "slide_from_right", title: "Repository" }}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="add-project/destination"
|
||||
options={{ animation: "slide_from_right", title: "Clone destination" }}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="add-project/local"
|
||||
options={{ animation: "slide_from_right", title: "Local folder" }}
|
||||
/>
|
||||
<Stack.Screen name="draft" options={{ animation: "slide_from_right", title: "New task" }} />
|
||||
</Stack>
|
||||
</NewTaskFlowProvider>
|
||||
);
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import { Stack } from "expo-router";
|
||||
import { useThemeColor } from "../../../lib/useThemeColor";
|
||||
|
||||
export default function AddProjectLayout() {
|
||||
const sheetStyle = {
|
||||
backgroundColor: useThemeColor("--color-sheet"),
|
||||
};
|
||||
|
||||
return (
|
||||
<Stack screenOptions={{ headerShown: false, contentStyle: sheetStyle }}>
|
||||
<Stack.Screen name="index" options={{ animation: "slide_from_right" }} />
|
||||
<Stack.Screen name="repository" options={{ animation: "slide_from_right" }} />
|
||||
<Stack.Screen name="destination" options={{ animation: "slide_from_right" }} />
|
||||
<Stack.Screen name="local" options={{ animation: "slide_from_right" }} />
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
import { Stack } from "expo-router";
|
||||
|
||||
import { AddProjectDestinationScreen } from "../../../features/projects/AddProjectScreen";
|
||||
|
||||
export default function AddProjectDestinationRoute() {
|
||||
return (
|
||||
<>
|
||||
<Stack.Screen options={{ headerShown: false }} />
|
||||
<AddProjectDestinationScreen />
|
||||
</>
|
||||
);
|
||||
return <AddProjectDestinationScreen />;
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
import { Stack } from "expo-router";
|
||||
|
||||
import { AddProjectSourceScreen } from "../../../features/projects/AddProjectScreen";
|
||||
|
||||
export default function AddProjectRoute() {
|
||||
return (
|
||||
<>
|
||||
<Stack.Screen options={{ headerShown: false }} />
|
||||
<AddProjectSourceScreen />
|
||||
</>
|
||||
);
|
||||
return <AddProjectSourceScreen />;
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
import { Stack } from "expo-router";
|
||||
|
||||
import { AddProjectLocalFolderScreen } from "../../../features/projects/AddProjectScreen";
|
||||
|
||||
export default function AddProjectLocalRoute() {
|
||||
return (
|
||||
<>
|
||||
<Stack.Screen options={{ headerShown: false }} />
|
||||
<AddProjectLocalFolderScreen />
|
||||
</>
|
||||
);
|
||||
return <AddProjectLocalFolderScreen />;
|
||||
}
|
||||
@@ -1,11 +1,22 @@
|
||||
import { Stack } from "expo-router";
|
||||
import { Stack, useLocalSearchParams } from "expo-router";
|
||||
import { addProjectRemoteSourceLabel } from "@t3tools/client-runtime";
|
||||
|
||||
import { AddProjectRepositoryScreen } from "../../../features/projects/AddProjectScreen";
|
||||
|
||||
export default function AddProjectRepositoryRoute() {
|
||||
const params = useLocalSearchParams<{ source?: string | string[] }>();
|
||||
const source = Array.isArray(params.source) ? params.source[0] : params.source;
|
||||
const title =
|
||||
source === "github" ||
|
||||
source === "gitlab" ||
|
||||
source === "bitbucket" ||
|
||||
source === "azure-devops"
|
||||
? addProjectRemoteSourceLabel(source)
|
||||
: "Git URL";
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack.Screen options={{ headerShown: false }} />
|
||||
<Stack.Screen options={{ title }} />
|
||||
<AddProjectRepositoryScreen />
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -6,11 +6,16 @@ export default function NewTaskDraftRoute() {
|
||||
const params = useLocalSearchParams<{
|
||||
environmentId?: string | string[];
|
||||
projectId?: string | string[];
|
||||
title?: string | string[];
|
||||
}>();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack.Screen options={{ headerShown: false }} />
|
||||
<Stack.Screen
|
||||
options={{
|
||||
title: Array.isArray(params.title) ? params.title[0] : (params.title ?? "New task"),
|
||||
}}
|
||||
/>
|
||||
<NewTaskDraftScreen
|
||||
initialProjectRef={{
|
||||
environmentId: Array.isArray(params.environmentId)
|
||||
|
||||
@@ -8,7 +8,6 @@ import { useThemeColor } from "../../lib/useThemeColor";
|
||||
|
||||
import { AppText as Text } from "../../components/AppText";
|
||||
import { ProjectFavicon } from "../../components/ProjectFavicon";
|
||||
import { NewTaskSheetHeader } from "../../features/threads/NewTaskSheetHeader";
|
||||
import { groupProjectsByRepository } from "../../lib/repositoryGroups";
|
||||
import { type RemoteCatalogState, useRemoteCatalog } from "../../state/use-remote-catalog";
|
||||
import { useRemoteEnvironmentState } from "../../state/use-remote-environment-registry";
|
||||
@@ -102,9 +101,14 @@ export default function NewTaskRoute() {
|
||||
|
||||
return (
|
||||
<View collapsable={false} className="flex-1 bg-sheet">
|
||||
<Stack.Screen options={{ headerShown: false }} />
|
||||
|
||||
<NewTaskSheetHeader title="Choose project" />
|
||||
<Stack.Screen options={{ title: "Choose project" }} />
|
||||
<Stack.Toolbar placement="right">
|
||||
<Stack.Toolbar.Button
|
||||
icon="plus"
|
||||
onPress={() => router.push("/new/add-project")}
|
||||
separateBackground
|
||||
/>
|
||||
</Stack.Toolbar>
|
||||
|
||||
<ScrollView
|
||||
showsVerticalScrollIndicator={false}
|
||||
@@ -148,6 +152,7 @@ export default function NewTaskRoute() {
|
||||
<View collapsable={false} className="overflow-hidden rounded-[24px] bg-card">
|
||||
{items.map((item, index) => {
|
||||
const isFirst = index === 0;
|
||||
const isLast = index === items.length - 1;
|
||||
|
||||
return (
|
||||
<Link
|
||||
@@ -166,25 +171,33 @@ export default function NewTaskRoute() {
|
||||
className="bg-card"
|
||||
style={{
|
||||
paddingHorizontal: 16,
|
||||
paddingVertical: 18,
|
||||
paddingVertical: 14,
|
||||
borderTopWidth: isFirst ? 0 : 1,
|
||||
borderTopColor: borderSubtleColor,
|
||||
borderTopLeftRadius: isFirst ? 24 : 0,
|
||||
borderTopRightRadius: isFirst ? 24 : 0,
|
||||
borderBottomLeftRadius: 0,
|
||||
borderBottomRightRadius: 0,
|
||||
borderBottomLeftRadius: isLast ? 24 : 0,
|
||||
borderBottomRightRadius: isLast ? 24 : 0,
|
||||
}}
|
||||
>
|
||||
<View className="flex-row items-center justify-between gap-3">
|
||||
<ProjectFavicon
|
||||
size={22}
|
||||
projectTitle={item.title}
|
||||
httpBaseUrl={savedConnectionsById[item.environmentId]?.httpBaseUrl ?? null}
|
||||
workspaceRoot={item.workspaceRoot}
|
||||
bearerToken={savedConnectionsById[item.environmentId]?.bearerToken ?? null}
|
||||
/>
|
||||
<View className="h-7 w-7 items-center justify-center">
|
||||
<ProjectFavicon
|
||||
size={20}
|
||||
projectTitle={item.title}
|
||||
httpBaseUrl={
|
||||
savedConnectionsById[item.environmentId]?.httpBaseUrl ?? null
|
||||
}
|
||||
workspaceRoot={item.workspaceRoot}
|
||||
bearerToken={
|
||||
savedConnectionsById[item.environmentId]?.bearerToken ?? null
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
<View className="flex-1">
|
||||
<Text className="text-[18px] font-t3-bold">{item.title}</Text>
|
||||
<Text className="text-[16px] leading-[21px] font-t3-bold">
|
||||
{item.title}
|
||||
</Text>
|
||||
</View>
|
||||
<SymbolView
|
||||
name="chevron.right"
|
||||
@@ -197,33 +210,6 @@ export default function NewTaskRoute() {
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
<Pressable
|
||||
className="bg-card"
|
||||
style={{
|
||||
paddingHorizontal: 16,
|
||||
paddingVertical: 18,
|
||||
borderTopWidth: 1,
|
||||
borderTopColor: borderSubtleColor,
|
||||
borderBottomLeftRadius: 24,
|
||||
borderBottomRightRadius: 24,
|
||||
}}
|
||||
onPress={() => router.push("/new/add-project")}
|
||||
>
|
||||
<View className="flex-row items-center justify-between gap-3">
|
||||
<View className="h-[22px] w-[22px] items-center justify-center rounded-full bg-subtle">
|
||||
<SymbolView name="plus" size={13} tintColor={accentColor} type="monochrome" />
|
||||
</View>
|
||||
<View className="flex-1">
|
||||
<Text className="text-[18px] font-t3-bold">Add new project</Text>
|
||||
</View>
|
||||
<SymbolView
|
||||
name="chevron.right"
|
||||
size={14}
|
||||
tintColor={chevronColor}
|
||||
type="monochrome"
|
||||
/>
|
||||
</View>
|
||||
</Pressable>
|
||||
</View>
|
||||
)}
|
||||
</ScrollView>
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import Stack from "expo-router/stack";
|
||||
import { useColorScheme } from "react-native";
|
||||
import { useResolveClassNames } from "uniwind";
|
||||
|
||||
import { useThemeColor } from "../../lib/useThemeColor";
|
||||
|
||||
export const unstable_settings = {
|
||||
anchor: "index",
|
||||
};
|
||||
|
||||
export default function SettingsLayout() {
|
||||
const contentStyle = useResolveClassNames("bg-sheet");
|
||||
const sheetBg = String(useThemeColor("--color-sheet"));
|
||||
const headerTint = String(useThemeColor("--color-icon"));
|
||||
const isDark = useColorScheme() === "dark";
|
||||
const sheetBg = isDark ? "rgba(14, 14, 14, 0.98)" : "rgba(242, 242, 247, 0.98)";
|
||||
const headerTint = isDark ? "#f5f5f5" : "#262626";
|
||||
|
||||
return (
|
||||
<Stack
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useAuth } from "@clerk/expo";
|
||||
import { Link, Stack } from "expo-router";
|
||||
import { Stack, useRouter } from "expo-router";
|
||||
import { SymbolView } from "expo-symbols";
|
||||
import type { EnvironmentId } from "@t3tools/contracts";
|
||||
import type { RelayClientEnvironmentRecord } from "@t3tools/contracts/relay";
|
||||
@@ -35,11 +35,11 @@ export default function SettingsEnvironmentsRouteScreen() {
|
||||
onRemoveEnvironmentPress,
|
||||
onUpdateEnvironment,
|
||||
} = useRemoteConnections();
|
||||
const router = useRouter();
|
||||
const insets = useSafeAreaInsets();
|
||||
const hasEnvironments = connectedEnvironments.length > 0;
|
||||
const [expandedId, setExpandedId] = useState<EnvironmentId | null>(null);
|
||||
const accentColor = useThemeColor("--color-icon-muted");
|
||||
const iconColor = useThemeColor("--color-icon");
|
||||
|
||||
const handleToggle = useCallback((environmentId: EnvironmentId) => {
|
||||
setExpandedId((prev) => (prev === environmentId ? null : environmentId));
|
||||
@@ -50,25 +50,15 @@ export default function SettingsEnvironmentsRouteScreen() {
|
||||
<Stack.Screen
|
||||
options={{
|
||||
title: "Environments",
|
||||
headerRight: () => (
|
||||
<Link href="/settings/environment-new" asChild>
|
||||
<Pressable
|
||||
accessibilityLabel="Add environment"
|
||||
accessibilityRole="button"
|
||||
className="h-10 w-10 items-center justify-center active:opacity-70"
|
||||
>
|
||||
<SymbolView
|
||||
name="plus"
|
||||
size={18}
|
||||
tintColor={iconColor}
|
||||
type="monochrome"
|
||||
weight="semibold"
|
||||
/>
|
||||
</Pressable>
|
||||
</Link>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Stack.Toolbar placement="right">
|
||||
<Stack.Toolbar.Button
|
||||
icon="plus"
|
||||
onPress={() => router.push("/settings/environment-new")}
|
||||
separateBackground
|
||||
/>
|
||||
</Stack.Toolbar>
|
||||
<ScrollView
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
showsVerticalScrollIndicator={false}
|
||||
|
||||
@@ -17,6 +17,7 @@ export default function ThreadLayout() {
|
||||
headerShown: true,
|
||||
headerTransparent: true,
|
||||
headerShadowVisible: false,
|
||||
headerTitle: "",
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
import { SymbolView } from "expo-symbols";
|
||||
import type { ComponentProps, ReactNode } from "react";
|
||||
import { useCallback, useMemo, useState } from "react";
|
||||
import {
|
||||
Pressable,
|
||||
ScrollView,
|
||||
View,
|
||||
useColorScheme,
|
||||
type LayoutChangeEvent,
|
||||
type NativeScrollEvent,
|
||||
type NativeSyntheticEvent,
|
||||
type StyleProp,
|
||||
type ViewStyle,
|
||||
} from "react-native";
|
||||
|
||||
import { useThemeColor } from "../lib/useThemeColor";
|
||||
import { cn } from "../lib/cn";
|
||||
import { AppText as Text } from "./AppText";
|
||||
|
||||
export const COMPOSER_TOOLBAR_CONTROL_HEIGHT = 44;
|
||||
export const COMPOSER_TOOLBAR_GAP = 8;
|
||||
export const COMPOSER_TOOLBAR_FADE_WIDTH = 18;
|
||||
const COMPOSER_TOOLBAR_SCROLL_EPSILON = 4;
|
||||
|
||||
export function ComposerToolbarRow(props: {
|
||||
readonly children: ReactNode;
|
||||
readonly paddingBottom?: number;
|
||||
readonly paddingHorizontal?: number;
|
||||
readonly paddingTop?: number;
|
||||
readonly style?: StyleProp<ViewStyle>;
|
||||
}) {
|
||||
return (
|
||||
<View
|
||||
style={[
|
||||
{
|
||||
alignItems: "center",
|
||||
flexDirection: "row",
|
||||
gap: 6,
|
||||
paddingBottom: props.paddingBottom ?? 8,
|
||||
paddingHorizontal: props.paddingHorizontal ?? 6,
|
||||
paddingTop: props.paddingTop ?? 8,
|
||||
},
|
||||
props.style,
|
||||
]}
|
||||
>
|
||||
{props.children}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function ComposerToolbarScroller(props: {
|
||||
readonly children: ReactNode;
|
||||
readonly fadeOpaque: string;
|
||||
readonly fadeTransparent: string;
|
||||
readonly contentPaddingRight?: number;
|
||||
}) {
|
||||
const [metrics, setMetrics] = useState({
|
||||
contentWidth: 0,
|
||||
offsetX: 0,
|
||||
viewportWidth: 0,
|
||||
});
|
||||
|
||||
const scrollEdges = useMemo(() => {
|
||||
const maxOffset = Math.max(0, metrics.contentWidth - metrics.viewportWidth);
|
||||
return {
|
||||
showLeftFade: metrics.offsetX > COMPOSER_TOOLBAR_SCROLL_EPSILON,
|
||||
showRightFade: metrics.offsetX < maxOffset - COMPOSER_TOOLBAR_SCROLL_EPSILON,
|
||||
};
|
||||
}, [metrics]);
|
||||
|
||||
const handleLayout = useCallback((event: LayoutChangeEvent) => {
|
||||
const viewportWidth = event.nativeEvent.layout.width;
|
||||
setMetrics((current) =>
|
||||
current.viewportWidth === viewportWidth ? current : { ...current, viewportWidth },
|
||||
);
|
||||
}, []);
|
||||
|
||||
const handleContentSizeChange = useCallback((contentWidth: number) => {
|
||||
setMetrics((current) =>
|
||||
current.contentWidth === contentWidth ? current : { ...current, contentWidth },
|
||||
);
|
||||
}, []);
|
||||
|
||||
const handleScroll = useCallback((event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
||||
const offsetX = event.nativeEvent.contentOffset.x;
|
||||
setMetrics((current) =>
|
||||
Math.abs(current.offsetX - offsetX) < 1 ? current : { ...current, offsetX },
|
||||
);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<View className="min-w-0 flex-1" style={{ position: "relative" }}>
|
||||
<ScrollView
|
||||
horizontal
|
||||
keyboardShouldPersistTaps="always"
|
||||
onContentSizeChange={handleContentSizeChange}
|
||||
onLayout={handleLayout}
|
||||
onScroll={handleScroll}
|
||||
scrollEventThrottle={16}
|
||||
showsHorizontalScrollIndicator={false}
|
||||
contentContainerStyle={{
|
||||
alignItems: "center",
|
||||
gap: COMPOSER_TOOLBAR_GAP,
|
||||
paddingLeft: 0,
|
||||
paddingRight: props.contentPaddingRight ?? 1,
|
||||
}}
|
||||
>
|
||||
{props.children}
|
||||
</ScrollView>
|
||||
{scrollEdges.showLeftFade ? (
|
||||
<View
|
||||
pointerEvents="none"
|
||||
style={{
|
||||
bottom: 0,
|
||||
experimental_backgroundImage: `linear-gradient(to right, ${props.fadeOpaque} 0%, ${props.fadeTransparent} 100%)`,
|
||||
left: 0,
|
||||
position: "absolute",
|
||||
top: 0,
|
||||
width: COMPOSER_TOOLBAR_FADE_WIDTH,
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
{scrollEdges.showRightFade ? (
|
||||
<View
|
||||
pointerEvents="none"
|
||||
style={{
|
||||
bottom: 0,
|
||||
experimental_backgroundImage: `linear-gradient(to right, ${props.fadeTransparent} 0%, ${props.fadeOpaque} 100%)`,
|
||||
position: "absolute",
|
||||
right: 0,
|
||||
top: 0,
|
||||
width: COMPOSER_TOOLBAR_FADE_WIDTH,
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function ComposerToolbarButton(props: {
|
||||
readonly icon?: ComponentProps<typeof SymbolView>["name"];
|
||||
readonly iconNode?: ReactNode;
|
||||
readonly label?: string;
|
||||
readonly accessibilityLabel?: string;
|
||||
readonly active?: boolean;
|
||||
readonly disabled?: boolean;
|
||||
readonly maxWidth?: number;
|
||||
readonly minWidth?: number;
|
||||
readonly onPress?: () => void;
|
||||
readonly showChevron?: boolean;
|
||||
readonly textTransform?: "none" | "uppercase";
|
||||
readonly variant?: "default" | "primary" | "danger";
|
||||
readonly style?: StyleProp<ViewStyle>;
|
||||
}) {
|
||||
const isDarkMode = useColorScheme() === "dark";
|
||||
const iconColor = useThemeColor("--color-icon");
|
||||
const iconSubtle = useThemeColor("--color-icon-subtle");
|
||||
const primaryFg = useThemeColor("--color-primary-foreground");
|
||||
const dangerFg = useThemeColor("--color-danger-foreground");
|
||||
const variant = props.variant ?? "default";
|
||||
const isCircle = !props.label && props.showChevron === false;
|
||||
const defaultBorderColor = isDarkMode ? "rgba(255,255,255,0.08)" : "rgba(0,0,0,0.06)";
|
||||
const activeBorderColor = isDarkMode ? "rgba(255,255,255,0.13)" : "rgba(0,0,0,0.1)";
|
||||
const filledBorderColor =
|
||||
variant === "danger"
|
||||
? "rgba(255,255,255,0.14)"
|
||||
: props.disabled
|
||||
? defaultBorderColor
|
||||
: "rgba(255,255,255,0.18)";
|
||||
const iconTintColor =
|
||||
variant === "primary"
|
||||
? props.disabled
|
||||
? iconSubtle
|
||||
: primaryFg
|
||||
: variant === "danger"
|
||||
? dangerFg
|
||||
: iconColor;
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
accessibilityLabel={props.accessibilityLabel ?? props.label}
|
||||
accessibilityRole="button"
|
||||
disabled={props.disabled}
|
||||
onPress={props.onPress}
|
||||
className={cn(
|
||||
"h-11 flex-row items-center justify-center rounded-full active:opacity-70",
|
||||
isCircle ? "w-11" : "gap-2 px-3.5",
|
||||
variant === "primary"
|
||||
? props.disabled
|
||||
? "bg-subtle-strong"
|
||||
: "bg-primary"
|
||||
: variant === "danger"
|
||||
? "bg-danger"
|
||||
: props.active
|
||||
? "bg-subtle-strong"
|
||||
: "bg-subtle",
|
||||
)}
|
||||
style={({ pressed }) => [
|
||||
{
|
||||
borderColor:
|
||||
variant === "default"
|
||||
? props.active
|
||||
? activeBorderColor
|
||||
: defaultBorderColor
|
||||
: filledBorderColor,
|
||||
borderWidth: 1,
|
||||
maxWidth: props.maxWidth ?? 172,
|
||||
minWidth: props.minWidth,
|
||||
opacity: props.disabled ? 0.55 : pressed ? 0.72 : 1,
|
||||
shadowColor: "#000",
|
||||
shadowOffset: { width: 0, height: isDarkMode ? 3 : 2 },
|
||||
shadowOpacity: props.disabled ? 0 : isDarkMode ? 0.24 : 0.08,
|
||||
shadowRadius: isDarkMode ? 10 : 8,
|
||||
},
|
||||
props.style,
|
||||
]}
|
||||
>
|
||||
{props.iconNode ? (
|
||||
<View className="h-4 w-4 items-center justify-center">{props.iconNode}</View>
|
||||
) : props.icon ? (
|
||||
<SymbolView name={props.icon} size={16} tintColor={iconTintColor} type="monochrome" />
|
||||
) : null}
|
||||
{props.label ? (
|
||||
<Text
|
||||
className={cn(
|
||||
"shrink text-center text-[13px] font-t3-bold",
|
||||
variant === "primary"
|
||||
? props.disabled
|
||||
? "text-foreground-muted"
|
||||
: "text-primary-foreground"
|
||||
: "text-foreground",
|
||||
)}
|
||||
ellipsizeMode="tail"
|
||||
numberOfLines={1}
|
||||
style={{ textTransform: props.textTransform ?? "none" }}
|
||||
>
|
||||
{props.label}
|
||||
</Text>
|
||||
) : null}
|
||||
{props.showChevron === false ? null : (
|
||||
<SymbolView name="chevron.down" size={11} tintColor={iconTintColor} type="monochrome" />
|
||||
)}
|
||||
</Pressable>
|
||||
);
|
||||
}
|
||||
|
||||
export const ComposerToolbarTrigger = ComposerToolbarButton;
|
||||
@@ -5,10 +5,14 @@ import { useThemeColor } from "../lib/useThemeColor";
|
||||
import { AppText as Text } from "./AppText";
|
||||
import { BrandMark } from "./BrandMark";
|
||||
|
||||
export function LoadingScreen(props: { readonly message: string }) {
|
||||
export function LoadingScreen(props: {
|
||||
readonly message: string;
|
||||
readonly messagePlacement?: "above-spinner" | "below-spinner";
|
||||
}) {
|
||||
const colorScheme = useColorScheme();
|
||||
const screenBg = useThemeColor("--color-screen");
|
||||
const insets = useSafeAreaInsets();
|
||||
const messagePlacement = props.messagePlacement ?? "below-spinner";
|
||||
|
||||
return (
|
||||
<View className="flex-1 bg-screen" style={{ paddingTop: insets.top }}>
|
||||
@@ -19,8 +23,13 @@ export function LoadingScreen(props: { readonly message: string }) {
|
||||
/>
|
||||
<View className="flex-1 items-center justify-center gap-5 px-6">
|
||||
<BrandMark compact />
|
||||
{messagePlacement === "above-spinner" ? (
|
||||
<Text className="font-t3-bold text-lg text-foreground">{props.message}</Text>
|
||||
) : null}
|
||||
<ActivityIndicator size="large" />
|
||||
<Text className="font-t3-bold text-lg text-foreground">{props.message}</Text>
|
||||
{messagePlacement === "below-spinner" ? (
|
||||
<Text className="font-t3-bold text-lg text-foreground">{props.message}</Text>
|
||||
) : null}
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
|
||||
@@ -41,7 +41,6 @@ import {
|
||||
refreshSourceControlDiscoveryForEnvironment,
|
||||
useSourceControlDiscovery,
|
||||
} from "../../state/use-source-control-discovery";
|
||||
import { NewTaskSheetHeader } from "../threads/NewTaskSheetHeader";
|
||||
|
||||
interface EnvironmentOption {
|
||||
readonly environmentId: EnvironmentId;
|
||||
@@ -105,25 +104,11 @@ function SectionTitle(props: { readonly children: string }) {
|
||||
);
|
||||
}
|
||||
|
||||
function AddProjectShell(props: {
|
||||
readonly title: string;
|
||||
readonly closeToNew?: boolean;
|
||||
readonly children: ReactNode;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
function AddProjectShell(props: { readonly children: ReactNode }) {
|
||||
const insets = useSafeAreaInsets();
|
||||
|
||||
return (
|
||||
<View className="flex-1 bg-sheet">
|
||||
<NewTaskSheetHeader
|
||||
eyebrow="New project"
|
||||
title={props.title}
|
||||
control={{
|
||||
icon: props.closeToNew ? "xmark" : "chevron.left",
|
||||
onPress: () => router.back(),
|
||||
}}
|
||||
/>
|
||||
|
||||
<ScrollView
|
||||
keyboardShouldPersistTaps="handled"
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
@@ -179,9 +164,9 @@ function ListRow(props: {
|
||||
{props.icon}
|
||||
</View>
|
||||
<View className="flex-1 gap-0.5">
|
||||
<Text className="text-[15px] font-t3-bold">{props.title}</Text>
|
||||
<Text className="text-[16px] leading-[21px] font-t3-bold">{props.title}</Text>
|
||||
{props.subtitle ? (
|
||||
<Text className="text-[12px] leading-[16px] text-foreground-muted" numberOfLines={2}>
|
||||
<Text className="text-[13px] leading-[17px] text-foreground-muted" numberOfLines={2}>
|
||||
{props.subtitle}
|
||||
</Text>
|
||||
) : null}
|
||||
@@ -363,7 +348,7 @@ export function AddProjectSourceScreen() {
|
||||
}, [selectedEnvironment]);
|
||||
|
||||
return (
|
||||
<AddProjectShell title="Select source" closeToNew>
|
||||
<AddProjectShell>
|
||||
{environmentOptions.length === 0 ? <EmptyEnvironmentState /> : null}
|
||||
|
||||
{environmentOptions.length > 1 ? (
|
||||
@@ -561,7 +546,7 @@ export function AddProjectRepositoryScreen() {
|
||||
}, [environment, isSubmitting, repositoryInput, router, source]);
|
||||
|
||||
return (
|
||||
<AddProjectShell title={source === "url" ? "Git URL" : addProjectRemoteSourceLabel(source)}>
|
||||
<AddProjectShell>
|
||||
{error ? <ErrorBanner message={error} /> : null}
|
||||
<TextInput
|
||||
className="h-12 min-h-12 rounded-[24px] px-4 py-0 text-[15px] leading-[20px]"
|
||||
@@ -711,7 +696,7 @@ export function AddProjectLocalFolderScreen() {
|
||||
}, [createProject, environment, isSubmitting, pathInput]);
|
||||
|
||||
return (
|
||||
<AddProjectShell title="Local folder">
|
||||
<AddProjectShell>
|
||||
{error ? <ErrorBanner message={error} /> : null}
|
||||
{environment ? (
|
||||
<>
|
||||
@@ -790,7 +775,7 @@ export function AddProjectDestinationScreen() {
|
||||
}, [createProject, environment, isSubmitting, pathInput, remoteUrl]);
|
||||
|
||||
return (
|
||||
<AddProjectShell title="Clone destination">
|
||||
<AddProjectShell>
|
||||
{error ? <ErrorBanner message={error} /> : null}
|
||||
{repositoryTitle ? (
|
||||
<View className="rounded-[24px] bg-card px-4 py-3">
|
||||
|
||||
@@ -8,16 +8,7 @@ import type { KnownTerminalSession } from "@t3tools/client-runtime";
|
||||
import { SymbolView } from "expo-symbols";
|
||||
import { Stack, useLocalSearchParams, useRouter } from "expo-router";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import {
|
||||
Pressable,
|
||||
ScrollView,
|
||||
Text as RNText,
|
||||
View,
|
||||
useColorScheme,
|
||||
type LayoutChangeEvent,
|
||||
type NativeScrollEvent,
|
||||
type NativeSyntheticEvent,
|
||||
} from "react-native";
|
||||
import { Pressable, Text as RNText, View, useColorScheme } from "react-native";
|
||||
import {
|
||||
KeyboardController,
|
||||
KeyboardEvents,
|
||||
@@ -25,6 +16,11 @@ import {
|
||||
useKeyboardState,
|
||||
} from "react-native-keyboard-controller";
|
||||
|
||||
import {
|
||||
ComposerToolbarButton,
|
||||
ComposerToolbarRow,
|
||||
ComposerToolbarScroller,
|
||||
} from "../../components/ComposerToolbarTrigger";
|
||||
import { EmptyState } from "../../components/EmptyState";
|
||||
import { GlassSurface } from "../../components/GlassSurface";
|
||||
import { LoadingScreen } from "../../components/LoadingScreen";
|
||||
@@ -79,7 +75,6 @@ import {
|
||||
const DEFAULT_TERMINAL_COLS = 80;
|
||||
const DEFAULT_TERMINAL_ROWS = 24;
|
||||
const TERMINAL_ACCESSORY_HEIGHT = 52;
|
||||
const TERMINAL_ACCESSORY_FADE_WIDTH = 18;
|
||||
|
||||
type PendingModifier = "ctrl" | "meta";
|
||||
type HostPlatform = "mac" | "linux" | "windows" | "unknown";
|
||||
@@ -94,47 +89,6 @@ type TerminalToolbarAction =
|
||||
readonly modifier: PendingModifier;
|
||||
};
|
||||
|
||||
function getTerminalStatusTone(input: {
|
||||
readonly status: TerminalMenuSession["status"];
|
||||
readonly hasRunningSubprocess?: boolean;
|
||||
}): {
|
||||
readonly tintColor: string;
|
||||
readonly textColor: string;
|
||||
} {
|
||||
if (input.status === "running") {
|
||||
if (input.hasRunningSubprocess) {
|
||||
return {
|
||||
tintColor: "#fbbf24",
|
||||
textColor: "#a3a3a3",
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
tintColor: "#34d399",
|
||||
textColor: "#a3a3a3",
|
||||
};
|
||||
}
|
||||
|
||||
if (input.status === "starting") {
|
||||
return {
|
||||
tintColor: "#f59e0b",
|
||||
textColor: "#a3a3a3",
|
||||
};
|
||||
}
|
||||
|
||||
if (input.status === "error") {
|
||||
return {
|
||||
tintColor: "#ef4444",
|
||||
textColor: "#fca5a5",
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
tintColor: "#ef4444",
|
||||
textColor: "#a3a3a3",
|
||||
};
|
||||
}
|
||||
|
||||
function firstRouteParam(value: string | string[] | undefined): string | null {
|
||||
if (Array.isArray(value)) {
|
||||
return value[0] ?? null;
|
||||
@@ -186,10 +140,6 @@ function applyCtrlModifier(input: string): string {
|
||||
return input;
|
||||
}
|
||||
|
||||
function withAlpha(hexColor: string, alpha: string): string {
|
||||
return /^#[0-9a-f]{6}$/i.test(hexColor) ? `${hexColor}${alpha}` : hexColor;
|
||||
}
|
||||
|
||||
function pickRunningTerminalSessionForBootstrap(
|
||||
sessions: ReadonlyArray<KnownTerminalSession>,
|
||||
): KnownTerminalSession | null {
|
||||
@@ -248,15 +198,6 @@ export function ThreadTerminalRouteScreen() {
|
||||
const [fontSize, setFontSize] = useState(cachedFontSize ?? DEFAULT_TERMINAL_FONT_SIZE);
|
||||
const [keyboardFocusRequest, setKeyboardFocusRequest] = useState(0);
|
||||
const [isAccessoryDismissed, setIsAccessoryDismissed] = useState(false);
|
||||
const toolbarScrollGeometryRef = useRef({
|
||||
contentWidth: 0,
|
||||
offsetX: 0,
|
||||
viewportWidth: 0,
|
||||
});
|
||||
const [toolbarScrollEdges, setToolbarScrollEdges] = useState({
|
||||
showLeftFade: false,
|
||||
showRightFade: false,
|
||||
});
|
||||
const hasOpenedRef = useRef(false);
|
||||
const bufferReplayTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const attachStreamLogCountRef = useRef(0);
|
||||
@@ -370,14 +311,6 @@ export function ThreadTerminalRouteScreen() {
|
||||
activeKnownSummary: activeKnownSession?.state.summary ?? null,
|
||||
};
|
||||
|
||||
const terminalStatusTone = useMemo(
|
||||
() =>
|
||||
getTerminalStatusTone({
|
||||
status: terminal.status,
|
||||
hasRunningSubprocess: terminal.hasRunningSubprocess,
|
||||
}),
|
||||
[terminal.hasRunningSubprocess, terminal.status],
|
||||
);
|
||||
const terminalTheme = getPierreTerminalTheme(appearanceScheme);
|
||||
const pendingModifier =
|
||||
pendingModifierState.terminalId === terminalId ? pendingModifierState.value : null;
|
||||
@@ -964,47 +897,6 @@ export function ThreadTerminalRouteScreen() {
|
||||
[handleClearTerminal, pendingModifier, terminalId, writeInput],
|
||||
);
|
||||
|
||||
const updateToolbarScrollEdges = useCallback(
|
||||
(patch: Partial<(typeof toolbarScrollGeometryRef)["current"]>) => {
|
||||
const nextGeometry = { ...toolbarScrollGeometryRef.current, ...patch };
|
||||
toolbarScrollGeometryRef.current = nextGeometry;
|
||||
const nextEdges = {
|
||||
showLeftFade: nextGeometry.offsetX > 1,
|
||||
showRightFade:
|
||||
nextGeometry.offsetX + nextGeometry.viewportWidth < nextGeometry.contentWidth - 1,
|
||||
};
|
||||
|
||||
setToolbarScrollEdges((current) =>
|
||||
current.showLeftFade === nextEdges.showLeftFade &&
|
||||
current.showRightFade === nextEdges.showRightFade
|
||||
? current
|
||||
: nextEdges,
|
||||
);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
const handleToolbarLayout = useCallback(
|
||||
(event: LayoutChangeEvent) => {
|
||||
updateToolbarScrollEdges({ viewportWidth: event.nativeEvent.layout.width });
|
||||
},
|
||||
[updateToolbarScrollEdges],
|
||||
);
|
||||
|
||||
const handleToolbarContentSizeChange = useCallback(
|
||||
(contentWidth: number) => {
|
||||
updateToolbarScrollEdges({ contentWidth });
|
||||
},
|
||||
[updateToolbarScrollEdges],
|
||||
);
|
||||
|
||||
const handleToolbarScroll = useCallback(
|
||||
(event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
||||
updateToolbarScrollEdges({ offsetX: event.nativeEvent.contentOffset.x });
|
||||
},
|
||||
[updateToolbarScrollEdges],
|
||||
);
|
||||
|
||||
const handleDismissKeyboard = useCallback(() => {
|
||||
setIsAccessoryDismissed(true);
|
||||
void KeyboardController.dismiss();
|
||||
@@ -1089,17 +981,7 @@ export function ThreadTerminalRouteScreen() {
|
||||
/>
|
||||
|
||||
<Stack.Toolbar placement="right">
|
||||
<Stack.Toolbar.Menu
|
||||
icon="circle.fill"
|
||||
style={{
|
||||
color: terminalStatusTone.textColor,
|
||||
fontFamily: "DMSans_700Bold",
|
||||
fontSize: 12,
|
||||
fontWeight: "700",
|
||||
}}
|
||||
tintColor={terminalStatusTone.tintColor}
|
||||
title="Terminal options"
|
||||
>
|
||||
<Stack.Toolbar.Menu icon="terminal" title="Terminal options" separateBackground>
|
||||
<Stack.Toolbar.Label>
|
||||
{getTerminalStatusLabel({
|
||||
status: terminal.status,
|
||||
@@ -1170,127 +1052,43 @@ export function ThreadTerminalRouteScreen() {
|
||||
borderTopColor: terminalTheme.border,
|
||||
borderTopWidth: 1,
|
||||
minHeight: TERMINAL_ACCESSORY_HEIGHT,
|
||||
paddingBottom: 4,
|
||||
paddingHorizontal: 8,
|
||||
paddingTop: 4,
|
||||
}}
|
||||
>
|
||||
<View style={{ alignItems: "center", flexDirection: "row", gap: 6 }}>
|
||||
<View style={{ flex: 1, position: "relative" }}>
|
||||
<ScrollView
|
||||
horizontal
|
||||
contentContainerStyle={{ alignItems: "center", gap: 6, paddingRight: 2 }}
|
||||
onContentSizeChange={handleToolbarContentSizeChange}
|
||||
onLayout={handleToolbarLayout}
|
||||
onScroll={handleToolbarScroll}
|
||||
scrollEventThrottle={16}
|
||||
showsHorizontalScrollIndicator={false}
|
||||
>
|
||||
{terminalToolbarActions.map((action) => {
|
||||
const active =
|
||||
action.kind === "modifier" && pendingModifier === action.modifier;
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
key={action.key}
|
||||
onPress={() => handleToolbarActionPress(action)}
|
||||
style={({ pressed }) => ({
|
||||
alignItems: "center",
|
||||
backgroundColor: active
|
||||
? withAlpha(
|
||||
terminalTheme.palette[10] ?? terminalTheme.foreground,
|
||||
"2e",
|
||||
)
|
||||
: pressed
|
||||
? withAlpha(terminalTheme.foreground, "1f")
|
||||
: withAlpha(terminalTheme.foreground, "12"),
|
||||
borderColor: active
|
||||
? withAlpha(
|
||||
terminalTheme.palette[10] ?? terminalTheme.foreground,
|
||||
"52",
|
||||
)
|
||||
: terminalTheme.border,
|
||||
borderRadius: 12,
|
||||
borderWidth: 1,
|
||||
justifyContent: "center",
|
||||
minWidth: action.label.length > 1 ? 46 : 38,
|
||||
paddingHorizontal: 11,
|
||||
paddingVertical: 8,
|
||||
})}
|
||||
>
|
||||
<RNText
|
||||
style={{
|
||||
color: active
|
||||
? (terminalTheme.palette[10] ?? terminalTheme.foreground)
|
||||
: terminalTheme.foreground,
|
||||
fontFamily: "DMSans_700Bold",
|
||||
fontSize: 12,
|
||||
fontWeight: "700",
|
||||
textTransform:
|
||||
action.kind === "modifier" || action.kind === "clear"
|
||||
? "uppercase"
|
||||
: "none",
|
||||
}}
|
||||
>
|
||||
{action.label}
|
||||
</RNText>
|
||||
</Pressable>
|
||||
);
|
||||
})}
|
||||
</ScrollView>
|
||||
{toolbarScrollEdges.showLeftFade ? (
|
||||
<View
|
||||
pointerEvents="none"
|
||||
style={{
|
||||
bottom: 0,
|
||||
experimental_backgroundImage: `linear-gradient(to right, ${terminalTheme.background} 0%, ${withAlpha(terminalTheme.background, "00")} 100%)`,
|
||||
left: 0,
|
||||
position: "absolute",
|
||||
top: 0,
|
||||
width: TERMINAL_ACCESSORY_FADE_WIDTH,
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
{toolbarScrollEdges.showRightFade ? (
|
||||
<View
|
||||
pointerEvents="none"
|
||||
style={{
|
||||
bottom: 0,
|
||||
experimental_backgroundImage: `linear-gradient(to right, ${withAlpha(terminalTheme.background, "00")} 0%, ${terminalTheme.background} 100%)`,
|
||||
position: "absolute",
|
||||
right: 0,
|
||||
top: 0,
|
||||
width: TERMINAL_ACCESSORY_FADE_WIDTH,
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
</View>
|
||||
<Pressable
|
||||
accessibilityLabel="Dismiss keyboard"
|
||||
accessibilityRole="button"
|
||||
onPress={handleDismissKeyboard}
|
||||
style={({ pressed }) => ({
|
||||
alignItems: "center",
|
||||
backgroundColor: pressed
|
||||
? withAlpha(terminalTheme.foreground, "1f")
|
||||
: withAlpha(terminalTheme.foreground, "12"),
|
||||
borderColor: terminalTheme.border,
|
||||
borderRadius: 12,
|
||||
borderWidth: 1,
|
||||
justifyContent: "center",
|
||||
minWidth: 38,
|
||||
paddingHorizontal: 11,
|
||||
paddingVertical: 8,
|
||||
})}
|
||||
<ComposerToolbarRow paddingBottom={4} paddingHorizontal={8} paddingTop={4}>
|
||||
<ComposerToolbarScroller
|
||||
contentPaddingRight={2}
|
||||
fadeOpaque={terminalTheme.background}
|
||||
fadeTransparent={`${terminalTheme.background}00`}
|
||||
>
|
||||
<SymbolView
|
||||
name={{ ios: "keyboard.chevron.compact.down", android: "keyboard_hide" }}
|
||||
size={14}
|
||||
tintColor={terminalTheme.foreground}
|
||||
type="monochrome"
|
||||
/>
|
||||
</Pressable>
|
||||
</View>
|
||||
{terminalToolbarActions.map((action) => {
|
||||
const active =
|
||||
action.kind === "modifier" && pendingModifier === action.modifier;
|
||||
|
||||
return (
|
||||
<ComposerToolbarButton
|
||||
key={action.key}
|
||||
active={active}
|
||||
label={action.label}
|
||||
maxWidth={120}
|
||||
minWidth={action.label.length > 1 ? 56 : 44}
|
||||
onPress={() => handleToolbarActionPress(action)}
|
||||
showChevron={false}
|
||||
textTransform={
|
||||
action.kind === "modifier" || action.kind === "clear"
|
||||
? "uppercase"
|
||||
: "none"
|
||||
}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</ComposerToolbarScroller>
|
||||
<ComposerToolbarButton
|
||||
accessibilityLabel="Dismiss keyboard"
|
||||
icon={{ ios: "keyboard.chevron.compact.down", android: "keyboard_hide" }}
|
||||
onPress={handleDismissKeyboard}
|
||||
showChevron={false}
|
||||
/>
|
||||
</ComposerToolbarRow>
|
||||
</View>
|
||||
</KeyboardStickyView>
|
||||
) : !keyboardState.isVisible ? (
|
||||
|
||||
@@ -1,24 +1,10 @@
|
||||
import { useRouter } from "expo-router";
|
||||
import { SymbolView } from "expo-symbols";
|
||||
import { Stack, useRouter } from "expo-router";
|
||||
import { TextInputWrapper } from "expo-paste-input";
|
||||
import {
|
||||
type ComponentProps,
|
||||
type ReactNode,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import { useCallback, useEffect, useMemo, useRef } 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";
|
||||
@@ -27,9 +13,15 @@ import { useThemeColor } from "../../lib/useThemeColor";
|
||||
|
||||
import { EnvironmentId, type ModelSelection } from "@t3tools/contracts";
|
||||
|
||||
import { AppText as Text, AppTextInput as TextInput } from "../../components/AppText";
|
||||
import { AppTextInput as TextInput } from "../../components/AppText";
|
||||
import {
|
||||
ComposerToolbarButton,
|
||||
ComposerToolbarRow,
|
||||
ComposerToolbarScroller,
|
||||
ComposerToolbarTrigger,
|
||||
} from "../../components/ComposerToolbarTrigger";
|
||||
import { ComposerAttachmentStrip } from "../../components/ComposerAttachmentStrip";
|
||||
import { ControlPill, ControlPillMenu } from "../../components/ControlPill";
|
||||
import { ControlPillMenu } from "../../components/ControlPill";
|
||||
import { ProviderIcon } from "../../components/ProviderIcon";
|
||||
|
||||
import { convertPastedImagesToAttachments, pickComposerImages } from "../../lib/composerImages";
|
||||
@@ -37,13 +29,9 @@ import { buildThreadRoutePath } from "../../lib/routes";
|
||||
import { useRemoteCatalog } from "../../state/use-remote-catalog";
|
||||
import { useNativePaste } from "../../lib/useNativePaste";
|
||||
import { CLAUDE_AGENT_EFFORT_OPTIONS } from "./claudeEffortOptions";
|
||||
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,
|
||||
@@ -72,45 +60,6 @@ function formatWorkspaceLabel(input: {
|
||||
return branchName ? `Current · ${branchName}` : "Current checkout";
|
||||
}
|
||||
|
||||
function NewTaskToolbarTrigger(props: {
|
||||
readonly icon?: ComponentProps<typeof SymbolView>["name"];
|
||||
readonly iconNode?: ReactNode;
|
||||
readonly label?: string;
|
||||
readonly accessibilityLabel?: string;
|
||||
readonly onPress?: () => void;
|
||||
readonly showChevron?: boolean;
|
||||
}) {
|
||||
const iconColor = useThemeColor("--color-icon");
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
accessibilityLabel={props.accessibilityLabel ?? props.label}
|
||||
accessibilityRole="button"
|
||||
onPress={props.onPress}
|
||||
className="h-11 flex-row items-center justify-center gap-2 rounded-full bg-subtle px-3.5 active:opacity-70"
|
||||
style={{ maxWidth: 172 }}
|
||||
>
|
||||
{props.iconNode ? (
|
||||
<View className="h-4 w-4 items-center justify-center">{props.iconNode}</View>
|
||||
) : props.icon ? (
|
||||
<SymbolView name={props.icon} size={16} tintColor={iconColor} type="monochrome" />
|
||||
) : null}
|
||||
{props.label ? (
|
||||
<Text
|
||||
className="shrink text-[13px] font-t3-bold text-foreground"
|
||||
ellipsizeMode="tail"
|
||||
numberOfLines={1}
|
||||
>
|
||||
{props.label}
|
||||
</Text>
|
||||
) : null}
|
||||
{props.showChevron === false ? null : (
|
||||
<SymbolView name="chevron.down" size={11} tintColor={iconColor} type="monochrome" />
|
||||
)}
|
||||
</Pressable>
|
||||
);
|
||||
}
|
||||
|
||||
export function NewTaskDraftScreen(props: {
|
||||
readonly initialProjectRef?: {
|
||||
readonly environmentId?: string;
|
||||
@@ -127,11 +76,6 @@ export function NewTaskDraftScreen(props: {
|
||||
const controlsBottomPadding = isKeyboardVisible ? 8 : Math.max(insets.bottom, 10);
|
||||
const { logicalProjects, selectedProject, setProject } = flow;
|
||||
const promptInputRef = useRef<RNTextInput>(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)";
|
||||
@@ -382,31 +326,6 @@ export function NewTaskDraftScreen(props: {
|
||||
}),
|
||||
[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<NativeScrollEvent>) => {
|
||||
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;
|
||||
@@ -536,6 +455,8 @@ export function NewTaskDraftScreen(props: {
|
||||
});
|
||||
|
||||
if (createdThread) {
|
||||
flow.setPrompt("");
|
||||
flow.clearAttachments();
|
||||
router.replace(buildThreadRoutePath(createdThread));
|
||||
}
|
||||
} finally {
|
||||
@@ -546,21 +467,14 @@ export function NewTaskDraftScreen(props: {
|
||||
if (!selectedProject) {
|
||||
return (
|
||||
<View className="flex-1 bg-sheet">
|
||||
<NewTaskSheetHeader title="Loading task" />
|
||||
<Stack.Screen options={{ title: "Loading task" }} />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<View className="flex-1 bg-sheet">
|
||||
<NewTaskSheetHeader
|
||||
title={selectedProject.title}
|
||||
control={
|
||||
flow.logicalProjects.length > 1
|
||||
? { icon: "chevron.left", onPress: () => router.back() }
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
<Stack.Screen options={{ title: selectedProject.title }} />
|
||||
|
||||
<KeyboardAvoidingView automaticOffset behavior="padding" style={{ flex: 1 }}>
|
||||
<View style={{ flex: 1, minHeight: 0, paddingHorizontal: 20, paddingTop: 8 }}>
|
||||
@@ -600,101 +514,65 @@ export function NewTaskDraftScreen(props: {
|
||||
/>
|
||||
</View>
|
||||
) : null}
|
||||
<View className="flex-row items-center gap-1.5 px-1.5 pt-2">
|
||||
<View className="min-w-0 flex-1" style={{ position: "relative" }}>
|
||||
<ScrollView
|
||||
horizontal
|
||||
keyboardShouldPersistTaps="always"
|
||||
onContentSizeChange={handleToolbarContentSizeChange}
|
||||
onLayout={handleToolbarLayout}
|
||||
onScroll={handleToolbarScroll}
|
||||
scrollEventThrottle={16}
|
||||
showsHorizontalScrollIndicator={false}
|
||||
contentContainerStyle={{
|
||||
alignItems: "center",
|
||||
gap: 8,
|
||||
paddingLeft: 0,
|
||||
paddingRight: 1,
|
||||
}}
|
||||
<ComposerToolbarRow paddingBottom={controlsBottomPadding} paddingHorizontal={6}>
|
||||
<ComposerToolbarScroller
|
||||
fadeOpaque={sheetFadeOpaque}
|
||||
fadeTransparent={sheetFadeTransparent}
|
||||
>
|
||||
<ComposerToolbarButton
|
||||
icon="plus"
|
||||
onPress={() => void handlePickImages()}
|
||||
showChevron={false}
|
||||
/>
|
||||
<ControlPillMenu
|
||||
actions={modelMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleModelMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<ControlPill icon="plus" onPress={() => void handlePickImages()} />
|
||||
<ControlPillMenu
|
||||
actions={modelMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleModelMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<NewTaskToolbarTrigger
|
||||
accessibilityLabel="Model"
|
||||
iconNode={
|
||||
<ProviderIcon provider={flow.selectedModelOption?.providerDriver} size={16} />
|
||||
}
|
||||
label={flow.selectedModelOption?.label ?? "Model"}
|
||||
/>
|
||||
</ControlPillMenu>
|
||||
<ControlPillMenu
|
||||
actions={optionsMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleOptionsMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<NewTaskToolbarTrigger
|
||||
accessibilityLabel="Configuration"
|
||||
icon="slider.horizontal.3"
|
||||
label={configurationLabel}
|
||||
/>
|
||||
</ControlPillMenu>
|
||||
<ControlPillMenu
|
||||
actions={environmentMenuActions}
|
||||
onPressAction={({ nativeEvent }) =>
|
||||
handleEnvironmentMenuAction(nativeEvent.event)
|
||||
<ComposerToolbarTrigger
|
||||
accessibilityLabel="Model"
|
||||
iconNode={
|
||||
<ProviderIcon provider={flow.selectedModelOption?.providerDriver} size={16} />
|
||||
}
|
||||
>
|
||||
<NewTaskToolbarTrigger
|
||||
accessibilityLabel="Environment"
|
||||
icon="desktopcomputer"
|
||||
label={selectedEnvironmentLabel}
|
||||
/>
|
||||
</ControlPillMenu>
|
||||
<ControlPillMenu
|
||||
actions={workspaceMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleWorkspaceMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<NewTaskToolbarTrigger
|
||||
accessibilityLabel="Workspace"
|
||||
icon="point.topleft.down.curvedto.point.bottomright.up"
|
||||
label={workspaceLabel}
|
||||
/>
|
||||
</ControlPillMenu>
|
||||
</ScrollView>
|
||||
{toolbarScrollEdges.showLeftFade ? (
|
||||
<View
|
||||
pointerEvents="none"
|
||||
style={{
|
||||
bottom: 0,
|
||||
experimental_backgroundImage: `linear-gradient(to right, ${sheetFadeOpaque} 0%, ${sheetFadeTransparent} 100%)`,
|
||||
left: 0,
|
||||
position: "absolute",
|
||||
top: 0,
|
||||
width: TOOLBAR_FADE_WIDTH,
|
||||
}}
|
||||
label={flow.selectedModelOption?.label ?? "Model"}
|
||||
/>
|
||||
) : null}
|
||||
{toolbarScrollEdges.showRightFade ? (
|
||||
<View
|
||||
pointerEvents="none"
|
||||
style={{
|
||||
bottom: 0,
|
||||
experimental_backgroundImage: `linear-gradient(to right, ${sheetFadeTransparent} 0%, ${sheetFadeOpaque} 100%)`,
|
||||
position: "absolute",
|
||||
right: 0,
|
||||
top: 0,
|
||||
width: TOOLBAR_FADE_WIDTH,
|
||||
}}
|
||||
</ControlPillMenu>
|
||||
<ControlPillMenu
|
||||
actions={optionsMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleOptionsMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<ComposerToolbarTrigger
|
||||
accessibilityLabel="Configuration"
|
||||
icon="slider.horizontal.3"
|
||||
label={configurationLabel}
|
||||
/>
|
||||
) : null}
|
||||
</View>
|
||||
<ControlPill
|
||||
</ControlPillMenu>
|
||||
<ControlPillMenu
|
||||
actions={environmentMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleEnvironmentMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<ComposerToolbarTrigger
|
||||
accessibilityLabel="Environment"
|
||||
icon="desktopcomputer"
|
||||
label={selectedEnvironmentLabel}
|
||||
/>
|
||||
</ControlPillMenu>
|
||||
<ControlPillMenu
|
||||
actions={workspaceMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleWorkspaceMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<ComposerToolbarTrigger
|
||||
accessibilityLabel="Workspace"
|
||||
icon="point.topleft.down.curvedto.point.bottomright.up"
|
||||
label={workspaceLabel}
|
||||
/>
|
||||
</ControlPillMenu>
|
||||
</ComposerToolbarScroller>
|
||||
<ComposerToolbarButton
|
||||
accessibilityLabel={flow.submitting ? "Starting task" : "Start task"}
|
||||
icon="arrow.up"
|
||||
onPress={() => void handleStart()}
|
||||
variant="primary"
|
||||
showChevron={false}
|
||||
disabled={
|
||||
!flow.selectedProject ||
|
||||
!flow.selectedModel ||
|
||||
@@ -703,7 +581,7 @@ export function NewTaskDraftScreen(props: {
|
||||
(flow.workspaceMode === "worktree" && !flow.selectedBranchName)
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
</ComposerToolbarRow>
|
||||
</View>
|
||||
</KeyboardAvoidingView>
|
||||
</View>
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
import { SymbolView } from "expo-symbols";
|
||||
import { Pressable, View } from "react-native";
|
||||
|
||||
import { AppText as Text } from "../../components/AppText";
|
||||
import { useThemeColor } from "../../lib/useThemeColor";
|
||||
|
||||
export function NewTaskSheetHeader(props: {
|
||||
readonly eyebrow?: string;
|
||||
readonly title: string;
|
||||
readonly control?: {
|
||||
readonly icon: "chevron.left" | "xmark";
|
||||
readonly onPress: () => void;
|
||||
};
|
||||
}) {
|
||||
const iconColor = useThemeColor("--color-icon");
|
||||
|
||||
return (
|
||||
<>
|
||||
<View style={{ minHeight: 16, paddingTop: 8 }} />
|
||||
<View className="items-center gap-1 px-5 pb-3 pt-4">
|
||||
{props.control ? (
|
||||
<Pressable
|
||||
className="absolute left-3 top-4 h-9 w-9 items-center justify-center rounded-full bg-subtle"
|
||||
style={{ zIndex: 1 }}
|
||||
onPress={props.control.onPress}
|
||||
>
|
||||
<SymbolView
|
||||
name={props.control.icon}
|
||||
size={16}
|
||||
tintColor={iconColor}
|
||||
type="monochrome"
|
||||
weight="medium"
|
||||
/>
|
||||
</Pressable>
|
||||
) : null}
|
||||
<Text
|
||||
className="text-[12px] font-t3-bold uppercase text-foreground-muted"
|
||||
style={{ letterSpacing: 1 }}
|
||||
>
|
||||
{props.eyebrow ?? "New task"}
|
||||
</Text>
|
||||
<Text className="text-[28px] font-t3-bold">{props.title}</Text>
|
||||
</View>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -30,6 +30,12 @@ import { useThemeColor } from "../../lib/useThemeColor";
|
||||
|
||||
import { AppText as Text } from "../../components/AppText";
|
||||
import { ComposerAttachmentStrip } from "../../components/ComposerAttachmentStrip";
|
||||
import {
|
||||
ComposerToolbarButton,
|
||||
ComposerToolbarRow,
|
||||
ComposerToolbarScroller,
|
||||
ComposerToolbarTrigger,
|
||||
} from "../../components/ComposerToolbarTrigger";
|
||||
import { ControlPill, ControlPillMenu } from "../../components/ControlPill";
|
||||
import { ProviderIcon } from "../../components/ProviderIcon";
|
||||
import type { DraftComposerImageAttachment } from "../../lib/composerImages";
|
||||
@@ -66,7 +72,7 @@ export const COMPOSER_EXPANDED_CHROME = 174;
|
||||
* Used by the feed inset because KeyboardAvoidingLegendList only accounts for
|
||||
* keyboard height; the floating toolbar remains an additional overlay.
|
||||
*/
|
||||
export const COMPOSER_EXPANDED_TOOLBAR_CHROME = 54;
|
||||
export const COMPOSER_EXPANDED_TOOLBAR_CHROME = 60;
|
||||
|
||||
export interface ThreadComposerProps {
|
||||
readonly draftMessage: string;
|
||||
@@ -84,7 +90,6 @@ export interface ThreadComposerProps {
|
||||
readonly onPickDraftImages: () => Promise<void>;
|
||||
readonly onNativePasteImages: (uris: ReadonlyArray<string>) => Promise<void>;
|
||||
readonly onRemoveDraftImage: (imageId: string) => void;
|
||||
readonly onRefresh: () => Promise<void>;
|
||||
readonly onStopThread: () => Promise<void>;
|
||||
readonly onSendMessage: () => void;
|
||||
readonly onUpdateModelSelection: (modelSelection: ModelSelection) => Promise<void>;
|
||||
@@ -144,6 +149,10 @@ function withModelSelectionOption(
|
||||
};
|
||||
}
|
||||
|
||||
function formatTitleCase(value: string): string {
|
||||
return value.length === 0 ? value : `${value.charAt(0).toUpperCase()}${value.slice(1)}`;
|
||||
}
|
||||
|
||||
export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposerProps) {
|
||||
const isDarkMode = useColorScheme() === "dark";
|
||||
const themePlaceholderColor = useThemeColor("--color-placeholder");
|
||||
@@ -183,10 +192,11 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
|
||||
props.queueCount > 0;
|
||||
|
||||
const sendLabel = props.activeThreadBusy || props.queueCount > 0 ? "Queue" : "Send";
|
||||
const modelProvider = props.selectedThread.modelSelection?.instanceId ?? null;
|
||||
const currentModelSelection = props.selectedThread.modelSelection;
|
||||
const currentRuntimeMode = props.selectedThread.runtimeMode;
|
||||
const currentInteractionMode = props.selectedThread.interactionMode ?? "default";
|
||||
const toolbarFadeOpaque = isDarkMode ? "rgba(0,0,0,0.95)" : "rgba(255,255,255,0.95)";
|
||||
const toolbarFadeTransparent = isDarkMode ? "rgba(0,0,0,0)" : "rgba(255,255,255,0)";
|
||||
const selectedProviderStatus = useMemo(() => {
|
||||
if (!props.serverConfig) return null;
|
||||
return (
|
||||
@@ -430,11 +440,25 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
|
||||
);
|
||||
|
||||
// ── Model menu ───────────────────────────────────────────
|
||||
const providerGroups = useMemo(() => {
|
||||
const options = buildModelOptions(props.serverConfig, currentModelSelection);
|
||||
return groupByProvider(options);
|
||||
}, [props.serverConfig, currentModelSelection]);
|
||||
|
||||
const modelOptions = useMemo(
|
||||
() => buildModelOptions(props.serverConfig, currentModelSelection),
|
||||
[props.serverConfig, currentModelSelection],
|
||||
);
|
||||
const providerGroups = useMemo(() => groupByProvider(modelOptions), [modelOptions]);
|
||||
const currentModelOption =
|
||||
modelOptions.find(
|
||||
(option) =>
|
||||
option.selection.instanceId === currentModelSelection.instanceId &&
|
||||
option.selection.model === currentModelSelection.model,
|
||||
) ?? null;
|
||||
const configurationLabel = useMemo(() => {
|
||||
const parts = [
|
||||
formatTitleCase(currentEffort),
|
||||
currentFastMode ? "Fast" : null,
|
||||
currentContextWindow !== "1M" ? currentContextWindow : null,
|
||||
].filter((part): part is string => Boolean(part));
|
||||
return parts.length > 0 ? parts.join(" · ") : "Configuration";
|
||||
}, [currentContextWindow, currentEffort, currentFastMode]);
|
||||
const modelMenuActions = useMemo(
|
||||
() =>
|
||||
providerGroups.map((group) => ({
|
||||
@@ -545,8 +569,7 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
|
||||
return;
|
||||
}
|
||||
const modelKey = event.slice("model:".length);
|
||||
const options = buildModelOptions(props.serverConfig, currentModelSelection);
|
||||
const option = options.find((o) => o.key === modelKey);
|
||||
const option = modelOptions.find((o) => o.key === modelKey);
|
||||
if (option) {
|
||||
void props.onUpdateModelSelection(option.selection);
|
||||
}
|
||||
@@ -752,44 +775,56 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
|
||||
|
||||
{/* Toolbar row — matches draft page layout (expanded only) */}
|
||||
{isExpanded ? (
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
paddingTop: 10,
|
||||
gap: 8,
|
||||
}}
|
||||
>
|
||||
<ControlPill icon="plus" onPress={() => void props.onPickDraftImages()} />
|
||||
<ControlPillMenu
|
||||
actions={modelMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleModelMenuAction(nativeEvent.event)}
|
||||
<ComposerToolbarRow paddingBottom={8} paddingHorizontal={0} paddingTop={8}>
|
||||
<ComposerToolbarScroller
|
||||
fadeOpaque={toolbarFadeOpaque}
|
||||
fadeTransparent={toolbarFadeTransparent}
|
||||
>
|
||||
<ControlPill iconNode={<ProviderIcon provider={modelProvider} size={16} />} />
|
||||
</ControlPillMenu>
|
||||
<ControlPillMenu
|
||||
actions={optionsMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleOptionsMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<ControlPill icon="slider.horizontal.3" />
|
||||
</ControlPillMenu>
|
||||
<ControlPill icon="arrow.clockwise" onPress={() => void props.onRefresh()} />
|
||||
{showStopAction ? (
|
||||
<ControlPill
|
||||
icon="stop.fill"
|
||||
variant="danger"
|
||||
onPress={() => void props.onStopThread()}
|
||||
<ComposerToolbarButton
|
||||
icon="plus"
|
||||
onPress={() => void props.onPickDraftImages()}
|
||||
showChevron={false}
|
||||
/>
|
||||
) : null}
|
||||
<ControlPill
|
||||
<ControlPillMenu
|
||||
actions={modelMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleModelMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<ComposerToolbarTrigger
|
||||
accessibilityLabel="Model"
|
||||
iconNode={
|
||||
<ProviderIcon provider={currentModelOption?.providerDriver} size={16} />
|
||||
}
|
||||
label={currentModelOption?.label ?? currentModelSelection.model}
|
||||
/>
|
||||
</ControlPillMenu>
|
||||
<ControlPillMenu
|
||||
actions={optionsMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleOptionsMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<ComposerToolbarTrigger
|
||||
accessibilityLabel="Configuration"
|
||||
icon="slider.horizontal.3"
|
||||
label={configurationLabel}
|
||||
/>
|
||||
</ControlPillMenu>
|
||||
{showStopAction ? (
|
||||
<ComposerToolbarButton
|
||||
icon="stop.fill"
|
||||
variant="danger"
|
||||
onPress={() => void props.onStopThread()}
|
||||
showChevron={false}
|
||||
/>
|
||||
) : null}
|
||||
</ComposerToolbarScroller>
|
||||
<ComposerToolbarButton
|
||||
accessibilityLabel={sendLabel}
|
||||
icon="arrow.up"
|
||||
label={sendLabel}
|
||||
variant="primary"
|
||||
disabled={!canSend}
|
||||
onPress={handleSend}
|
||||
showChevron={false}
|
||||
/>
|
||||
</View>
|
||||
</ComposerToolbarRow>
|
||||
) : null}
|
||||
|
||||
{/* Queue count */}
|
||||
|
||||
@@ -67,7 +67,6 @@ export interface ThreadDetailScreenProps {
|
||||
readonly onPickDraftImages: () => Promise<void>;
|
||||
readonly onNativePasteImages: (uris: ReadonlyArray<string>) => Promise<void>;
|
||||
readonly onRemoveDraftImage: (imageId: string) => void;
|
||||
readonly onRefresh: () => Promise<void>;
|
||||
readonly onStopThread: () => Promise<void>;
|
||||
readonly onSendMessage: () => void;
|
||||
readonly onUpdateThreadModelSelection: (modelSelection: ModelSelection) => Promise<void>;
|
||||
@@ -198,18 +197,17 @@ const WorkingDurationPill = memo(function WorkingDurationPill(props: {
|
||||
});
|
||||
|
||||
export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: ThreadDetailScreenProps) {
|
||||
const { onOpenDrawer, onRefresh } = props;
|
||||
const { onOpenDrawer } = props;
|
||||
|
||||
const insets = useSafeAreaInsets();
|
||||
const agentLabel = `${props.selectedThread.modelSelection.instanceId} agent`;
|
||||
const composerBottomInset = Math.max(insets.bottom, 12);
|
||||
const [composerExpanded, setComposerExpanded] = useState(false);
|
||||
const composerBottomInset = composerExpanded ? 0 : Math.max(insets.bottom, 12);
|
||||
const composerChrome = composerExpanded ? COMPOSER_EXPANDED_CHROME : COMPOSER_COLLAPSED_CHROME;
|
||||
const composerOverlapHeight = composerChrome + composerBottomInset;
|
||||
const activeWorkIndicatorHeight = props.activeWorkStartedAt ? WORKING_INDICATOR_HEIGHT : 0;
|
||||
const estimatedOverlayHeight = composerOverlapHeight + activeWorkIndicatorHeight;
|
||||
const [measuredOverlayHeight, setMeasuredOverlayHeight] = useState(0);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const showContent = props.showContent ?? true;
|
||||
const layoutVariant = props.layoutVariant ?? "compact";
|
||||
const isSplitLayout = layoutVariant === "split";
|
||||
@@ -223,19 +221,6 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
|
||||
onOpenDrawer();
|
||||
}, [onOpenDrawer]);
|
||||
|
||||
const handleRefresh = useCallback(async (): Promise<void> => {
|
||||
if (refreshing) {
|
||||
return;
|
||||
}
|
||||
|
||||
setRefreshing(true);
|
||||
try {
|
||||
await onRefresh();
|
||||
} finally {
|
||||
setRefreshing(false);
|
||||
}
|
||||
}, [onRefresh, refreshing]);
|
||||
|
||||
const drawerGestureThreshold = 80;
|
||||
const headerDrawerGesture = useMemo(
|
||||
() =>
|
||||
@@ -273,8 +258,6 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
|
||||
contentBottomInset={feedBottomInset}
|
||||
layoutVariant={layoutVariant}
|
||||
composerExpanded={composerExpanded}
|
||||
refreshing={refreshing}
|
||||
onRefresh={handleRefresh}
|
||||
/>
|
||||
) : (
|
||||
<View style={{ flex: 1 }} />
|
||||
@@ -330,7 +313,6 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
|
||||
onPickDraftImages={props.onPickDraftImages}
|
||||
onNativePasteImages={props.onNativePasteImages}
|
||||
onRemoveDraftImage={props.onRemoveDraftImage}
|
||||
onRefresh={props.onRefresh}
|
||||
onStopThread={props.onStopThread}
|
||||
onSendMessage={props.onSendMessage}
|
||||
onUpdateModelSelection={props.onUpdateThreadModelSelection}
|
||||
|
||||
@@ -55,8 +55,6 @@ export interface ThreadFeedProps {
|
||||
readonly bearerToken: string | null;
|
||||
readonly agentLabel: string;
|
||||
readonly contentBottomInset?: number;
|
||||
readonly refreshing?: boolean;
|
||||
readonly onRefresh?: () => void;
|
||||
readonly layoutVariant?: MobileLayoutVariant;
|
||||
readonly composerExpanded?: boolean;
|
||||
}
|
||||
@@ -958,8 +956,6 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
|
||||
on: { layout: true, itemLayout: true, dataChange: true },
|
||||
}}
|
||||
maintainScrollAtEndThreshold={0.1}
|
||||
refreshing={props.refreshing ?? false}
|
||||
onRefresh={props.onRefresh}
|
||||
safeAreaInsetBottom={insets.bottom}
|
||||
contentContainerStyle={{
|
||||
paddingTop: 12,
|
||||
|
||||
@@ -7,7 +7,7 @@ import { EnvironmentId, type ProjectScript } from "@t3tools/contracts";
|
||||
import { projectScriptCwd, projectScriptRuntimeEnv } from "@t3tools/shared/projectScripts";
|
||||
import { Pressable, ScrollView, Text as RNText, View, useColorScheme } from "react-native";
|
||||
import { useThemeColor } from "../../lib/useThemeColor";
|
||||
import { useVcsStatus, vcsStatusManager } from "../../state/use-vcs-status";
|
||||
import { useVcsStatus } from "../../state/use-vcs-status";
|
||||
import { dismissGitActionResult, useGitActionProgress } from "../../state/use-vcs-action-state";
|
||||
|
||||
import { EmptyState } from "../../components/EmptyState";
|
||||
@@ -53,6 +53,10 @@ function firstRouteParam(value: string | string[] | undefined): string | null {
|
||||
return value ?? null;
|
||||
}
|
||||
|
||||
function OpeningThreadLoadingScreen() {
|
||||
return <LoadingScreen message="Opening thread…" messagePlacement="above-spinner" />;
|
||||
}
|
||||
|
||||
export function ThreadRouteScreen() {
|
||||
const { isLoadingSavedConnection, environmentStateById, pendingConnectionError } =
|
||||
useRemoteEnvironmentState();
|
||||
@@ -70,7 +74,6 @@ export function ThreadRouteScreen() {
|
||||
const commands = useSelectedThreadCommands({
|
||||
refreshSelectedThreadGitStatus: gitActions.refreshSelectedThreadGitStatus,
|
||||
});
|
||||
const refreshSelectedThread = commands.onRefresh;
|
||||
const router = useRouter();
|
||||
const params = useLocalSearchParams<{
|
||||
environmentId?: string | string[];
|
||||
@@ -122,20 +125,6 @@ export function ThreadRouteScreen() {
|
||||
);
|
||||
const gitActionProgress = useGitActionProgress(gitActionProgressTarget);
|
||||
|
||||
const handleRefreshGitStatus = useCallback(async () => {
|
||||
if (!selectedThread) return;
|
||||
await vcsStatusManager.refresh({
|
||||
environmentId: selectedThread.environmentId,
|
||||
cwd: selectedThreadCwd,
|
||||
});
|
||||
}, [selectedThread, selectedThreadCwd]);
|
||||
|
||||
/** Wraps thread refresh + git status refresh for pull-to-refresh */
|
||||
const handleRefreshAll = useCallback(async () => {
|
||||
await refreshSelectedThread();
|
||||
await handleRefreshGitStatus();
|
||||
}, [handleRefreshGitStatus, refreshSelectedThread]);
|
||||
|
||||
const handleOpenDrawer = useCallback(() => {
|
||||
setDrawerVisible(true);
|
||||
}, []);
|
||||
@@ -245,7 +234,7 @@ export function ThreadRouteScreen() {
|
||||
);
|
||||
|
||||
if (!environmentId || !threadId) {
|
||||
return <LoadingScreen message="Opening thread…" />;
|
||||
return <OpeningThreadLoadingScreen />;
|
||||
}
|
||||
|
||||
if (!selectedThread) {
|
||||
@@ -255,7 +244,7 @@ export function ThreadRouteScreen() {
|
||||
routeConnectionState === "reconnecting";
|
||||
|
||||
if (stillHydrating) {
|
||||
return <LoadingScreen message="Opening thread…" />;
|
||||
return <OpeningThreadLoadingScreen />;
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -278,7 +267,7 @@ export function ThreadRouteScreen() {
|
||||
}
|
||||
|
||||
if (!selectedThreadDetail) {
|
||||
return <LoadingScreen message="Opening thread…" />;
|
||||
return <OpeningThreadLoadingScreen />;
|
||||
}
|
||||
|
||||
const selectedThreadKey = scopedThreadKey(selectedThread.environmentId, selectedThread.id);
|
||||
@@ -388,7 +377,6 @@ export function ThreadRouteScreen() {
|
||||
onPickDraftImages={composer.onPickDraftImages}
|
||||
onNativePasteImages={composer.onNativePasteImages}
|
||||
onRemoveDraftImage={composer.onRemoveDraftImage}
|
||||
onRefresh={handleRefreshAll}
|
||||
serverConfig={serverConfig}
|
||||
onStopThread={commands.onStopThread}
|
||||
onSendMessage={composer.onSendMessage}
|
||||
|
||||
@@ -15,6 +15,13 @@ import type { ModelOption, ProviderGroup } from "../../lib/modelOptions";
|
||||
import { buildModelOptions, groupByProvider } from "../../lib/modelOptions";
|
||||
import { groupProjectsByRepository } from "../../lib/repositoryGroups";
|
||||
import { scopedProjectKey } from "../../lib/scopedEntities";
|
||||
import {
|
||||
appendComposerDraftAttachments,
|
||||
removeComposerDraftAttachment,
|
||||
replaceComposerDraftAttachments,
|
||||
setComposerDraftText,
|
||||
useComposerDraft,
|
||||
} from "../../state/use-composer-drafts";
|
||||
import { vcsRefManager, useVcsRefs } from "../../state/use-vcs-refs";
|
||||
import { useRemoteCatalog } from "../../state/use-remote-catalog";
|
||||
import {
|
||||
@@ -153,8 +160,6 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
|
||||
const [selectedBranchName, setSelectedBranchName] = useState<string | null>(null);
|
||||
const [selectedWorktreePath, setSelectedWorktreePath] = useState<string | null>(null);
|
||||
const branchLoadVersionRef = useRef(0);
|
||||
const [prompt, setPrompt] = useState("");
|
||||
const [attachments, setAttachments] = useState<ReadonlyArray<DraftComposerImageAttachment>>([]);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [branchQuery, setBranchQuery] = useState("");
|
||||
const [runtimeMode, setRuntimeMode] = useState<RuntimeMode>(DEFAULT_RUNTIME_MODE);
|
||||
@@ -166,28 +171,6 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
|
||||
const [contextWindow, setContextWindow] = useState("1M");
|
||||
const [expandedProvider, setExpandedProvider] = useState<string | null>(null);
|
||||
|
||||
const replaceAttachments = useCallback(
|
||||
(nextAttachments: ReadonlyArray<DraftComposerImageAttachment>) => {
|
||||
setAttachments(nextAttachments);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
const appendAttachments = useCallback(
|
||||
(nextAttachments: ReadonlyArray<DraftComposerImageAttachment>) => {
|
||||
setAttachments((current) => [...current, ...nextAttachments]);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
const removeAttachment = useCallback((imageId: string) => {
|
||||
setAttachments((current) => current.filter((candidate) => candidate.id !== imageId));
|
||||
}, []);
|
||||
|
||||
const clearAttachments = useCallback(() => {
|
||||
setAttachments([]);
|
||||
}, []);
|
||||
|
||||
const reset = useCallback(() => {
|
||||
console.log("[new task flow] reset", {
|
||||
defaultEnvironmentId: projects[0]?.environmentId ?? null,
|
||||
@@ -199,8 +182,6 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
|
||||
setWorkspaceMode("local");
|
||||
setSelectedBranchName(null);
|
||||
setSelectedWorktreePath(null);
|
||||
setPrompt("");
|
||||
clearAttachments();
|
||||
setSubmitting(false);
|
||||
setBranchQuery("");
|
||||
setRuntimeMode(DEFAULT_RUNTIME_MODE);
|
||||
@@ -209,7 +190,7 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
|
||||
setFastMode(false);
|
||||
setContextWindow("1M");
|
||||
setExpandedProvider(null);
|
||||
}, [clearAttachments, projects]);
|
||||
}, [projects]);
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedEnvironmentId !== null || projects.length === 0) {
|
||||
@@ -271,6 +252,12 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
|
||||
) ??
|
||||
projectsForEnvironment[0] ??
|
||||
null;
|
||||
const selectedProjectDraftKey = selectedProject
|
||||
? `new-task:${scopedProjectKey(selectedProject.environmentId, selectedProject.id)}`
|
||||
: null;
|
||||
const selectedProjectDraft = useComposerDraft(selectedProjectDraftKey);
|
||||
const prompt = selectedProjectDraft.text;
|
||||
const attachments = selectedProjectDraft.attachments;
|
||||
|
||||
const modelOptions = useMemo(
|
||||
() =>
|
||||
@@ -298,6 +285,48 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
|
||||
) ?? null;
|
||||
|
||||
const providerGroups = useMemo(() => groupByProvider(modelOptions), [modelOptions]);
|
||||
const setPrompt = useCallback(
|
||||
(value: string) => {
|
||||
if (!selectedProjectDraftKey) {
|
||||
return;
|
||||
}
|
||||
setComposerDraftText(selectedProjectDraftKey, value);
|
||||
},
|
||||
[selectedProjectDraftKey],
|
||||
);
|
||||
const replaceAttachments = useCallback(
|
||||
(nextAttachments: ReadonlyArray<DraftComposerImageAttachment>) => {
|
||||
if (!selectedProjectDraftKey) {
|
||||
return;
|
||||
}
|
||||
replaceComposerDraftAttachments(selectedProjectDraftKey, nextAttachments);
|
||||
},
|
||||
[selectedProjectDraftKey],
|
||||
);
|
||||
const appendAttachments = useCallback(
|
||||
(nextAttachments: ReadonlyArray<DraftComposerImageAttachment>) => {
|
||||
if (!selectedProjectDraftKey) {
|
||||
return;
|
||||
}
|
||||
appendComposerDraftAttachments(selectedProjectDraftKey, nextAttachments);
|
||||
},
|
||||
[selectedProjectDraftKey],
|
||||
);
|
||||
const removeAttachment = useCallback(
|
||||
(imageId: string) => {
|
||||
if (!selectedProjectDraftKey) {
|
||||
return;
|
||||
}
|
||||
removeComposerDraftAttachment(selectedProjectDraftKey, imageId);
|
||||
},
|
||||
[selectedProjectDraftKey],
|
||||
);
|
||||
const clearAttachments = useCallback(() => {
|
||||
if (!selectedProjectDraftKey) {
|
||||
return;
|
||||
}
|
||||
replaceComposerDraftAttachments(selectedProjectDraftKey, []);
|
||||
}, [selectedProjectDraftKey]);
|
||||
const branchTarget = useMemo(
|
||||
() => ({
|
||||
environmentId: selectedProject?.environmentId ?? null,
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
import { useAtomValue } from "@effect/atom-react";
|
||||
import { useEffect } from "react";
|
||||
import { Atom } from "effect/unstable/reactivity";
|
||||
|
||||
import type { DraftComposerImageAttachment } from "../lib/composerImages";
|
||||
import { appAtomRegistry } from "./atom-registry";
|
||||
|
||||
const COMPOSER_DRAFTS_SCHEMA_VERSION = 1;
|
||||
const COMPOSER_DRAFTS_DIRECTORY = "composer-drafts";
|
||||
const COMPOSER_DRAFTS_FILE = "drafts.json";
|
||||
const PERSIST_DEBOUNCE_MS = 200;
|
||||
|
||||
export interface ComposerDraft {
|
||||
readonly text: string;
|
||||
readonly attachments: ReadonlyArray<DraftComposerImageAttachment>;
|
||||
}
|
||||
|
||||
interface PersistedComposerDrafts {
|
||||
readonly schemaVersion: typeof COMPOSER_DRAFTS_SCHEMA_VERSION;
|
||||
readonly drafts: Record<string, ComposerDraft>;
|
||||
}
|
||||
|
||||
const EMPTY_DRAFT: ComposerDraft = {
|
||||
text: "",
|
||||
attachments: [],
|
||||
};
|
||||
|
||||
export const composerDraftsAtom = Atom.make<Record<string, ComposerDraft>>({}).pipe(
|
||||
Atom.keepAlive,
|
||||
Atom.withLabel("mobile:composer-drafts"),
|
||||
);
|
||||
|
||||
let loadStarted = false;
|
||||
let persistTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
function normalizeDraft(draft: ComposerDraft | undefined): ComposerDraft {
|
||||
if (!draft) {
|
||||
return EMPTY_DRAFT;
|
||||
}
|
||||
return {
|
||||
text: draft.text,
|
||||
attachments: draft.attachments,
|
||||
};
|
||||
}
|
||||
|
||||
function isEmptyDraft(draft: ComposerDraft): boolean {
|
||||
return draft.text.length === 0 && draft.attachments.length === 0;
|
||||
}
|
||||
|
||||
async function getComposerDraftsFile() {
|
||||
const { Directory, File, Paths } = await import("expo-file-system");
|
||||
const directory = new Directory(Paths.document, COMPOSER_DRAFTS_DIRECTORY);
|
||||
directory.create({ idempotent: true, intermediates: true });
|
||||
return new File(directory, COMPOSER_DRAFTS_FILE);
|
||||
}
|
||||
|
||||
async function loadPersistedComposerDrafts(): Promise<Record<string, ComposerDraft>> {
|
||||
try {
|
||||
const file = await getComposerDraftsFile();
|
||||
if (!file.exists) {
|
||||
return {};
|
||||
}
|
||||
const parsed = JSON.parse(await file.text()) as Partial<PersistedComposerDrafts>;
|
||||
if (parsed.schemaVersion !== COMPOSER_DRAFTS_SCHEMA_VERSION || !parsed.drafts) {
|
||||
return {};
|
||||
}
|
||||
return Object.fromEntries(
|
||||
Object.entries(parsed.drafts).filter((entry): entry is [string, ComposerDraft] => {
|
||||
const draft = entry[1];
|
||||
return (
|
||||
typeof draft?.text === "string" &&
|
||||
Array.isArray(draft.attachments) &&
|
||||
!isEmptyDraft(draft)
|
||||
);
|
||||
}),
|
||||
);
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
async function savePersistedComposerDrafts(drafts: Record<string, ComposerDraft>): Promise<void> {
|
||||
try {
|
||||
const file = await getComposerDraftsFile();
|
||||
const nonEmptyDrafts = Object.fromEntries(
|
||||
Object.entries(drafts).filter(([, draft]) => !isEmptyDraft(draft)),
|
||||
);
|
||||
const document: PersistedComposerDrafts = {
|
||||
schemaVersion: COMPOSER_DRAFTS_SCHEMA_VERSION,
|
||||
drafts: nonEmptyDrafts,
|
||||
};
|
||||
if (!file.exists) {
|
||||
file.create({ intermediates: true, overwrite: true });
|
||||
}
|
||||
file.write(JSON.stringify(document));
|
||||
} catch {
|
||||
// Draft persistence is best-effort; in-memory drafts still keep working.
|
||||
}
|
||||
}
|
||||
|
||||
function schedulePersistComposerDrafts(drafts: Record<string, ComposerDraft>): void {
|
||||
if (persistTimer !== null) {
|
||||
clearTimeout(persistTimer);
|
||||
}
|
||||
persistTimer = setTimeout(() => {
|
||||
persistTimer = null;
|
||||
void savePersistedComposerDrafts(drafts);
|
||||
}, PERSIST_DEBOUNCE_MS);
|
||||
}
|
||||
|
||||
export function ensureComposerDraftsLoaded(): void {
|
||||
if (loadStarted) {
|
||||
return;
|
||||
}
|
||||
loadStarted = true;
|
||||
void loadPersistedComposerDrafts().then((persistedDrafts) => {
|
||||
if (Object.keys(persistedDrafts).length === 0) {
|
||||
return;
|
||||
}
|
||||
const current = appAtomRegistry.get(composerDraftsAtom);
|
||||
appAtomRegistry.set(composerDraftsAtom, {
|
||||
...persistedDrafts,
|
||||
...current,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function updateComposerDrafts(
|
||||
update: (current: Record<string, ComposerDraft>) => Record<string, ComposerDraft>,
|
||||
): void {
|
||||
const next = update(appAtomRegistry.get(composerDraftsAtom));
|
||||
appAtomRegistry.set(composerDraftsAtom, next);
|
||||
schedulePersistComposerDrafts(next);
|
||||
}
|
||||
|
||||
export function setComposerDraftText(draftKey: string, value: string): void {
|
||||
updateComposerDrafts((current) => {
|
||||
const draft = {
|
||||
...normalizeDraft(current[draftKey]),
|
||||
text: value,
|
||||
};
|
||||
if (isEmptyDraft(draft)) {
|
||||
const next = { ...current };
|
||||
delete next[draftKey];
|
||||
return next;
|
||||
}
|
||||
return {
|
||||
...current,
|
||||
[draftKey]: draft,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function appendComposerDraftText(draftKey: string, value: string): void {
|
||||
updateComposerDrafts((current) => {
|
||||
const existing = normalizeDraft(current[draftKey]);
|
||||
return {
|
||||
...current,
|
||||
[draftKey]: {
|
||||
...existing,
|
||||
text: `${existing.text}${value}`,
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function appendComposerDraftAttachments(
|
||||
draftKey: string,
|
||||
attachments: ReadonlyArray<DraftComposerImageAttachment>,
|
||||
): void {
|
||||
if (attachments.length === 0) {
|
||||
return;
|
||||
}
|
||||
updateComposerDrafts((current) => {
|
||||
const existing = normalizeDraft(current[draftKey]);
|
||||
return {
|
||||
...current,
|
||||
[draftKey]: {
|
||||
...existing,
|
||||
attachments: [...existing.attachments, ...attachments],
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function replaceComposerDraftAttachments(
|
||||
draftKey: string,
|
||||
attachments: ReadonlyArray<DraftComposerImageAttachment>,
|
||||
): void {
|
||||
updateComposerDrafts((current) => {
|
||||
const draft = {
|
||||
...normalizeDraft(current[draftKey]),
|
||||
attachments,
|
||||
};
|
||||
if (isEmptyDraft(draft)) {
|
||||
const next = { ...current };
|
||||
delete next[draftKey];
|
||||
return next;
|
||||
}
|
||||
return {
|
||||
...current,
|
||||
[draftKey]: draft,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function removeComposerDraftAttachment(draftKey: string, imageId: string): void {
|
||||
updateComposerDrafts((current) => {
|
||||
const existing = normalizeDraft(current[draftKey]);
|
||||
const draft = {
|
||||
...existing,
|
||||
attachments: existing.attachments.filter((image) => image.id !== imageId),
|
||||
};
|
||||
if (isEmptyDraft(draft)) {
|
||||
const next = { ...current };
|
||||
delete next[draftKey];
|
||||
return next;
|
||||
}
|
||||
return {
|
||||
...current,
|
||||
[draftKey]: draft,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function clearComposerDraft(draftKey: string): void {
|
||||
updateComposerDrafts((current) => {
|
||||
if (!current[draftKey]) {
|
||||
return current;
|
||||
}
|
||||
const next = { ...current };
|
||||
delete next[draftKey];
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
export function useComposerDraft(draftKey: string | null): ComposerDraft {
|
||||
const drafts = useAtomValue(composerDraftsAtom);
|
||||
useEffect(() => {
|
||||
ensureComposerDraftsLoaded();
|
||||
}, []);
|
||||
return draftKey ? normalizeDraft(drafts[draftKey]) : EMPTY_DRAFT;
|
||||
}
|
||||
@@ -16,6 +16,16 @@ import type { DraftComposerImageAttachment } from "../lib/composerImages";
|
||||
import { scopedThreadKey } from "../lib/scopedEntities";
|
||||
import { buildThreadFeed, type QueuedThreadMessage } from "../lib/threadActivity";
|
||||
import { appAtomRegistry } from "../state/atom-registry";
|
||||
import {
|
||||
appendComposerDraftAttachments,
|
||||
appendComposerDraftText,
|
||||
clearComposerDraft,
|
||||
composerDraftsAtom,
|
||||
ensureComposerDraftsLoaded,
|
||||
removeComposerDraftAttachment,
|
||||
setComposerDraftText,
|
||||
useComposerDraft,
|
||||
} from "./use-composer-drafts";
|
||||
import { getEnvironmentClient } from "./environment-session-registry";
|
||||
import type { ConnectedEnvironmentSummary } from "../state/remote-runtime-types";
|
||||
import {
|
||||
@@ -26,15 +36,6 @@ import { useRemoteCatalog } from "../state/use-remote-catalog";
|
||||
import { useSelectedThreadDetail } from "../state/use-thread-detail";
|
||||
import { useThreadSelection } from "../state/use-thread-selection";
|
||||
|
||||
const draftMessageByThreadKeyAtom = Atom.make<Record<string, string>>({}).pipe(
|
||||
Atom.keepAlive,
|
||||
Atom.withLabel("mobile:thread-composer:draft-message"),
|
||||
);
|
||||
|
||||
const draftAttachmentsByThreadKeyAtom = Atom.make<
|
||||
Record<string, ReadonlyArray<DraftComposerImageAttachment>>
|
||||
>({}).pipe(Atom.keepAlive, Atom.withLabel("mobile:thread-composer:draft-attachments"));
|
||||
|
||||
const dispatchingQueuedMessageIdAtom = Atom.make<MessageId | null>(null).pipe(
|
||||
Atom.keepAlive,
|
||||
Atom.withLabel("mobile:thread-composer:dispatching-message-id"),
|
||||
@@ -44,33 +45,6 @@ const queuedMessagesByThreadKeyAtom = Atom.make<Record<string, ReadonlyArray<Que
|
||||
{},
|
||||
).pipe(Atom.keepAlive, Atom.withLabel("mobile:thread-composer:queued-messages"));
|
||||
|
||||
function setDraftMessage(threadKey: string, value: string): void {
|
||||
const current = appAtomRegistry.get(draftMessageByThreadKeyAtom);
|
||||
appAtomRegistry.set(draftMessageByThreadKeyAtom, {
|
||||
...current,
|
||||
[threadKey]: value,
|
||||
});
|
||||
}
|
||||
|
||||
function appendDraftAttachments(
|
||||
threadKey: string,
|
||||
attachments: ReadonlyArray<DraftComposerImageAttachment>,
|
||||
): void {
|
||||
const current = appAtomRegistry.get(draftAttachmentsByThreadKeyAtom);
|
||||
appAtomRegistry.set(draftAttachmentsByThreadKeyAtom, {
|
||||
...current,
|
||||
[threadKey]: [...(current[threadKey] ?? []), ...attachments],
|
||||
});
|
||||
}
|
||||
|
||||
function appendDraftMessage(threadKey: string, value: string): void {
|
||||
const current = appAtomRegistry.get(draftMessageByThreadKeyAtom);
|
||||
appAtomRegistry.set(draftMessageByThreadKeyAtom, {
|
||||
...current,
|
||||
[threadKey]: `${current[threadKey] ?? ""}${value}`,
|
||||
});
|
||||
}
|
||||
|
||||
export function appendReviewCommentToDraft(input: {
|
||||
readonly environmentId: EnvironmentId;
|
||||
readonly threadId: ThreadId;
|
||||
@@ -78,15 +52,11 @@ export function appendReviewCommentToDraft(input: {
|
||||
readonly attachments?: ReadonlyArray<DraftComposerImageAttachment>;
|
||||
}): void {
|
||||
const threadKey = scopedThreadKey(input.environmentId, input.threadId);
|
||||
const current = appAtomRegistry.get(draftMessageByThreadKeyAtom);
|
||||
const existing = current[threadKey] ?? "";
|
||||
const existing = appAtomRegistry.get(composerDraftsAtom)[threadKey]?.text ?? "";
|
||||
const separator = existing.trim().length > 0 && !existing.endsWith("\n") ? "\n\n" : "";
|
||||
appAtomRegistry.set(draftMessageByThreadKeyAtom, {
|
||||
...current,
|
||||
[threadKey]: `${existing}${separator}${input.text}`,
|
||||
});
|
||||
setComposerDraftText(threadKey, `${existing}${separator}${input.text}`);
|
||||
if (input.attachments && input.attachments.length > 0) {
|
||||
appendDraftAttachments(threadKey, input.attachments);
|
||||
appendComposerDraftAttachments(threadKey, input.attachments);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,40 +64,18 @@ export function useThreadDraftForThread(input: {
|
||||
readonly environmentId?: EnvironmentId;
|
||||
readonly threadId?: ThreadId;
|
||||
}) {
|
||||
const draftMessageByThreadKey = useAtomValue(draftMessageByThreadKeyAtom);
|
||||
const draftAttachmentsByThreadKey = useAtomValue(draftAttachmentsByThreadKeyAtom);
|
||||
const threadKey =
|
||||
input.environmentId && input.threadId
|
||||
? scopedThreadKey(input.environmentId, input.threadId)
|
||||
: null;
|
||||
const draft = useComposerDraft(threadKey);
|
||||
|
||||
return {
|
||||
draftMessage: threadKey ? (draftMessageByThreadKey[threadKey] ?? "") : "",
|
||||
draftAttachments: threadKey ? (draftAttachmentsByThreadKey[threadKey] ?? []) : [],
|
||||
draftMessage: draft.text,
|
||||
draftAttachments: draft.attachments,
|
||||
};
|
||||
}
|
||||
|
||||
function clearDraft(threadKey: string): void {
|
||||
const draftMessages = appAtomRegistry.get(draftMessageByThreadKeyAtom);
|
||||
const draftAttachments = appAtomRegistry.get(draftAttachmentsByThreadKeyAtom);
|
||||
appAtomRegistry.set(draftMessageByThreadKeyAtom, {
|
||||
...draftMessages,
|
||||
[threadKey]: "",
|
||||
});
|
||||
appAtomRegistry.set(draftAttachmentsByThreadKeyAtom, {
|
||||
...draftAttachments,
|
||||
[threadKey]: [],
|
||||
});
|
||||
}
|
||||
|
||||
function removeDraftImage(threadKey: string, imageId: string): void {
|
||||
const current = appAtomRegistry.get(draftAttachmentsByThreadKeyAtom);
|
||||
appAtomRegistry.set(draftAttachmentsByThreadKeyAtom, {
|
||||
...current,
|
||||
[threadKey]: (current[threadKey] ?? []).filter((image) => image.id !== imageId),
|
||||
});
|
||||
}
|
||||
|
||||
function beginDispatchingQueuedMessage(queuedMessageId: MessageId): void {
|
||||
appAtomRegistry.set(dispatchingQueuedMessageIdAtom, queuedMessageId);
|
||||
}
|
||||
@@ -231,11 +179,14 @@ export function useThreadComposerState() {
|
||||
const { threads } = useRemoteCatalog();
|
||||
const { selectedThread: selectedThreadShell } = useThreadSelection();
|
||||
const selectedThread = useSelectedThreadDetail();
|
||||
const draftMessageByThreadKey = useAtomValue(draftMessageByThreadKeyAtom);
|
||||
const draftAttachmentsByThreadKey = useAtomValue(draftAttachmentsByThreadKeyAtom);
|
||||
const composerDrafts = useAtomValue(composerDraftsAtom);
|
||||
const dispatchingQueuedMessageId = useAtomValue(dispatchingQueuedMessageIdAtom);
|
||||
const queuedMessagesByThreadKey = useAtomValue(queuedMessagesByThreadKeyAtom);
|
||||
|
||||
useEffect(() => {
|
||||
ensureComposerDraftsLoaded();
|
||||
}, []);
|
||||
|
||||
const selectedThreadKey = selectedThreadShell
|
||||
? scopedThreadKey(selectedThreadShell.environmentId, selectedThreadShell.id)
|
||||
: null;
|
||||
@@ -252,10 +203,9 @@ export function useThreadComposerState() {
|
||||
[dispatchingQueuedMessageId, selectedThread, selectedThreadQueuedMessages],
|
||||
);
|
||||
|
||||
const draftMessage = selectedThreadKey ? (draftMessageByThreadKey[selectedThreadKey] ?? "") : "";
|
||||
const draftAttachments = selectedThreadKey
|
||||
? (draftAttachmentsByThreadKey[selectedThreadKey] ?? [])
|
||||
: [];
|
||||
const selectedDraft = selectedThreadKey ? composerDrafts[selectedThreadKey] : null;
|
||||
const draftMessage = selectedDraft?.text ?? "";
|
||||
const draftAttachments = selectedDraft?.attachments ?? [];
|
||||
const selectedThreadQueueCount = selectedThreadQueuedMessages.length;
|
||||
|
||||
const selectedThreadSessionActivity = useMemo(() => {
|
||||
@@ -350,8 +300,9 @@ export function useThreadComposerState() {
|
||||
}
|
||||
|
||||
const threadKey = scopedThreadKey(selectedThreadShell.environmentId, selectedThreadShell.id);
|
||||
const text = (draftMessageByThreadKey[threadKey] ?? "").trim();
|
||||
const attachments = draftAttachmentsByThreadKey[threadKey] ?? [];
|
||||
const draft = composerDrafts[threadKey];
|
||||
const text = (draft?.text ?? "").trim();
|
||||
const attachments = draft?.attachments ?? [];
|
||||
if (text.length === 0 && attachments.length === 0) {
|
||||
return;
|
||||
}
|
||||
@@ -366,8 +317,8 @@ export function useThreadComposerState() {
|
||||
attachments,
|
||||
createdAt: metadata.createdAt,
|
||||
});
|
||||
clearDraft(threadKey);
|
||||
}, [draftAttachmentsByThreadKey, draftMessageByThreadKey, selectedThreadShell]);
|
||||
clearComposerDraft(threadKey);
|
||||
}, [composerDrafts, selectedThreadShell]);
|
||||
|
||||
const onChangeDraftMessage = useCallback(
|
||||
(value: string) => {
|
||||
@@ -376,7 +327,7 @@ export function useThreadComposerState() {
|
||||
}
|
||||
|
||||
const threadKey = scopedThreadKey(selectedThreadShell.environmentId, selectedThreadShell.id);
|
||||
setDraftMessage(threadKey, value);
|
||||
setComposerDraftText(threadKey, value);
|
||||
},
|
||||
[selectedThreadShell],
|
||||
);
|
||||
@@ -388,15 +339,15 @@ export function useThreadComposerState() {
|
||||
|
||||
const threadKey = scopedThreadKey(selectedThreadShell.environmentId, selectedThreadShell.id);
|
||||
const result = await pickComposerImages({
|
||||
existingCount: draftAttachmentsByThreadKey[threadKey]?.length ?? 0,
|
||||
existingCount: composerDrafts[threadKey]?.attachments.length ?? 0,
|
||||
});
|
||||
if (result.images.length > 0) {
|
||||
appendDraftAttachments(threadKey, result.images);
|
||||
appendComposerDraftAttachments(threadKey, result.images);
|
||||
}
|
||||
if (result.error) {
|
||||
setPendingConnectionError(result.error);
|
||||
}
|
||||
}, [draftAttachmentsByThreadKey, selectedThreadShell]);
|
||||
}, [composerDrafts, selectedThreadShell]);
|
||||
|
||||
const onPasteIntoDraft = useCallback(async () => {
|
||||
if (!selectedThreadShell) {
|
||||
@@ -405,18 +356,18 @@ export function useThreadComposerState() {
|
||||
|
||||
const threadKey = scopedThreadKey(selectedThreadShell.environmentId, selectedThreadShell.id);
|
||||
const result = await pasteComposerClipboard({
|
||||
existingCount: draftAttachmentsByThreadKey[threadKey]?.length ?? 0,
|
||||
existingCount: composerDrafts[threadKey]?.attachments.length ?? 0,
|
||||
});
|
||||
if (result.images.length > 0) {
|
||||
appendDraftAttachments(threadKey, result.images);
|
||||
appendComposerDraftAttachments(threadKey, result.images);
|
||||
}
|
||||
if (result.text) {
|
||||
appendDraftMessage(threadKey, result.text);
|
||||
appendComposerDraftText(threadKey, result.text);
|
||||
}
|
||||
if (result.error) {
|
||||
setPendingConnectionError(result.error);
|
||||
}
|
||||
}, [draftAttachmentsByThreadKey, selectedThreadShell]);
|
||||
}, [composerDrafts, selectedThreadShell]);
|
||||
|
||||
const onNativePasteImages = useCallback(
|
||||
async (uris: ReadonlyArray<string>) => {
|
||||
@@ -428,16 +379,16 @@ export function useThreadComposerState() {
|
||||
try {
|
||||
const images = await convertPastedImagesToAttachments({
|
||||
uris,
|
||||
existingCount: draftAttachmentsByThreadKey[threadKey]?.length ?? 0,
|
||||
existingCount: composerDrafts[threadKey]?.attachments.length ?? 0,
|
||||
});
|
||||
if (images.length > 0) {
|
||||
appendDraftAttachments(threadKey, images);
|
||||
appendComposerDraftAttachments(threadKey, images);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("[native paste] error converting images", error);
|
||||
}
|
||||
},
|
||||
[draftAttachmentsByThreadKey, selectedThreadShell],
|
||||
[composerDrafts, selectedThreadShell],
|
||||
);
|
||||
|
||||
const onRemoveDraftImage = useCallback(
|
||||
@@ -447,7 +398,7 @@ export function useThreadComposerState() {
|
||||
}
|
||||
|
||||
const threadKey = scopedThreadKey(selectedThreadShell.environmentId, selectedThreadShell.id);
|
||||
removeDraftImage(threadKey, imageId);
|
||||
removeComposerDraftAttachment(threadKey, imageId);
|
||||
},
|
||||
[selectedThreadShell],
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user