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

ConnectionsRouteScreen.tsx

78 lines2.7 KB

1import { useGT } from "gt-react-native";
2import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
3​
4import { useNavigation } from "@react-navigation/native";
5import type { EnvironmentId } from "@t3tools/contracts";
6import { useState } from "react";
7import { View } from "react-native";
8import { useSafeAreaInsets } from "react-native-safe-area-context";
9​
10import { AppBar } from "../../components/ui/AppBar";
11import { useRemoteConnections } from "../../state/use-remote-environment-registry";
12import { LocalEnvironmentList } from "./LocalEnvironmentList";
13import { PullRequestRoutingSettings } from "./PullRequestRoutingSettings";
14import { LinkedEnvironmentsSection } from "./LinkedEnvironmentsSection";
15​
16export function ConnectionsRouteScreen() {
17 const gt = useGT();
18 const {
19 connectedEnvironments,
20 onReconnectEnvironment,
21 onRemoveEnvironmentPress,
22 onSetEnvironmentEnabled,
23 onUpdateEnvironment,
24 } = useRemoteConnections();
25 const navigation = useNavigation();
26 const insets = useSafeAreaInsets();
27 const [expandedId, setExpandedId] = useState<EnvironmentId | null>(null);
28 const handleToggle = (environmentId: EnvironmentId) => {
29 setExpandedId((prev) => (prev === environmentId ? null : environmentId));
30 };
31​
32 return (
33 <View collapsable={false} className="flex-1 bg-sheet">
34 <AppBar
35 title={gt("Environments")}
36 onClose={() => navigation.goBack()}
37 closeAccessibilityLabel={gt("Close environments")}
38 actions={[
39 {
40 accessibilityLabel: gt("Add environment"),
41 icon: "plus",
42 onPress: () => navigation.navigate("ConnectionsNew"),
43 },
44 ]}
45 />
46 <ScrollView
47 contentInsetAdjustmentBehavior="automatic"
48 showsVerticalScrollIndicator={false}
49 className="flex-1"
50 contentContainerStyle={{
51 paddingBottom: Math.max(insets.bottom, 18) + 18,
52 paddingHorizontal: 20,
53 paddingTop: 16,
54 }}
55 >
56 <LocalEnvironmentList
57 environments={connectedEnvironments}
58 expandedId={expandedId}
59 onToggle={handleToggle}
60 onReconnect={onReconnectEnvironment}
61 onRemove={onRemoveEnvironmentPress}
62 onSetEnabled={onSetEnvironmentEnabled}
63 onUpdate={onUpdateEnvironment}
64 />
65 {connectedEnvironments
66 .filter((environment) => environment.connectionState === "connected")
67 .map((environment) => (
68 <LinkedEnvironmentsSection
69 key={environment.environmentId}
70 environmentId={environment.environmentId}
71 environmentLabel={environment.environmentLabel}
72 />
73 ))}
74 <PullRequestRoutingSettings />
75 </ScrollView>
76 </View>
77 );