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

ConnectionsRouteScreen.tsx

87 lines3.0 KB

1import { Toolbar } from "../../components/ui/Toolbar";
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 { Platform, 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 {
18 connectedEnvironments,
19 onReconnectEnvironment,
20 onRemoveEnvironmentPress,
21 onSetEnvironmentEnabled,
22 onUpdateEnvironment,
23 } = useRemoteConnections();
24 const navigation = useNavigation();
25 const insets = useSafeAreaInsets();
26 const [expandedId, setExpandedId] = useState<EnvironmentId | null>(null);
27 const handleToggle = (environmentId: EnvironmentId) => {
28 setExpandedId((prev) => (prev === environmentId ? null : environmentId));
29 };
30​
31 return (
32 <View collapsable={false} className="flex-1 bg-sheet">
33 {Platform.OS === "android" ? (
34 <AppBar
35 embedded
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 <Toolbar placement="right">
48 <Toolbar.Button
49 icon="plus"
50 onPress={() => navigation.navigate("ConnectionsNew")}
51 separateBackground
52 />
53 </Toolbar>
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 <LocalEnvironmentList
66 environments={connectedEnvironments}
67 expandedId={expandedId}
68 onToggle={handleToggle}
69 onReconnect={onReconnectEnvironment}
70 onRemove={onRemoveEnvironmentPress}
71 onSetEnabled={onSetEnvironmentEnabled}
72 onUpdate={onUpdateEnvironment}
73 />
74 {connectedEnvironments
75 .filter((environment) => environment.connectionState === "connected")
76 .map((environment) => (
77 <LinkedEnvironmentsSection
78 key={environment.environmentId}
79 environmentId={environment.environmentId}
80 environmentLabel={environment.environmentLabel}
81 />
82 ))}
83 <PullRequestRoutingSettings />
84 </ScrollView>
85 </View>
86 );