Open History to see the last commit
1import { NativeHeaderToolbar } from "../../native/StackHeader";
2import { useNavigation } from "@react-navigation/native";
3import { SymbolView } from "../../components/AppSymbol";
4import type { EnvironmentId } from "@t3tools/contracts";
5import { useCallback, useState } from "react";
6import { Platform, ScrollView, View } from "react-native";
7import { useSafeAreaInsets } from "react-native-safe-area-context";
8import { useThemeColor } from "../../lib/useThemeColor";
9
10import { AndroidScreenHeader } from "../../components/AndroidScreenHeader";
11import { AppText as Text } from "../../components/AppText";
12import { cn } from "../../lib/cn";
13import { useRemoteConnections } from "../../state/use-remote-environment-registry";
14import { ConnectionEnvironmentRow } from "./ConnectionEnvironmentRow";
15
16export function ConnectionsRouteScreen() {
17 const {
18 connectedEnvironments,
19 onReconnectEnvironment,
20 onRemoveEnvironmentPress,
21 onUpdateEnvironment,
22 } = useRemoteConnections();
23 const navigation = useNavigation();
24 const insets = useSafeAreaInsets();
25 const hasEnvironments = connectedEnvironments.length > 0;
26 const [expandedId, setExpandedId] = useState<EnvironmentId | null>(null);
27
28 const accentColor = useThemeColor("--color-icon-muted");
29
30 const handleToggle = useCallback((environmentId: EnvironmentId) => {
31 setExpandedId((prev) => (prev === environmentId ? null : environmentId));
32 }, []);
33
34 return (
35 <View collapsable={false} className="flex-1 bg-sheet">
36 {Platform.OS === "android" ? (
37 <AndroidScreenHeader
38 title="Environments"
39 onBack={() => navigation.goBack()}
40 actions={[
41 {
42 accessibilityLabel: "Add environment",
43 icon: "plus",
44 onPress: () => navigation.navigate("ConnectionsNew"),
45 },
46 ]}
47 />
48 ) : (
49 <NativeHeaderToolbar placement="right">
50 <NativeHeaderToolbar.Button
51 icon="plus"
52 onPress={() => navigation.navigate("ConnectionsNew")}
53 separateBackground
54 />
55 </NativeHeaderToolbar>
56 )}
57 <ScrollView
58 contentInsetAdjustmentBehavior="automatic"
59 showsVerticalScrollIndicator={false}
60 className="flex-1"
61 contentInset={{ bottom: Math.max(insets.bottom, 18) + 18 }}
62 contentContainerStyle={{
63 paddingHorizontal: 20,
64 paddingTop: 16,
65 }}
66 >
67 {hasEnvironments ? (
68 <View collapsable={false} className="overflow-hidden rounded-[24px] bg-card">
69 {connectedEnvironments.map((environment, index) => (
70 <View
71 key={environment.environmentId}
72 collapsable={false}
73 className={cn(index !== 0 && "border-t border-border")}
74 >
75 <ConnectionEnvironmentRow
76 environment={environment}
77 expanded={expandedId === environment.environmentId}
78 onToggle={() => handleToggle(environment.environmentId)}
79 onReconnect={onReconnectEnvironment}
80 onRemove={onRemoveEnvironmentPress}
81 onUpdate={onUpdateEnvironment}
82 />
83 </View>
84 ))}
85 </View>
86 ) : (
87 <View collapsable={false} className="items-center gap-3 rounded-[24px] bg-card px-6 py-8">
88 <View className="h-12 w-12 items-center justify-center rounded-[16px] bg-subtle">
89 <SymbolView
90 name="point.3.connected.trianglepath.dotted"
91 size={20}
92 tintColor={accentColor}
93 type="monochrome"
94 />
95 </View>
96 <Text className="text-center text-sm leading-normal text-foreground-muted">
97 No environments connected yet.{"\n"}Tap{" "}
98 <Text className="font-t3-bold text-foreground">+</Text> to add one.
99 </Text>
100 </View>
101 )}
102 </ScrollView>
103 </View>
104 );
105}