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

ConnectionsRouteScreen.tsx

86 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 { AndroidScreenHeader } from "../../components/ui/AndroidScreenHeader";
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 <AndroidScreenHeader
35 title="Environments"
36 onBack={() => navigation.goBack()}
37 actions={[
38 {
39 accessibilityLabel: "Add environment",
40 icon: "plus",
41 onPress: () => navigation.navigate("ConnectionsNew"),
42 },
43 ]}
44 />
45 ) : (
46 <Toolbar placement="right">
47 <Toolbar.Button
48 icon="plus"
49 onPress={() => navigation.navigate("ConnectionsNew")}
50 separateBackground
51 />
52 </Toolbar>
53 )}
54 <ScrollView
55 contentInsetAdjustmentBehavior="automatic"
56 showsVerticalScrollIndicator={false}
57 className="flex-1"
58 contentContainerStyle={{
59 paddingBottom: Math.max(insets.bottom, 18) + 18,
60 paddingHorizontal: 20,
61 paddingTop: 16,
62 }}
63 >
64 <LocalEnvironmentList
65 environments={connectedEnvironments}
66 expandedId={expandedId}
67 onToggle={handleToggle}
68 onReconnect={onReconnectEnvironment}
69 onRemove={onRemoveEnvironmentPress}
70 onSetEnabled={onSetEnvironmentEnabled}
71 onUpdate={onUpdateEnvironment}
72 />
73 {connectedEnvironments
74 .filter((environment) => environment.connectionState === "connected")
75 .map((environment) => (
76 <LinkedEnvironmentsSection
77 key={environment.environmentId}
78 environmentId={environment.environmentId}
79 environmentLabel={environment.environmentLabel}
80 />
81 ))}
82 <PullRequestRoutingSettings />
83 </ScrollView>
84 </View>
85 );