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

use-open-thread-pull-requests.ts

51 lines1.8 KB

1import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
2import { useNavigation } from "@react-navigation/native";
3import { useGT, select } from "gt-react-native";
4import { changeRequestTermKind } from "../../lib/changeRequestTerm";
5​
6import * as Dialog from "../../components/ui/Dialog";
7import { useNavigateToPullRequest } from "../../native/useOpenPullRequest";
8import {
9 resolveThreadPrBadgeAction,
10 type ThreadPrPresentation,
11} from "../../state/thread-pr-presentation";
12​
13/** Called once per thread list so virtualized rows share one stable handler. */
14export function useOpenThreadPullRequests() {
15 const gt = useGT();
16 const navigation = useNavigation();
17 const navigateToPullRequest = useNavigateToPullRequest();
18 return (thread: EnvironmentThreadShell, pr: ThreadPrPresentation) => {
19 if (resolveThreadPrBadgeAction(pr).kind === "list") {
20 navigation.navigate("ThreadPullRequests", {
21 environmentId: String(thread.environmentId),
22 threadId: String(thread.id),
23 });
24 return;
25 }
26 void navigateToPullRequest(pr.url, {
27 environmentId: String(thread.environmentId),
28 projectId: String(thread.projectId),
29 }).then((opened) => {
30 if (!opened)
31 Dialog.alert(
32 gt`${select(
33 { term: changeRequestTermKind(pr.changeRequest) },
34 {
35 mr: "Unable to open MR",
36 cr: "Unable to open change request",
37 other: "Unable to open PR",
38 },
39 )}`,
40 gt`${select(
41 { term: changeRequestTermKind(pr.changeRequest) },
42 {
43 mr: "The merge request could not be opened.",
44 cr: "The change request could not be opened.",
45 other: "The pull request could not be opened.",
46 },
47 )}`,
48 );
49 });
50 };