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

ConnectionsRouteScreen.tsx

106 lines4.1 KB

1import { ScreenScrollView as ScrollView } from "../../components/ScreenScrollView";
2import { NativeHeaderToolbar } from "../../native/StackHeader";
3import { useNavigation } from "@react-navigation/native";
4import { SymbolView } from "../../components/AppSymbol";
5import type { EnvironmentId } from "@t3tools/contracts";
6import { useCallback, useState } from "react";
7import { Platform, View } from "react-native";
8import { useSafeAreaInsets } from "react-native-safe-area-context";
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";
15import { GitHubRoutingSettings } from "./GitHubRoutingSettings";
16​
17export function ConnectionsRouteScreen() {
18 const {
19 connectedEnvironments,
20 onReconnectEnvironment,
21 onRemoveEnvironmentPress,
22 onSetEnvironmentEnabled,
23 onUpdateEnvironment,
24 } = useRemoteConnections();
25 const navigation = useNavigation();
26 const insets = useSafeAreaInsets();
27 const hasEnvironments = connectedEnvironments.length > 0;
28 const [expandedId, setExpandedId] = useState<EnvironmentId | null>(null);
29 const handleToggle = useCallback((environmentId: EnvironmentId) => {
30 setExpandedId((prev) => (prev === environmentId ? null : environmentId));
31 }, []);
32​
33 return (
34 <View collapsable={false} className="flex-1 bg-sheet">
35 {Platform.OS === "android" ? (
36 <AndroidScreenHeader
37 title="Environments"
38 onBack={() => navigation.goBack()}
39 actions={[
40 {
41 accessibilityLabel: "Add environment",
42 icon: "plus",
43 onPress: () => navigation.navigate("ConnectionsNew"),
44 },
45 ]}
46 />
47 ) : (
48 <NativeHeaderToolbar placement="right">
49 <NativeHeaderToolbar.Button
50 icon="plus"
51 onPress={() => navigation.navigate("ConnectionsNew")}
52 separateBackground
53 />
54 </NativeHeaderToolbar>
55 )}
56 <ScrollView
57 contentInsetAdjustmentBehavior="automatic"
58 showsVerticalScrollIndicator={false}
59 className="flex-1"
60 contentContainerStyle={{
61 paddingBottom: Math.max(insets.bottom, 18) + 18,
62 paddingHorizontal: 20,
63 paddingTop: 16,
64 }}
65 >
66 {hasEnvironments ? (
67 <View collapsable={false} className="overflow-hidden rounded-[24px] bg-card">
68 {connectedEnvironments.map((environment, index) => (
69 <View
70 key={environment.environmentId}
71 collapsable={false}
72 className={cn(index !== 0 && "border-t border-border")}
73 >
74 <ConnectionEnvironmentRow
75 environment={environment}
76 expanded={expandedId === environment.environmentId}
77 onToggle={() => handleToggle(environment.environmentId)}
78 onReconnect={onReconnectEnvironment}
79 onRemove={onRemoveEnvironmentPress}
80 onSetEnabled={onSetEnvironmentEnabled}
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 tintColorClassName={"accent-icon-muted"}
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 <GitHubRoutingSettings />
103 </ScrollView>
104 </View>
105 );