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