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