Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ConnectionsRouteScreen.tsx

101 lines3.8 KB

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