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