@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 760 lines 29.6 KB
Raw
1 import { RegistryContext, useAtomValue } from "@effect/atom-react";
2 import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native";
3 import { issueEventSentence } from "@t3tools/client-runtime/issue-presentation";
4 import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
5 import { createIssueCommentPager } from "@t3tools/client-runtime/state/issues";
6 import { visibleLinkedThreads } from "@t3tools/client-runtime/state/threads";
7 import type {
8 IssueComment,
9 IssueEvent,
10 IssueLinkedPullRequest,
11 IssueReaction,
12 IssueState,
13 IssueSummary,
14 } from "@t3tools/contracts";
15 import { AsyncResult } from "effect/reactivity";
16 import { T, useGT, useMessages, Var } from "gt-react-native";
17 import { useContext, useState } from "react";
18 import { Platform, Pressable, Share, View } from "react-native";
19 import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
20 import { KeyboardStickyView } from "react-native-keyboard-controller";
21
22 import { RelativeTime } from "../../components/RelativeTime";
23 import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
24 import { AppBar } from "../../components/ui/AppBar";
25 import { SymbolView } from "../../components/ui/AppSymbol";
26 import { AppText as Text } from "../../components/ui/AppText";
27 import { Button } from "../../components/ui/Button";
28 import { Chip } from "../../components/ui/Chip";
29 import { EmptyState } from "../../components/ui/EmptyState";
30 import { Menu } from "../../components/ui/Menu";
31 import { RefreshControl } from "../../components/ui/RefreshControl";
32 import { ScreenContent } from "../../components/ui/ScreenContent";
33 import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
34 import { useComposerBottomInset } from "../../components/ComposerSurface";
35 import { ANDROID_READING_MAX_WIDTH, CHAT_CONTENT_MAX_WIDTH } from "../../lib/layout";
36 import { relativeTime } from "../../lib/time";
37 import { deriveBottomControlInsets, type NativeLayoutMetrics } from "../../lib/reserved-regions";
38 import { NativeLayoutObserver } from "../../native/NativeLayoutObserver";
39 import { useNativeWorkspaceColumnsSupported } from "../../native/NativeWorkspaceColumns";
40 import { useDeviceType, useNativeColumnLayoutMetrics } from "../../native/native-layout-metrics";
41 import { NativeScrollView } from "../../native/NativeScrollViewMarker";
42 import { useEnvironmentServerConfig } from "../../state/entities";
43 import { issueEnvironment, refreshIssueLists } from "../../state/issues";
44 import { useEnvironmentQuery } from "../../state/query";
45 import { environmentThreadShells } from "../../state/threads";
46 import { useAtomCommand } from "../../state/use-atom-command";
47 import { usePullToRefresh } from "../../state/use-pull-to-refresh";
48 import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
49 import { useAndroidWorkspaceBack } from "../layout/workspace/useAndroidWorkspaceNavigation";
50 import { PullRequestDescription } from "../pull-requests/PullRequestDescription";
51 import {
52 PullRequestMarkdown,
53 PullRequestMarkdownRepository,
54 } from "../pull-requests/PullRequestMarkdown";
55 import { PullRequestAvatar } from "../pull-requests/PullRequestPresentation";
56 import { ReactionPills } from "../pull-requests/PullRequestReactions";
57 import { PullRequestSectionHeading } from "../pull-requests/PullRequestSectionHeading";
58 import { pullRequestStatus } from "../pull-requests/pullRequestStatus";
59 import { usePullRequestConnected } from "../pull-requests/usePullRequestConnected";
60 import { IssueCommentComposer } from "./IssueCommentComposer";
61 import { issueIdentity, issueParamsKey, issueTarget, type IssueParams } from "./issueParams";
62 import {
63 IssueLabelPill,
64 issueCommandError,
65 issueStatus,
66 useIssueAccess,
67 } from "./issuePresentation";
68
69 type IssueAccess = NonNullable<ReturnType<typeof useIssueAccess>>;
70
71 function IssueReactions(props: {
72 readonly params: IssueParams;
73 readonly reactions: ReadonlyArray<IssueReaction>;
74 readonly canReact: boolean;
75 /** Absent reacts to the issue itself. */
76 readonly subjectId?: string;
77 }) {
78 const target = issueTarget(props.params);
79 const react = useAtomCommand(issueEnvironment.react, { reportFailure: false });
80 if (props.reactions.length === 0 && !props.canReact) return null;
81 return (
82 <View className="flex-row flex-wrap items-center gap-1.5">
83 <ReactionPills
84 reactions={props.reactions}
85 canReact={props.canReact}
86 onReact={async (content, reacted) =>
87 !AsyncResult.isFailure(
88 await react({
89 ...target,
90 input: {
91 ...target.input,
92 ...(props.subjectId === undefined ? {} : { subjectId: props.subjectId }),
93 content,
94 reacted,
95 },
96 }),
97 )
98 }
99 />
100 </View>
101 );
102 }
103
104 function IssueStateControl(props: {
105 readonly state: IssueState;
106 readonly states: ReadonlyArray<IssueState>;
107 readonly busy: boolean;
108 readonly onMove: (state: string) => void;
109 }) {
110 const gt = useGT();
111 const status = issueStatus(props.state);
112 const moves = props.states;
113 const trigger = (
114 <Pressable
115 accessibilityRole={moves.length ? "button" : undefined}
116 accessibilityLabel={gt("Issue state, {state}", { state: status.label })}
117 disabled={!moves.length || props.busy}
118 className="min-h-8 flex-row items-center gap-1.5 active:opacity-70"
119 >
120 <SymbolView name={status.icon} size={14} tintColorClassName={status.tint} />
121 <Text className={`text-xs font-t3-medium ${status.text}`}>{status.label}</Text>
122 {moves.length ? (
123 <SymbolView name="chevron.down" size={9} tintColorClassName="accent-icon-muted" />
124 ) : null}
125 </Pressable>
126 );
127 if (!moves.length) return trigger;
128 return (
129 // As wide as the trigger: iOS anchors the menu to this view, not to the text inside it.
130 <View className="self-start">
131 <Menu
132 title={gt("Issue state")}
133 // The name is the id: unique within a workflow, and a NUL separator would end the native string.
134 actions={moves.map((move) => ({ id: move.name, title: move.name }))}
135 onPressAction={({ nativeEvent }) => {
136 if (moves.some((move) => move.name === nativeEvent.event))
137 props.onMove(nativeEvent.event);
138 }}
139 >
140 {trigger}
141 </Menu>
142 </View>
143 );
144 }
145
146 function IssueIdentity(props: {
147 readonly issue: IssueSummary;
148 readonly access: IssueAccess | null;
149 readonly busy: boolean;
150 readonly onMove: (state: string) => void;
151 readonly onEditLabels: () => void;
152 readonly onEditAssignees: () => void;
153 }) {
154 const gt = useGT();
155 const { issue, access } = props;
156 const canLabel = access?.labels === true;
157 const canAssign = access?.assignees === true;
158 return (
159 <View className="gap-3">
160 <IssueStateControl
161 state={issue.state}
162 states={access?.states ?? []}
163 busy={props.busy}
164 onMove={props.onMove}
165 />
166 <Text selectable className="text-xl font-t3-bold leading-7">
167 {issue.title}
168 </Text>
169 <View className="flex-row items-center gap-2">
170 <PullRequestAvatar actor={issue.author} size={20} />
171 <Text className="min-w-0 flex-1 text-xs font-t3-medium" numberOfLines={1}>
172 {issue.author?.login ?? gt("Unknown author")}
173 </Text>
174 <Text className="shrink text-right text-2xs text-foreground-muted" numberOfLines={1}>
175 {issue.closedAt ? (
176 <T>
177 Closed{" "}
178 <Var>
179 <RelativeTime timestamp={issue.closedAt} />
180 </Var>{" "}
181 ago
182 </T>
183 ) : (
184 <T>
185 Opened{" "}
186 <Var>
187 <RelativeTime timestamp={issue.createdAt} />
188 </Var>{" "}
189 ago
190 </T>
191 )}
192 </Text>
193 </View>
194 {issue.labels.length || canLabel ? (
195 <View className="flex-row flex-wrap gap-2">
196 {issue.labels.map((label) => (
197 <IssueLabelPill key={label.name} label={label} />
198 ))}
199 {canLabel ? (
200 <Chip
201 label={
202 issue.labels.length
203 ? gt("Edit", { $context: "verb, edits labels" })
204 : gt("Add labels")
205 }
206 icon="tag"
207 size="small"
208 accessibilityLabel={gt("Edit labels")}
209 onPress={props.onEditLabels}
210 />
211 ) : null}
212 </View>
213 ) : null}
214 <View className="flex-row flex-wrap items-center gap-2">
215 <Text className="text-xs text-foreground-muted">
216 <T>Assignees</T>
217 </Text>
218 {issue.assignees.length === 0 ? (
219 <Text className="text-xs text-foreground-muted">
220 <T context="no assignees">none</T>
221 </Text>
222 ) : null}
223 {issue.assignees.map((actor) => (
224 <View key={actor.login} className="flex-row items-center gap-1.5">
225 <PullRequestAvatar actor={actor} size={18} />
226 <Text className="text-xs font-t3-medium">{actor.login}</Text>
227 </View>
228 ))}
229 {canAssign ? (
230 <Chip
231 label={
232 issue.assignees.length
233 ? gt("Edit", { $context: "verb, edits assignees" })
234 : gt("Assign", { $context: "verb, assigns people to an issue" })
235 }
236 icon="person.badge.plus"
237 size="small"
238 accessibilityLabel={gt("Edit assignees")}
239 onPress={props.onEditAssignees}
240 />
241 ) : null}
242 </View>
243 </View>
244 );
245 }
246
247 function LinkedPullRequests(props: {
248 readonly params: IssueParams;
249 readonly links: ReadonlyArray<IssueLinkedPullRequest>;
250 }) {
251 const gt = useGT();
252 const navigation = useNavigation();
253 // Only a git host's tracker shares its host with the change request it links.
254 const sameHost = sourceControlClients.find(props.params.tracker) !== undefined;
255 return (
256 <View className="gap-2">
257 <PullRequestSectionHeading>
258 <T>Linked pull requests</T>
259 </PullRequestSectionHeading>
260 {props.links.map((link) => {
261 const status = pullRequestStatus(link);
262 return (
263 <Pressable
264 key={`${link.repository}#${link.number}`}
265 accessibilityRole="button"
266 accessibilityLabel={gt("{status} pull request {number}, {title}", {
267 status: status.label,
268 number: String(link.number),
269 title: link.title,
270 })}
271 onPress={() =>
272 sameHost
273 ? navigation.dispatch(
274 StackActions.push("PullRequest", {
275 environmentId: props.params.environmentId,
276 projectId: props.params.projectId,
277 repository: link.repository,
278 number: link.number,
279 ...(props.params.host ? { host: props.params.host } : {}),
280 }),
281 )
282 : void tryOpenExternalUrl(link.url)
283 }
284 className="flex-row items-center gap-2 rounded-2xl bg-grouped-card p-3 active:opacity-70"
285 >
286 <SymbolView name={status.icon} size={15} tintColorClassName={status.tint} />
287 <View className="min-w-0 flex-1">
288 <Text className="text-sm" numberOfLines={2}>
289 {link.title}
290 </Text>
291 <Text className="font-mono text-2xs text-foreground-muted" numberOfLines={1}>
292 {link.repository}#{link.number}
293 {link.closesIssue
294 ? ` · ${gt("closes", { $context: "the pull request closes this issue" })}`
295 : ""}
296 </Text>
297 </View>
298 <SymbolView name="chevron.right" size={12} tintColorClassName="accent-icon-muted" />
299 </Pressable>
300 );
301 })}
302 </View>
303 );
304 }
305
306 /** The threads this issue is linked to, most recently active first; hidden while there are none. */
307 function LinkedThreads(props: { readonly params: IssueParams; readonly host: string }) {
308 const gt = useGT();
309 const navigation = useNavigation();
310 const { environmentId, input } = issueTarget(props.params);
311 const listsThreads =
312 useEnvironmentServerConfig(environmentId)?.environment.capabilities.issueLinkedThreads === true;
313 const relations = useEnvironmentQuery(
314 listsThreads
315 ? issueEnvironment.linkedThreads({
316 environmentId,
317 input: { tracker: input.tracker, host: props.host, scope: input.scope, key: input.key },
318 })
319 : null,
320 );
321 const hiddenKeys = useAtomValue(environmentThreadShells.hiddenThreadKeysAtom);
322 const hidingAnywhere = useAtomValue(environmentThreadShells.anyEnvironmentHidingAtom);
323 const loadedThreadRefs = useAtomValue(
324 environmentThreadShells.environmentThreadRefsAtom(environmentId),
325 );
326 const threads = visibleLinkedThreads(
327 relations.data?.threads ?? [],
328 environmentId,
329 loadedThreadRefs,
330 hiddenKeys,
331 hidingAnywhere,
332 );
333 if (threads.length === 0) return null;
334 return (
335 <View className="gap-2">
336 <PullRequestSectionHeading>
337 <T>Linked threads</T>
338 </PullRequestSectionHeading>
339 {threads.map((thread) => {
340 const title = thread.title || gt("Untitled thread");
341 return (
342 <Pressable
343 key={thread.id}
344 accessibilityRole="button"
345 accessibilityLabel={gt("Open thread {title}", { title })}
346 onPress={() =>
347 navigation.dispatch(
348 StackActions.push("Thread", {
349 environmentId: props.params.environmentId,
350 threadId: thread.id,
351 }),
352 )
353 }
354 className="flex-row items-center gap-2 rounded-2xl bg-grouped-card p-3 active:opacity-70"
355 >
356 <SymbolView name="bubble.left" size={15} tintColorClassName="accent-icon-muted" />
357 <View className="min-w-0 flex-1">
358 <Text className="text-sm" numberOfLines={2}>
359 {title}
360 </Text>
361 {thread.archivedAt !== null ? (
362 <Text className="text-2xs text-foreground-muted" numberOfLines={1}>
363 <T>Archived thread</T>
364 </Text>
365 ) : null}
366 </View>
367 <SymbolView name="chevron.right" size={12} tintColorClassName="accent-icon-muted" />
368 </Pressable>
369 );
370 })}
371 </View>
372 );
373 }
374
375 function IssueCommentCard(props: {
376 readonly params: IssueParams;
377 readonly comment: IssueComment;
378 readonly canReact: boolean;
379 }) {
380 const gt = useGT();
381 const messages = useMessages();
382 const { comment } = props;
383 return (
384 <View className="gap-3 rounded-2xl bg-grouped-card p-3">
385 <View accessible accessibilityRole="header" className="flex-row items-center gap-2">
386 <PullRequestAvatar actor={comment.author} size={22} />
387 <Text className="min-w-0 flex-1 text-sm font-t3-medium" numberOfLines={1}>
388 {comment.author?.login ?? gt("Unknown author")}
389 </Text>
390 <Text className="text-2xs text-foreground-tertiary">
391 {relativeTime(comment.createdAt, undefined, messages)}
392 </Text>
393 </View>
394 <PullRequestMarkdown markdown={comment.body} />
395 {comment.reactions !== undefined ? (
396 <IssueReactions
397 params={props.params}
398 reactions={comment.reactions}
399 canReact={props.canReact}
400 subjectId={comment.id}
401 />
402 ) : null}
403 </View>
404 );
405 }
406
407 function IssueEventRow({ event }: { readonly event: IssueEvent }) {
408 const gt = useGT();
409 const messages = useMessages();
410 return (
411 <View className="flex-row items-center gap-2 px-1">
412 <PullRequestAvatar actor={event.actor} size={18} />
413 <Text className="min-w-0 flex-1 text-xs text-foreground-muted">
414 <Text className="text-xs font-t3-medium">
415 {event.actor?.login ?? gt("Someone", { $context: "an unknown person" })}
416 </Text>{" "}
417 {issueEventSentence(event, messages)}
418 </Text>
419 <Text className="text-2xs text-foreground-tertiary">
420 {relativeTime(event.createdAt, undefined, messages)}
421 </Text>
422 </View>
423 );
424 }
425
426 function IssueLoadingBody() {
427 const gt = useGT();
428 return (
429 <View
430 className="gap-5"
431 accessibilityLabel={gt("Loading issue")}
432 accessibilityState={{ busy: true }}
433 >
434 <View className="gap-3">
435 <PullRequestSectionHeading>
436 <T>Description</T>
437 </PullRequestSectionHeading>
438 <View className="gap-3 py-1">
439 <View className="h-4 w-full rounded bg-subtle-strong" />
440 <View className="h-4 w-full rounded bg-subtle-strong" />
441 <View className="h-4 w-3/4 rounded bg-subtle-strong" />
442 </View>
443 </View>
444 <View className="gap-3">
445 <PullRequestSectionHeading>
446 <T>Activity</T>
447 </PullRequestSectionHeading>
448 <View className="h-20 rounded-2xl bg-subtle-strong" />
449 <View className="h-20 rounded-2xl bg-subtle-strong" />
450 </View>
451 </View>
452 );
453 }
454
455 // Selecting another issue reuses this route, so the draft, older comments and errors are keyed.
456 export function IssueRouteScreen({ route }: StaticScreenProps<IssueParams>) {
457 return <IssueRoute key={issueParamsKey(route.params)} params={route.params} />;
458 }
459
460 function IssueRoute({ params }: { readonly params: IssueParams }) {
461 const gt = useGT();
462 const identity = issueIdentity(params);
463 const target = issueTarget(params);
464 const navigation = useNavigation();
465 const returnToList = useAndroidWorkspaceBack();
466 const { layout } = useAdaptiveWorkspaceLayout();
467 const composerBottomInset = useComposerBottomInset();
468 const deviceType = useDeviceType();
469 // The thread screen's composer host: the same metrics, so the same reserved regions and insets.
470 const usesNativeWorkspaceColumns = useNativeWorkspaceColumnsSupported();
471 const [screenMetrics, setScreenMetrics] = useState<NativeLayoutMetrics | null>(null);
472 const columnMetrics = useNativeColumnLayoutMetrics();
473 const controlInsets = deriveBottomControlInsets(
474 usesNativeWorkspaceColumns ? columnMetrics : screenMetrics,
475 );
476 const [composerFocused, setComposerFocused] = useState(false);
477 const connected = usePullRequestConnected(params.environmentId);
478 const detailAtom = issueEnvironment.detail(target);
479 const detailQuery = useEnvironmentQuery(detailAtom);
480 const pullRefresh = usePullToRefresh(detailAtom);
481 const registry = useContext(RegistryContext);
482 const [pager] = useState(() => createIssueCommentPager(detailAtom));
483 const { comments, nextCursor, loadingOlder, canLoadOlder } = useAtomValue(pager.view);
484 const detail = detailQuery.data;
485 const issue: IssueSummary | null = detail ?? params.initialSummary ?? null;
486 const access = useIssueAccess(params, detail);
487
488 const loadComments = useAtomCommand(issueEnvironment.comments, { reportFailure: false });
489 const postComment = useAtomCommand(issueEnvironment.comment, { reportFailure: false });
490 const setState = useAtomCommand(issueEnvironment.setState, { reportFailure: false });
491 const [busy, setBusy] = useState<"comment" | "state" | null>(null);
492 const [mutationError, setMutationError] = useState<string | null>(null);
493 const [olderCommentsError, setOlderCommentsError] = useState<string | null>(null);
494 const [composerHeight, setComposerHeight] = useState(0);
495
496 const timeline = detail
497 ? [
498 ...comments.map((comment) => ({
499 key: `c:${comment.id}`,
500 at: comment.createdAt,
501 content: (
502 <IssueCommentCard params={params} comment={comment} canReact={access?.react === true} />
503 ),
504 })),
505 ...detail.events.map((event) => ({
506 key: `e:${event.id}`,
507 at: event.createdAt,
508 content: <IssueEventRow event={event} />,
509 })),
510 ].sort((left, right) => Date.parse(left.at) - Date.parse(right.at))
511 : [];
512
513 const run = async (
514 kind: NonNullable<typeof busy>,
515 command: () => Promise<AsyncResult.AsyncResult<unknown, unknown>>,
516 ) => {
517 if (busy !== null) return false;
518 setBusy(kind);
519 setMutationError(null);
520 const failure = issueCommandError(await command());
521 setBusy(null);
522 setMutationError(failure);
523 // The list beside this issue shows its state and comment count, and reads only when asked.
524 if (failure === null) refreshIssueLists(target.environmentId);
525 return failure === null;
526 };
527 const loadOlder = async () => {
528 if (busy !== null) return;
529 const failure = await pager.loadOlder(registry, (cursor) => {
530 setOlderCommentsError(null);
531 return loadComments({ ...target, input: { ...target.input, cursor } });
532 });
533 if (failure) setOlderCommentsError(gt("Older comments could not be read."));
534 };
535 const submitComment = (body: string) =>
536 access?.comment === true
537 ? run("comment", () => postComment({ ...target, input: { ...target.input, body } }))
538 : Promise.resolve(false);
539 const moveTo = (state: string) =>
540 void run("state", () => setState({ ...target, input: { ...target.input, state } }));
541
542 const showComposer = detail?.capabilities.comment === true;
543 const commentBlocked =
544 access?.comment === true ? null : (access?.blocked ?? gt("You cannot comment here."));
545 const contentMaxWidth =
546 Platform.OS === "android"
547 ? ANDROID_READING_MAX_WIDTH
548 : layout.usesSplitView
549 ? CHAT_CONTENT_MAX_WIDTH
550 : undefined;
551 const url = issue?.url;
552 return (
553 <PullRequestMarkdownRepository
554 params={{
555 environmentId: params.environmentId,
556 projectId: params.projectId,
557 repository: params.scope,
558 number: 0,
559 }}
560 changeRequest={detail ? { provider: detail.tracker, url: detail.url } : null}
561 >
562 <View className="flex-1 bg-screen">
563 <AppBar
564 title={issue?.displayKey ?? params.issueKey}
565 subtitle={connected ? params.scope : gt("{scope} · Offline", { scope: params.scope })}
566 onBack={layout.usesSplitView ? undefined : returnToList}
567 menus={[
568 {
569 title: gt("Issue actions"),
570 icon: "ellipsis",
571 items: [
572 ...(access?.edit
573 ? [
574 {
575 id: "edit-title",
576 title: gt("Edit title"),
577 icon: "pencil",
578 onPress: () =>
579 navigation.navigate("IssueEdit", { ...identity, field: "title" }),
580 },
581 {
582 id: "edit-description",
583 title: gt("Edit description"),
584 icon: "doc.text",
585 onPress: () =>
586 navigation.navigate("IssueEdit", { ...identity, field: "body" }),
587 },
588 ]
589 : []),
590 ...(url
591 ? [
592 {
593 id: "open-on-host",
594 title: gt("Open on the tracker"),
595 icon: "arrow.up.right",
596 onPress: () => void tryOpenExternalUrl(url),
597 },
598 {
599 id: "copy-link",
600 title: gt("Copy link"),
601 icon: "link",
602 onPress: () => copyTextWithHaptic(url, { target: "issue link" }),
603 },
604 {
605 id: "share",
606 title: gt("Share…"),
607 icon: "square.and.arrow.up",
608 onPress: () =>
609 // Android ignores `url`; iOS shows a `message` URL as plain text.
610 void Share.share(
611 Platform.OS === "ios" ? { url } : { message: url },
612 ).catch(() => undefined),
613 },
614 ]
615 : []),
616 ],
617 },
618 ]}
619 />
620 <ScreenContent>
621 {!usesNativeWorkspaceColumns ? (
622 <NativeLayoutObserver onChange={setScreenMetrics} />
623 ) : null}
624 {/* Not a bare marker: Android wraps a refreshable scroll view, which the marker rejects. */}
625 <NativeScrollView
626 className="flex-1"
627 contentInsetAdjustmentBehavior="automatic"
628 keyboardShouldPersistTaps="handled"
629 keyboardDismissMode="interactive"
630 refreshControl={
631 <RefreshControl
632 refreshing={pullRefresh.refreshing}
633 onRefresh={() => void pager.refresh(registry, pullRefresh.onRefresh)}
634 />
635 }
636 contentContainerStyle={{
637 paddingHorizontal: 16,
638 paddingTop: 8,
639 paddingBottom: showComposer ? composerHeight + 16 : 24,
640 }}
641 >
642 {!issue ? (
643 detailQuery.error && !detailQuery.isPending ? (
644 <EmptyState
645 title={gt("Couldn't load this issue")}
646 detail={detailQuery.error}
647 variant="plain"
648 />
649 ) : (
650 <AppActivityIndicator className="my-12" colorClassName="accent-icon" />
651 )
652 ) : (
653 <View className="gap-5">
654 <IssueIdentity
655 issue={issue}
656 access={access}
657 busy={busy === "state"}
658 onMove={moveTo}
659 onEditLabels={() => navigation.navigate("IssueLabels", identity)}
660 onEditAssignees={() => navigation.navigate("IssueAssignees", identity)}
661 />
662 {mutationError || olderCommentsError || (detail && detailQuery.error) ? (
663 <Text selectable className="text-sm text-danger-foreground">
664 {mutationError ?? olderCommentsError ?? detailQuery.error}
665 </Text>
666 ) : null}
667 {!detail ? (
668 detailQuery.error && !detailQuery.isPending ? (
669 <EmptyState
670 title={gt("Couldn't load this issue")}
671 detail={detailQuery.error}
672 variant="plain"
673 />
674 ) : (
675 <IssueLoadingBody />
676 )
677 ) : (
678 <>
679 <PullRequestDescription
680 markdown={detail.body}
681 footer={
682 detail.reactions !== undefined ? (
683 <IssueReactions
684 params={params}
685 reactions={detail.reactions}
686 canReact={access?.react === true}
687 />
688 ) : undefined
689 }
690 />
691 {detail.linkedPullRequests.length > 0 ? (
692 <LinkedPullRequests params={params} links={detail.linkedPullRequests} />
693 ) : null}
694 <LinkedThreads params={params} host={detail.host} />
695 <View className="gap-3">
696 <PullRequestSectionHeading>
697 {detail.commentCount > 0
698 ? gt(
699 "{count, plural, one {Activity · {count} comment} other {Activity · {count} comments}}",
700 { count: detail.commentCount },
701 )
702 : gt("Activity")}
703 </PullRequestSectionHeading>
704 {nextCursor !== null ? (
705 <Button
706 label={loadingOlder ? gt("Loading…") : gt("Load older comments")}
707 disabled={busy !== null || !canLoadOlder}
708 onPress={() => void loadOlder()}
709 />
710 ) : null}
711 {timeline.length === 0 ? (
712 <Text className="text-sm text-foreground-muted">
713 <T>Nothing has happened here yet.</T>
714 </Text>
715 ) : null}
716 {timeline.map((item) => (
717 <View key={item.key}>{item.content}</View>
718 ))}
719 </View>
720 </>
721 )}
722 </View>
723 )}
724 </NativeScrollView>
725 {showComposer ? (
726 <KeyboardStickyView
727 // On the unfolded Duo the sidebar's search shares the keyboard; follow it only for ours.
728 enabled={deviceType !== "duo-unfolded" || composerFocused}
729 pointerEvents="box-none"
730 style={{ position: "absolute", bottom: 0, left: 0, right: 0, top: 0 }}
731 offset={{ closed: 0, opened: composerBottomInset }}
732 >
733 <View
734 pointerEvents="box-none"
735 style={{
736 position: "absolute",
737 bottom: controlInsets.bottom,
738 left: controlInsets.left,
739 right: controlInsets.right,
740 }}
741 >
742 <IssueCommentComposer
743 ownerKey={`issue-comment:${issueParamsKey(params)}`}
744 label={issue?.displayKey ?? params.issueKey}
745 blocked={commentBlocked}
746 posting={busy === "comment"}
747 bottomInset={composerBottomInset}
748 contentMaxWidth={contentMaxWidth}
749 onSubmit={submitComment}
750 onHeightChange={setComposerHeight}
751 onFocusChange={setComposerFocused}
752 />
753 </View>
754 </KeyboardStickyView>
755 ) : null}
756 </ScreenContent>
757 </View>
758 </PullRequestMarkdownRepository>
759 );
760 }