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

main
tsx 53 lines 2 KB
Raw
1 import { useAtomValue } from "@effect/atom-react";
2 import type { EnvironmentId } from "@t3tools/contracts";
3 import { CHATGPT_USAGE_URL } from "@t3tools/shared/usageLimits";
4 import { collectExternalUsageLinks } from "@t3tools/shared/usageLimitsCopy";
5 import { T, useMessages, Var } from "gt-react-native";
6 import { Pressable, View } from "react-native";
7 import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
8 import { AppText as Text } from "../../components/ui/AppText";
9 import { ProviderIcon } from "../../components/ProviderIcon";
10 import { environmentPresentations } from "../../state/presentation";
11
12 export function ChatGptUsageSummary({
13 selectedEnvironmentIds,
14 }: {
15 selectedEnvironmentIds: ReadonlySet<EnvironmentId> | null;
16 }) {
17 const presentations = useAtomValue(environmentPresentations.presentationsWithProvidersAtom);
18 const m = useMessages();
19 const selected =
20 selectedEnvironmentIds === null
21 ? presentations
22 : new Map([...presentations].filter(([id]) => selectedEnvironmentIds.has(id)));
23 const usage = collectExternalUsageLinks(selected, m).find(
24 (link) => link.url === CHATGPT_USAGE_URL,
25 );
26 if (!usage) return null;
27 return (
28 <View className="gap-1">
29 <View className="flex-row items-center justify-between gap-3">
30 <View className="flex-row items-center gap-2">
31 <ProviderIcon provider="codex" size={16} />
32 <Text className="text-sm text-foreground">
33 <T>ChatGPT shared usage</T>
34 </Text>
35 </View>
36 <Pressable
37 accessibilityRole="link"
38 className="min-h-11 justify-center"
39 onPress={() => void tryOpenExternalUrl(usage.url)}
40 >
41 <Text className="text-sm font-t3-medium text-primary">
42 <T>Manage usage</T>
43 </Text>
44 </Pressable>
45 </View>
46 <Text className="text-xs text-foreground-muted">
47 <T>
48 <Var>{usage.accounts.join(", ")}</Var>. Open ChatGPT with the account you connected.
49 </T>
50 </Text>
51 </View>
52 );
53 }