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 { sourceControlClients } from "@t3tools/client-runtime/source-control-clients"; |
| 2 | import { changeRequestTermKind } from "../../lib/changeRequestTerm"; |
| 3 | import { useGT, useMessages } from "gt-react-native"; |
| 4 | import { memo } from "react"; |
| 5 | import { Pressable, View } from "react-native"; |
| 6 | import { AppText as Text } from "../../components/ui/AppText"; |
| 7 | import { SymbolView } from "../../components/ui/AppSymbol"; |
| 8 | import { Menu } from "../../components/ui/Menu"; |
| 9 | import type { MenuProps } from "../../components/ui/Menu.types"; |
| 10 | import { cn } from "../../lib/cn"; |
| 11 | import { RelativeTime } from "../../components/RelativeTime"; |
| 12 | import { |
| 13 | selectedThreadRowColors, |
| 14 | THREAD_LIST_V2_SIDEBAR_ROW_STYLE, |
| 15 | THREAD_LIST_V2_SIDEBAR_ROW_CONTAINER_STYLE, |
| 16 | } from "../threads/thread-list-v2-row-appearance"; |
| 17 | import { |
| 18 | PullRequestAvatar, |
| 19 | PullRequestConflictBadge, |
| 20 | PullRequestDiffStats, |
| 21 | } from "./PullRequestPresentation"; |
| 22 | import { |
| 23 | pullRequestLabelColor, |
| 24 | pullRequestListReviewStatus, |
| 25 | pullRequestListRowsAreEqual, |
| 26 | type EnvironmentPullRequestListEntry, |
| 27 | } from "./pullRequestList"; |
| 28 | import { |
| 29 | pullRequestChecksStatus, |
| 30 | pullRequestConflict, |
| 31 | pullRequestStatus, |
| 32 | } from "./pullRequestStatus"; |
| 33 | import { PullRequestGlyph } from "./pullRequestGlyphs"; |
| 34 | |
| 35 | /** A label as list rows show it: small, tinted by its color, truncating. */ |
| 36 | export function ListRowLabel(props: { |
| 37 | readonly label: { readonly name: string; readonly color: string | null }; |
| 38 | readonly textClassName: string; |
| 39 | }) { |
| 40 | const color = pullRequestLabelColor(props.label.color); |
| 41 | return ( |
| 42 | <View |
| 43 | className="min-w-0 shrink flex-row items-center gap-1 rounded-md bg-subtle px-1.5 py-0.5" |
| 44 | style={{ maxWidth: 160, ...(color ? { backgroundColor: `${color}20` } : {}) }} |
| 45 | > |
| 46 | {color ? ( |
| 47 | <View style={{ width: 5, height: 5, borderRadius: 3, backgroundColor: color }} /> |
| 48 | ) : null} |
| 49 | <Text className={cn("shrink text-2xs font-t3-medium", props.textClassName)} numberOfLines={1}> |
| 50 | {props.label.name} |
| 51 | </Text> |
| 52 | </View> |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | export const PullRequestListRow = memo( |
| 57 | function PullRequestListRow(props: { |
| 58 | readonly item: EnvironmentPullRequestListEntry; |
| 59 | readonly onSelect: (item: EnvironmentPullRequestListEntry) => void; |
| 60 | readonly selected: boolean; |
| 61 | readonly sidebar: boolean; |
| 62 | readonly busy: boolean; |
| 63 | readonly getActions: (item: EnvironmentPullRequestListEntry) => MenuProps["actions"]; |
| 64 | readonly onAction: (item: EnvironmentPullRequestListEntry, action: string) => void; |
| 65 | }) { |
| 66 | const { item } = props; |
| 67 | const foreground = props.selected |
| 68 | ? selectedThreadRowColors.foregroundClassName |
| 69 | : props.sidebar |
| 70 | ? "text-drawer-foreground" |
| 71 | : "text-foreground"; |
| 72 | const mutedForeground = props.selected |
| 73 | ? selectedThreadRowColors.mutedForegroundClassName |
| 74 | : props.sidebar |
| 75 | ? "text-drawer-foreground-muted" |
| 76 | : "text-foreground-muted"; |
| 77 | const tertiaryForeground = props.selected |
| 78 | ? selectedThreadRowColors.mutedForegroundClassName |
| 79 | : props.sidebar |
| 80 | ? "text-drawer-foreground-muted" |
| 81 | : "text-foreground-tertiary"; |
| 82 | const gt = useGT(); |
| 83 | const m = useMessages(); |
| 84 | const status = pullRequestStatus(item, m); |
| 85 | const conflict = pullRequestConflict(item, m); |
| 86 | const review = pullRequestListReviewStatus(item, m); |
| 87 | const checksSpoken = item.checksState |
| 88 | ? { |
| 89 | passing: gt("checks passing"), |
| 90 | failing: gt("checks failing"), |
| 91 | pending: gt("checks pending"), |
| 92 | }[item.checksState] |
| 93 | : null; |
| 94 | const checksLabel = item.checksState |
| 95 | ? { |
| 96 | passing: gt("Checks passing"), |
| 97 | failing: gt("Checks failing"), |
| 98 | pending: gt("Checks pending"), |
| 99 | }[item.checksState] |
| 100 | : undefined; |
| 101 | const checks = item.checksState ? pullRequestChecksStatus(item.checksState) : null; |
| 102 | return ( |
| 103 | <View style={props.sidebar ? THREAD_LIST_V2_SIDEBAR_ROW_CONTAINER_STYLE : undefined}> |
| 104 | <Menu |
| 105 | shouldOpenOnLongPress |
| 106 | title={`#${item.number} · ${item.repository}`} |
| 107 | actions={props.getActions(item)} |
| 108 | onPressAction={({ nativeEvent }) => props.onAction(item, nativeEvent.event)} |
| 109 | > |
| 110 | <Pressable |
| 111 | accessibilityRole="button" |
| 112 | accessibilityState={{ selected: props.selected, busy: props.busy }} |
| 113 | accessibilityLabel={[ |
| 114 | gt( |
| 115 | "{term, select, mr {Merge request} cr {Change request} other {Pull request}} {number}", |
| 116 | { |
| 117 | term: changeRequestTermKind( |
| 118 | sourceControlClients.get(item.provider).changeRequest, |
| 119 | ), |
| 120 | number: item.number, |
| 121 | }, |
| 122 | ), |
| 123 | item.title, |
| 124 | status.label, |
| 125 | conflict ? conflict.label.toLowerCase() : null, |
| 126 | gt("by {author}", { author: item.author?.login ?? gt("unknown author") }), |
| 127 | review ? review.accessibleLabel : null, |
| 128 | checksSpoken, |
| 129 | item.stack |
| 130 | ? gt("stack {position} of {size}", { |
| 131 | position: item.stack.position, |
| 132 | size: item.stack.size, |
| 133 | }) |
| 134 | : null, |
| 135 | item.labels.length ? item.labels.map((label) => label.name).join(", ") : null, |
| 136 | gt("{additions} additions, {deletions} deletions", { |
| 137 | additions: item.additions, |
| 138 | deletions: item.deletions, |
| 139 | }), |
| 140 | ] |
| 141 | .filter((part) => part !== null) |
| 142 | .join(", ")} |
| 143 | accessibilityHint={gt("Double tap to open. Touch and hold for quick actions.")} |
| 144 | onPress={() => props.onSelect(item)} |
| 145 | disabled={props.busy} |
| 146 | style={props.sidebar ? THREAD_LIST_V2_SIDEBAR_ROW_STYLE : undefined} |
| 147 | className={cn( |
| 148 | "flex-row gap-3 overflow-hidden", |
| 149 | !props.sidebar && "px-4 active:bg-row-hover", |
| 150 | props.sidebar && "bg-drawer", |
| 151 | props.sidebar && !props.selected && "active:bg-thread-hover", |
| 152 | props.selected && "bg-thread-selected", |
| 153 | props.busy && "opacity-50", |
| 154 | )} |
| 155 | > |
| 156 | <View className={cn("self-start", props.sidebar ? "pt-0.5" : "pt-2.5")}> |
| 157 | <SymbolView name={status.icon} size={20} tintColorClassName={status.tint} /> |
| 158 | {conflict ? ( |
| 159 | <PullRequestConflictBadge |
| 160 | surfaceClassName={ |
| 161 | props.selected |
| 162 | ? "text-thread-selected" |
| 163 | : props.sidebar |
| 164 | ? "text-drawer" |
| 165 | : "text-screen" |
| 166 | } |
| 167 | /> |
| 168 | ) : null} |
| 169 | </View> |
| 170 | <View |
| 171 | className={cn( |
| 172 | "min-w-0 flex-1 gap-1", |
| 173 | !props.sidebar && "border-b border-border-subtle py-2.5", |
| 174 | )} |
| 175 | > |
| 176 | <View className="flex-row items-center gap-1.5"> |
| 177 | <PullRequestAvatar actor={item.author} size={16} /> |
| 178 | <Text className={cn("min-w-0 flex-1 text-xs", mutedForeground)} numberOfLines={1}> |
| 179 | {item.repository} <Text className={tertiaryForeground}>#{item.number}</Text> |
| 180 | </Text> |
| 181 | {item.stack ? ( |
| 182 | <View className="flex-row items-center gap-1"> |
| 183 | <SymbolView |
| 184 | name={PullRequestGlyph.stack} |
| 185 | size={12} |
| 186 | tintColorClassName={ |
| 187 | props.selected |
| 188 | ? selectedThreadRowColors.mutedIconTintClassName |
| 189 | : props.sidebar |
| 190 | ? "accent-drawer-foreground-muted" |
| 191 | : "accent-foreground-muted" |
| 192 | } |
| 193 | /> |
| 194 | <Text className={cn("text-2xs tabular-nums", mutedForeground)}> |
| 195 | {item.stack.position}/{item.stack.size} |
| 196 | </Text> |
| 197 | </View> |
| 198 | ) : null} |
| 199 | <Text className={cn("text-2xs tabular-nums", tertiaryForeground)}> |
| 200 | <RelativeTime timestamp={item.updatedAt} /> |
| 201 | </Text> |
| 202 | </View> |
| 203 | <Text |
| 204 | className={cn("text-base leading-5 font-t3-medium", foreground)} |
| 205 | numberOfLines={2} |
| 206 | ellipsizeMode="tail" |
| 207 | > |
| 208 | {item.title} |
| 209 | </Text> |
| 210 | <View className="flex-row items-center gap-1.5"> |
| 211 | <View className="min-w-0 flex-1 flex-row items-center gap-1"> |
| 212 | {item.labels.slice(0, 2).map((label) => ( |
| 213 | <ListRowLabel key={label.name} label={label} textClassName={mutedForeground} /> |
| 214 | ))} |
| 215 | {item.labels.length > 2 ? ( |
| 216 | <Text className={cn("shrink-0 text-2xs", tertiaryForeground)}> |
| 217 | +{item.labels.length - 2} |
| 218 | </Text> |
| 219 | ) : null} |
| 220 | </View> |
| 221 | {checks ? ( |
| 222 | <View className="shrink-0" accessibilityLabel={checksLabel}> |
| 223 | <SymbolView name={checks.icon} size={13} tintColorClassName={checks.tint} /> |
| 224 | </View> |
| 225 | ) : null} |
| 226 | {review ? ( |
| 227 | <View className="shrink-0" accessibilityLabel={review.accessibleLabel}> |
| 228 | <SymbolView name={review.icon} size={13} tintColorClassName={review.tint} /> |
| 229 | </View> |
| 230 | ) : null} |
| 231 | {item.additions || item.deletions ? ( |
| 232 | <PullRequestDiffStats |
| 233 | additions={item.additions} |
| 234 | deletions={item.deletions} |
| 235 | compact |
| 236 | /> |
| 237 | ) : null} |
| 238 | </View> |
| 239 | </View> |
| 240 | </Pressable> |
| 241 | </Menu> |
| 242 | </View> |
| 243 | ); |
| 244 | }, |
| 245 | (previous, next) => |
| 246 | pullRequestListRowsAreEqual(previous.item, next.item) && |
| 247 | previous.selected === next.selected && |
| 248 | previous.sidebar === next.sidebar && |
| 249 | previous.busy === next.busy && |
| 250 | previous.onSelect === next.onSelect && |
| 251 | previous.onAction === next.onAction && |
| 252 | previous.getActions === next.getActions, |
| 253 | ); |