Skip to content
Source
Sign inSign up

use-open-thread-pull-requests.ts

34 lines1.2 KB

1import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
2import { useNavigation } from "@react-navigation/native";
3​
4import * as Dialog from "../../components/ui/Dialog";
5import { useNavigateToPullRequest } from "../../native/useOpenPullRequest";
6import {
7 resolveThreadPrBadgeAction,
8 type ThreadPrPresentation,
9} from "../../state/thread-pr-presentation";
10​
11/** Called once per thread list so virtualized rows share one stable handler. */
12export function useOpenThreadPullRequests() {
13 const navigation = useNavigation();
14 const navigateToPullRequest = useNavigateToPullRequest();
15 return (thread: EnvironmentThreadShell, pr: ThreadPrPresentation) => {
16 if (resolveThreadPrBadgeAction(pr).kind === "list") {
17 navigation.navigate("ThreadPullRequests", {
18 environmentId: String(thread.environmentId),
19 threadId: String(thread.id),
20 });
21 return;
22 }
23 void navigateToPullRequest(pr.url, {
24 environmentId: String(thread.environmentId),
25 projectId: String(thread.projectId),
26 }).then((opened) => {
27 if (!opened)
28 Dialog.alert(
29 `Unable to open ${pr.changeRequest.shortLabel}`,
30 `The ${pr.changeRequest.singular} could not be opened.`,
31 );
32 });
33 };