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

ConnectionsRouteScreen.tsx

75 lines2.6 KB

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