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 { EnvironmentId } from "@t3tools/contracts"; |
| 2 | import { |
| 3 | readHostCredentialSettings, |
| 4 | sourceControlClients, |
| 5 | } from "@t3tools/client-runtime/source-control-clients"; |
| 6 | import { T, Var } from "gt-react-native"; |
| 7 | import { Pressable, View } from "react-native"; |
| 8 | import { tryOpenExternalUrl } from "../../lib/openExternalUrl"; |
| 9 | |
| 10 | import { AppText as Text } from "../../components/ui/AppText"; |
| 11 | import { useEnvironmentPresentation } from "../../state/presentation"; |
| 12 | import { useEnvironmentQuery } from "../../state/query"; |
| 13 | import { sourceControlEnvironment } from "../../state/sourceControl"; |
| 14 | |
| 15 | /** |
| 16 | * Says when the server's forge app sign-in cannot reach `repository`, so requests there fall back |
| 17 | * to the user's own login. Renders nothing for servers that do not use the app. |
| 18 | */ |
| 19 | export function SourceControlAppAccessNotice(props: { |
| 20 | readonly environmentId: string; |
| 21 | readonly provider: string | undefined; |
| 22 | readonly host: string | undefined; |
| 23 | /** `owner/name`. */ |
| 24 | readonly repository: string; |
| 25 | }) { |
| 26 | const environmentId = EnvironmentId.make(props.environmentId); |
| 27 | const { presentation } = useEnvironmentPresentation(environmentId); |
| 28 | const definition = props.provider ? sourceControlClients.find(props.provider) : undefined; |
| 29 | const appSignIn = definition?.credentials?.appSignIn; |
| 30 | const host = (props.host ?? definition?.publicHost ?? "").toLowerCase(); |
| 31 | const settings = presentation?.serverConfig?.settings; |
| 32 | const signedIn = |
| 33 | definition !== undefined && |
| 34 | settings !== undefined && |
| 35 | (readHostCredentialSettings(settings, definition.kind).signIns[host] ?? "").length > 0; |
| 36 | const access = useEnvironmentQuery( |
| 37 | definition !== undefined && appSignIn?.hosts.includes(host) && signedIn |
| 38 | ? sourceControlEnvironment.appAccess({ |
| 39 | environmentId, |
| 40 | input: { provider: definition.kind, host, repository: props.repository }, |
| 41 | }) |
| 42 | : null, |
| 43 | ); |
| 44 | if (appSignIn === undefined || access.data?.status !== "not-covered") return null; |
| 45 | const owner = props.repository.split("/")[0] ?? props.repository; |
| 46 | |
| 47 | return ( |
| 48 | <View className="mb-4 gap-1 rounded-2xl bg-grouped-card px-4 py-3"> |
| 49 | <Text className="text-sm text-foreground-muted"> |
| 50 | <T> |
| 51 | <Var>{appSignIn.appName}</Var> isn't installed on <Var>{owner}</Var>, so requests here use |
| 52 | your own GitHub login and its lower rate limit. |
| 53 | </T> |
| 54 | </Text> |
| 55 | <Pressable |
| 56 | accessibilityRole="link" |
| 57 | onPress={() => void tryOpenExternalUrl(appSignIn.installUrl, "provider-auth")} |
| 58 | > |
| 59 | <Text className="text-sm font-t3-bold text-foreground"> |
| 60 | <T> |
| 61 | Install on <Var>{owner}</Var> |
| 62 | </T> |
| 63 | </Text> |
| 64 | </Pressable> |
| 65 | </View> |
| 66 | ); |
| 67 | } |