The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { msg, useGT, useMessages } from "gt-react-native"; |
| 2 | import { Pressable, ScrollView, StyleSheet, View } from "react-native"; |
| 3 | |
| 4 | import { AppText as Text } from "../../components/ui/AppText"; |
| 5 | import { GlassSurface } from "../../components/ui/GlassSurface"; |
| 6 | import { PullRequestAvatar } from "./PullRequestPresentation"; |
| 7 | import type { PullRequestCompletion } from "@t3tools/shared/pullRequestComposerTrigger"; |
| 8 | import type { usePullRequestCompletions } from "./usePullRequestCompletions"; |
| 9 | |
| 10 | const COPY = { |
| 11 | mention: { |
| 12 | label: msg("Mention a user"), |
| 13 | pending: msg("Searching users..."), |
| 14 | failed: msg("Couldn't search users on the host"), |
| 15 | none: msg("No matching users"), |
| 16 | }, |
| 17 | reference: { |
| 18 | label: msg("Reference an issue or change request"), |
| 19 | pending: msg("Searching..."), |
| 20 | failed: msg("Couldn't search the host"), |
| 21 | none: msg("No matching issues or change requests"), |
| 22 | }, |
| 23 | } as const; |
| 24 | |
| 25 | const STATE_LABEL = { |
| 26 | open: msg("Open", { $context: "issue or pull request state" }), |
| 27 | closed: msg("Closed", { $context: "issue or pull request state" }), |
| 28 | merged: msg("Merged", { $context: "issue or pull request state" }), |
| 29 | }; |
| 30 | |
| 31 | function CompletionRow({ completion }: { readonly completion: PullRequestCompletion }) { |
| 32 | const m = useMessages(); |
| 33 | if (completion.kind === "mention") { |
| 34 | const { actor } = completion; |
| 35 | return ( |
| 36 | <> |
| 37 | <PullRequestAvatar actor={actor} size={20} /> |
| 38 | <Text className="shrink-0 text-base font-t3-medium text-foreground" numberOfLines={1}> |
| 39 | {actor.login} |
| 40 | </Text> |
| 41 | {actor.name && actor.name !== actor.login ? ( |
| 42 | <Text className="min-w-0 flex-1 text-xs text-foreground-muted" numberOfLines={1}> |
| 43 | {actor.name} |
| 44 | </Text> |
| 45 | ) : null} |
| 46 | </> |
| 47 | ); |
| 48 | } |
| 49 | const { candidate } = completion; |
| 50 | return ( |
| 51 | <> |
| 52 | <Text className="shrink-0 text-base font-t3-medium text-foreground" numberOfLines={1}> |
| 53 | {candidate.reference} |
| 54 | </Text> |
| 55 | <Text className="min-w-0 flex-1 text-sm text-foreground-muted" numberOfLines={1}> |
| 56 | {candidate.title} |
| 57 | </Text> |
| 58 | <Text className="shrink-0 text-xs text-foreground-tertiary"> |
| 59 | {m(STATE_LABEL[candidate.state])} |
| 60 | </Text> |
| 61 | </> |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | /** The `@`, `#` and `!` suggestions for a pull request text input, rendered just above it. */ |
| 66 | export function PullRequestCompletionSuggestions({ |
| 67 | completions, |
| 68 | }: { |
| 69 | readonly completions: ReturnType<typeof usePullRequestCompletions>; |
| 70 | }) { |
| 71 | const gt = useGT(); |
| 72 | const m = useMessages(); |
| 73 | if (completions.kind === null) return null; |
| 74 | const copy = COPY[completions.kind]; |
| 75 | return ( |
| 76 | <GlassSurface |
| 77 | glassEffectStyle="clear" |
| 78 | tintColorClassName="accent-glass-surface" |
| 79 | style={{ borderRadius: 16, overflow: "hidden" }} |
| 80 | > |
| 81 | {completions.candidates.length > 0 ? ( |
| 82 | <ScrollView |
| 83 | className="max-h-[180px]" |
| 84 | keyboardShouldPersistTaps="always" |
| 85 | showsVerticalScrollIndicator={false} |
| 86 | accessibilityLabel={m(copy.label)} |
| 87 | > |
| 88 | {completions.candidates.map((completion, index) => ( |
| 89 | <Pressable |
| 90 | key={completion.token} |
| 91 | accessibilityRole="button" |
| 92 | accessibilityLabel={gt("Insert {token}", { token: completion.token })} |
| 93 | onPress={() => completions.select(completion)} |
| 94 | className="flex-row items-center gap-2.5 border-border px-3.5 py-2.5 active:opacity-60" |
| 95 | style={{ |
| 96 | borderBottomWidth: |
| 97 | index === completions.candidates.length - 1 ? 0 : StyleSheet.hairlineWidth, |
| 98 | }} |
| 99 | > |
| 100 | <CompletionRow completion={completion} /> |
| 101 | </Pressable> |
| 102 | ))} |
| 103 | </ScrollView> |
| 104 | ) : ( |
| 105 | <View className="px-3.5 py-2.5"> |
| 106 | <Text className="text-xs text-foreground-tertiary"> |
| 107 | {m(copy[completions.isLoading ? "pending" : completions.failed ? "failed" : "none"])} |
| 108 | </Text> |
| 109 | </View> |
| 110 | )} |
| 111 | </GlassSurface> |
| 112 | ); |
| 113 | } |