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

main
tsx 131 lines 4.95 KB
Raw
1 import { LegendList } from "@legendapp/list/react-native";
2 import { useGT } from "gt-react-native";
3 import type { ReactNode } from "react";
4 import { Platform, View } from "react-native";
5
6 import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
7 import { AppText as Text } from "../../components/ui/AppText";
8 import { Button } from "../../components/ui/Button";
9 import { EmptyState } from "../../components/ui/EmptyState";
10 import { SelectionRow } from "../../components/ui/SelectionRow";
11 import { NativeScrollView } from "../../native/NativeScrollViewMarker";
12 import { PullRequestSearchSheet } from "../pull-requests/PullRequestSearchSheet";
13
14 interface Candidate {
15 readonly key: string;
16 readonly title: string;
17 readonly subtitle?: string;
18 readonly leading: ReactNode;
19 readonly selected: boolean;
20 }
21
22 /** The searchable checklist behind the label and assignee pickers. */
23 export function IssueCandidatesSheet(props: {
24 readonly title: string;
25 readonly noun: "labels" | "people";
26 readonly query: string;
27 readonly onQueryChange: (query: string) => void;
28 readonly candidates: ReadonlyArray<Candidate>;
29 readonly allowed: boolean;
30 readonly notice: string | null;
31 readonly pending: boolean;
32 readonly loadError: string | null;
33 readonly onRetry: () => void;
34 readonly truncated: boolean;
35 readonly onToggle: (key: string) => void;
36 }) {
37 const gt = useGT();
38 const labels = props.noun === "labels";
39 const searching = props.query.trim().length > 0;
40 return (
41 <PullRequestSearchSheet
42 title={props.title}
43 placeholder={labels ? gt("Search labels") : gt("Search people")}
44 closeAccessibilityLabel={gt("Close {title}", { title: props.title.toLowerCase() })}
45 clearAccessibilityLabel={gt("Clear search")}
46 query={props.query}
47 onQueryChange={props.onQueryChange}
48 >
49 {({ paddingBottom }) => (
50 <LegendList
51 renderScrollComponent={NativeScrollView}
52 data={props.candidates}
53 keyExtractor={(candidate) => candidate.key}
54 extraData={props.candidates}
55 estimatedItemSize={64}
56 recycleItems
57 className="flex-1"
58 contentInsetAdjustmentBehavior="automatic"
59 automaticallyAdjustKeyboardInsets={Platform.OS === "ios"}
60 keyboardDismissMode={Platform.OS === "ios" ? "interactive" : "on-drag"}
61 keyboardShouldPersistTaps="handled"
62 showsVerticalScrollIndicator={false}
63 contentContainerStyle={{ paddingHorizontal: 16, paddingTop: 16, paddingBottom }}
64 ListHeaderComponent={
65 props.notice ? (
66 <View className="items-start gap-2 pb-3">
67 <Text className="text-xs text-foreground-muted">{props.notice}</Text>
68 {props.loadError && props.candidates.length > 0 ? (
69 <Button label={gt("Retry")} size="compact" onPress={props.onRetry} />
70 ) : null}
71 </View>
72 ) : undefined
73 }
74 renderItem={({ item, index }) => (
75 <SelectionRow
76 title={item.title}
77 {...(item.subtitle ? { subtitle: item.subtitle } : {})}
78 role="checkbox"
79 selected={item.selected}
80 disabled={!props.allowed}
81 isFirst={index === 0}
82 isLast={index === props.candidates.length - 1}
83 leading={item.leading}
84 onPress={() => props.onToggle(item.key)}
85 />
86 )}
87 ListEmptyComponent={
88 props.pending ? (
89 <AppActivityIndicator className="my-8" />
90 ) : (
91 <View>
92 <EmptyState
93 title={
94 props.loadError
95 ? labels
96 ? gt("Couldn't load labels")
97 : gt("Couldn't load people")
98 : searching
99 ? labels
100 ? gt("No matching labels")
101 : gt("No matching people")
102 : labels
103 ? gt("This tracker has no labels")
104 : gt("Nobody can be assigned here")
105 }
106 detail={
107 props.loadError ??
108 (searching
109 ? gt("Try another name.")
110 : gt("Add them on the tracker to use them here."))
111 }
112 variant="plain"
113 />
114 {props.loadError ? <Button label={gt("Retry")} onPress={props.onRetry} /> : null}
115 </View>
116 )
117 }
118 ListFooterComponent={
119 props.truncated ? (
120 <Text className="py-4 text-xs text-foreground-muted">
121 {labels
122 ? gt("More labels exist than are listed here.")
123 : gt("More people exist than are listed here.")}
124 </Text>
125 ) : undefined
126 }
127 />
128 )}
129 </PullRequestSearchSheet>
130 );
131 }