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

IssueRouteScreen.tsx

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