The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { useGT } from "gt-react-native"; |
| 2 | import { AppBar } from "../../components/ui/AppBar"; |
| 3 | import { Button } from "../../components/ui/Button"; |
| 4 | import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView"; |
| 5 | |
| 6 | import { useAuth } from "@clerk/expo"; |
| 7 | import { useNavigation } from "@react-navigation/native"; |
| 8 | import { useState } from "react"; |
| 9 | import { View } from "react-native"; |
| 10 | import { RefreshControl } from "../../components/ui/RefreshControl"; |
| 11 | import { useSafeAreaInsets } from "react-native-safe-area-context"; |
| 12 | |
| 13 | import { reportAtomCommandResult, settlePromise } from "@t3tools/client-runtime/state/runtime"; |
| 14 | import { AppText as Text } from "../../components/ui/AppText"; |
| 15 | import { useRemoteConnections } from "../../state/use-remote-environment-registry"; |
| 16 | import { CloudEnvironmentRows } from "../connection/CloudEnvironmentRows"; |
| 17 | import { splitEnvironmentSections } from "../connection/environmentSections"; |
| 18 | import { useConnectionController } from "../connection/useConnectionController"; |
| 19 | import { optOutOfConnectOnboarding } from "./connectOnboardingOptOut"; |
| 20 | import { hasCloudPublicConfig } from "./publicConfig"; |
| 21 | |
| 22 | // Only reachable with cloud config: onboarding is requested after a T3 Connect |
| 23 | // sign-in, and appLinking drops the deep link otherwise. |
| 24 | export function ConnectOnboardingRouteScreen() { |
| 25 | return hasCloudPublicConfig() ? <ConfiguredConnectOnboardingRouteScreen /> : null; |
| 26 | } |
| 27 | |
| 28 | function ConfiguredConnectOnboardingRouteScreen() { |
| 29 | const gt = useGT(); |
| 30 | const navigation = useNavigation(); |
| 31 | const insets = useSafeAreaInsets(); |
| 32 | const { isSignedIn, userId } = useAuth({ treatPendingAsSignedOut: false }); |
| 33 | const { connectedEnvironments, onSetEnvironmentEnabled, onRemoveEnvironmentPress } = |
| 34 | useRemoteConnections(); |
| 35 | const { refreshRelayEnvironments } = useConnectionController(); |
| 36 | const { connectedCloudEnvironments } = splitEnvironmentSections({ |
| 37 | connectedEnvironments, |
| 38 | cloudEnvironments: null, |
| 39 | }); |
| 40 | |
| 41 | const [isRefreshing, setIsRefreshing] = useState(false); |
| 42 | const handleRefresh = () => { |
| 43 | setIsRefreshing(true); |
| 44 | void refreshRelayEnvironments().finally(() => setIsRefreshing(false)); |
| 45 | }; |
| 46 | |
| 47 | const handleClose = () => { |
| 48 | navigation.goBack(); |
| 49 | }; |
| 50 | |
| 51 | // Persist before dismissing so quick sign-out/sign-in cannot outrun the write. |
| 52 | const handleDontShowAgain = () => { |
| 53 | void (async () => { |
| 54 | if (userId) { |
| 55 | const result = await settlePromise(() => optOutOfConnectOnboarding(userId)); |
| 56 | reportAtomCommandResult(result, { label: "connect onboarding opt-out" }); |
| 57 | } |
| 58 | navigation.goBack(); |
| 59 | })(); |
| 60 | }; |
| 61 | |
| 62 | return ( |
| 63 | <View collapsable={false} className="flex-1 bg-sheet"> |
| 64 | <AppBar |
| 65 | title={gt("Set up {product}", { product: "T3 Connect" })} |
| 66 | onClose={handleClose} |
| 67 | refresh={{ |
| 68 | accessibilityLabel: gt("Refresh environments"), |
| 69 | disabled: isRefreshing, |
| 70 | onPress: handleRefresh, |
| 71 | }} |
| 72 | /> |
| 73 | <ScrollView |
| 74 | nestedScrollEnabled |
| 75 | alwaysBounceVertical |
| 76 | contentInsetAdjustmentBehavior="automatic" |
| 77 | showsVerticalScrollIndicator={false} |
| 78 | className="flex-1" |
| 79 | contentContainerStyle={{ |
| 80 | gap: 16, |
| 81 | paddingHorizontal: 20, |
| 82 | paddingTop: 16, |
| 83 | paddingBottom: Math.max(insets.bottom, 18) + 18, |
| 84 | }} |
| 85 | refreshControl={<RefreshControl refreshing={isRefreshing} onRefresh={handleRefresh} />} |
| 86 | > |
| 87 | {isSignedIn ? ( |
| 88 | <CloudEnvironmentRows |
| 89 | connectedCloudEnvironments={connectedCloudEnvironments} |
| 90 | onSetEnvironmentEnabled={onSetEnvironmentEnabled} |
| 91 | onRemoveEnvironment={onRemoveEnvironmentPress} |
| 92 | showHeader={false} |
| 93 | /> |
| 94 | ) : ( |
| 95 | <View collapsable={false} className="rounded-[24px] bg-grouped-card p-5"> |
| 96 | <Text className="text-sm leading-normal text-foreground-muted"> |
| 97 | {gt("Sign in to your T3 account to set up {product}.", { product: "T3 Connect" })} |
| 98 | </Text> |
| 99 | </View> |
| 100 | )} |
| 101 | |
| 102 | {userId ? ( |
| 103 | <Button label={gt("Don't show this again")} tone="text" onPress={handleDontShowAgain} /> |
| 104 | ) : null} |
| 105 | </ScrollView> |
| 106 | </View> |
| 107 | ); |
| 108 | } |