@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
tsx 104 lines 4.02 KB
Raw
1 import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
2 import { useGT } from "gt-react-native";
3 import { useRef, useState } from "react";
4
5 import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/AppText";
6 import { Button } from "../../components/ui/Button";
7 import { issueEnvironment, refreshIssueLists } from "../../state/issues";
8 import { useEnvironmentQuery } from "../../state/query";
9 import { useAtomCommand } from "../../state/use-atom-command";
10 import { PullRequestSheetContent } from "../pull-requests/PullRequestSheetContent";
11 import { issueTarget, type IssueParams } from "./issueParams";
12 import { issueCommandError, useIssueAccess } from "./issuePresentation";
13
14 type IssueEditParams = IssueParams & { readonly field: "title" | "body" };
15
16 export function IssueEditScreen({ route }: StaticScreenProps<IssueEditParams>) {
17 const params = route.params;
18 const gt = useGT();
19 const navigation = useNavigation();
20 const target = issueTarget(params);
21 const detailQuery = useEnvironmentQuery(issueEnvironment.detail(target));
22 const detail = detailQuery.data;
23 const access = useIssueAccess(params, detail);
24 const update = useAtomCommand(issueEnvironment.update, { reportFailure: false });
25 const isTitle = params.field === "title";
26 const original = detail ? (isTitle ? detail.title : detail.body) : null;
27 const [draft, setDraft] = useState<string | null>(null);
28 const value = draft ?? original ?? "";
29 const [busy, setBusy] = useState(false);
30 const [error, setError] = useState<string | null>(null);
31 const inFlight = useRef(false);
32 const allowed = access?.edit === true;
33 const unchanged = draft === null || draft === original;
34 const invalid = isTitle && value.trim().length === 0;
35 const save = async () => {
36 if (!allowed || unchanged || invalid || inFlight.current) return;
37 inFlight.current = true;
38 setBusy(true);
39 setError(null);
40 const failure = issueCommandError(
41 await update({
42 ...target,
43 input: { ...target.input, ...(isTitle ? { title: value.trim() } : { body: value }) },
44 }),
45 );
46 inFlight.current = false;
47 setBusy(false);
48 if (failure !== null) {
49 setError(failure);
50 return;
51 }
52 refreshIssueLists(target.environmentId);
53 navigation.goBack();
54 };
55 return (
56 <PullRequestSheetContent
57 busy={busy}
58 title={isTitle ? gt("Edit title") : gt("Edit description")}
59 subtitle={`${detail?.displayKey ?? params.issueKey} · ${params.scope}`}
60 footer={
61 <Button
62 fullWidth
63 tone="contrast"
64 label={busy ? gt("Saving…") : gt("Save")}
65 loading={busy}
66 disabled={!allowed || unchanged || invalid || original === null}
67 onPress={() => void save()}
68 />
69 }
70 >
71 <TextInput
72 multiline={!isTitle}
73 editable={!busy && original !== null}
74 autoFocus
75 accessibilityLabel={isTitle ? gt("Issue title") : gt("Issue description")}
76 placeholder={
77 isTitle ? gt("Title", { $context: "issue title field" }) : gt("Write in Markdown…")
78 }
79 placeholderTextColorClassName="accent-foreground-muted"
80 maxLength={isTitle ? 1024 : 65536}
81 value={value}
82 onChangeText={setDraft}
83 returnKeyType={isTitle ? "done" : undefined}
84 onSubmitEditing={isTitle ? () => void save() : undefined}
85 className={
86 isTitle
87 ? "min-h-12 rounded-[20px] bg-grouped-card px-4 text-base text-foreground"
88 : "min-h-48 rounded-[20px] bg-grouped-card p-4 text-base text-foreground"
89 }
90 style={isTitle ? undefined : { textAlignVertical: "top" }}
91 />
92 {detail && !allowed ? (
93 <Text className="text-xs text-foreground-muted">
94 {access?.blocked ?? gt("You can't edit this issue.")}
95 </Text>
96 ) : null}
97 {error || detailQuery.error ? (
98 <Text selectable className="text-sm text-danger-foreground">
99 {error ?? detailQuery.error}
100 </Text>
101 ) : null}
102 </PullRequestSheetContent>
103 );
104 }