Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

IssueRouteScreen.tsx

814 lines31.2 KB

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