The best way to control Claude Code, Codex and more from any computer or phone

main
tsx 123 lines 4.95 KB
Raw
1 import { msg, useGT, useMessages } from "gt-react-native";
2 import { ListChoiceRow } from "../../components/ui/ListChoiceRow";
3 import * as Dialog from "../../components/ui/Dialog";
4 import { useAtomValue } from "@effect/atom-react";
5 import {
6 connectionCatalogDisplayUrl,
7 pullRequestRoutingConnectionKey,
8 pullRequestRoutingPermissionFor,
9 type PullRequestRoutingPermission,
10 } from "@t3tools/client-runtime/connection";
11 import { useState } from "react";
12 import { Pressable, View } from "react-native";
13
14 import { AppText as Text } from "../../components/ui/AppText";
15 import { SymbolView } from "../../components/ui/AppSymbol";
16 import { environmentCatalog } from "../../connection/catalog";
17 import { useAtomCommand } from "../../state/use-atom-command";
18 import { SettingsSection } from "../settings/components/SettingsSection";
19
20 const options: ReadonlyArray<{
21 value: PullRequestRoutingPermission;
22 label: string;
23 description: string;
24 }> = [
25 {
26 value: "off",
27 label: msg("Off", { $context: "pull request routing permission" }),
28 description: msg("Keep source control requests on this environment."),
29 },
30 {
31 value: "read",
32 label: msg("Read PRs"),
33 description: msg("Share PR data with other enabled environments."),
34 },
35 {
36 value: "read-write",
37 label: msg("Read and act"),
38 description: msg(
39 "Actions may use broader source control permissions than the original environment.",
40 ),
41 },
42 ];
43
44 export function PullRequestRoutingSettings() {
45 const gt = useGT();
46 const m = useMessages();
47 const catalog = useAtomValue(environmentCatalog.catalogValueAtom);
48 const permissions = useAtomValue(environmentCatalog.pullRequestRoutingPermissionsValueAtom);
49 const update = useAtomCommand(environmentCatalog.setPullRequestRoutingPermission);
50 const [expanded, setExpanded] = useState<string | null>(null);
51 const [saving, setSaving] = useState(false);
52 if (catalog.entries.size === 0) return null;
53
54 return (
55 <View className="mt-5 gap-3">
56 <SettingsSection title={gt("Pull request routing")}>
57 {[...catalog.entries.values()].map((entry) => {
58 const environmentId = entry.target.environmentId;
59 const selected = pullRequestRoutingPermissionFor(entry, permissions);
60 const disabled =
61 !catalog.isReady || saving || pullRequestRoutingConnectionKey(entry) === null;
62 return (
63 <View key={environmentId}>
64 <Pressable
65 accessibilityRole="button"
66 accessibilityLabel={gt("{environment} pull request routing", {
67 environment: entry.target.label,
68 })}
69 accessibilityState={{ expanded: expanded === environmentId }}
70 className="flex-row items-center gap-3 p-4"
71 onPress={() => setExpanded(expanded === environmentId ? null : environmentId)}
72 >
73 <View className="min-w-0 flex-1 gap-0.5">
74 <Text className="text-base font-t3-bold text-foreground">
75 {entry.target.label}
76 </Text>
77 <Text className="text-xs text-foreground-muted" numberOfLines={1}>
78 {connectionCatalogDisplayUrl(entry) ?? "T3 Connect"}
79 </Text>
80 </View>
81 <Text className="text-sm text-foreground-muted">
82 {m(options.find((option) => option.value === selected)?.label ?? "")}
83 </Text>
84 <SymbolView
85 name={expanded === environmentId ? "chevron.up" : "chevron.down"}
86 size={12}
87 tintColorClassName="accent-icon-muted"
88 />
89 </Pressable>
90 {expanded === environmentId
91 ? options.map((option) => (
92 <ListChoiceRow
93 key={option.value}
94 label={m(option.label)}
95 description={m(option.description)}
96 selected={selected === option.value}
97 disabled={disabled}
98 onPress={() => {
99 setSaving(true);
100 void update({ environmentId, permission: option.value }).then((result) => {
101 setSaving(false);
102 if (result._tag === "Failure")
103 Dialog.alert(
104 gt("Could not save pull request routing permission"),
105 gt("Try again before leaving this screen."),
106 );
107 });
108 }}
109 />
110 ))
111 : null}
112 </View>
113 );
114 })}
115 </SettingsSection>
116 <Text className="px-2 text-sm text-foreground-muted">
117 {gt(
118 "Choose environments you trust to share PR data and use each other's source control access. Enable both environments. This applies only to this client.",
119 )}
120 </Text>
121 </View>
122 );
123 }