Open History to see the last commit
1import type { EnvironmentId, PullRequestRef } from "@t3tools/contracts";
2import { useMemo } from "react";
3import {
4 savedPullRequestStack,
5 pullRequestStackView,
6} from "../components/pullRequest/pullRequestStackSnapshot";
7import { useThreadShells } from "./entities";
8import { pullRequestStackAtom } from "./pullRequests";
9import { useEnvironmentQuery } from "./query";
10
11export function usePullRequestStack(
12 environmentId: EnvironmentId,
13 reference: PullRequestRef | null,
14) {
15 const threads = useThreadShells();
16 const saved = useMemo(
17 () =>
18 reference === null
19 ? null
20 : savedPullRequestStack(
21 threads
22 .filter((thread) => thread.environmentId === environmentId)
23 .flatMap((thread) => thread.pullRequests ?? []),
24 reference,
25 ),
26 [environmentId, reference, threads],
27 );
28 const query = useEnvironmentQuery(
29 reference === null ? null : pullRequestStackAtom({ environmentId, input: reference }),
30 );
31 return { ...query, ...pullRequestStackView(query, saved) };
32}