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