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

usePullRequestIntentPrefetch.ts

44 lines1.4 KB

1import type { EnvironmentId, ProjectId } from "@t3tools/contracts";
2​
3import { useIntentTarget } from "~/hooks/useIntentTarget";
4import { pullRequestEnvironment } from "~/state/pullRequests";
5import { useEnvironmentQuery } from "~/state/query";
6​
7import { pullRequestPanelReference } from "./usePullRequestDetail";
8​
9interface PullRequestIntentTarget {
10 readonly environmentId: EnvironmentId;
11 readonly projectId: ProjectId;
12 readonly host: string;
13 readonly repository: string;
14 readonly number: number;
16​
17/**
18 * Reads the detail and activity a row's panel will ask for once the pointer or focus rests on it,
19 * so the click paints from them. Passing over rows asks the host nothing, and leaving a row stops
20 * reading it.
21 */
22export function usePullRequestIntentPrefetch(
23 isListed: (target: PullRequestIntentTarget) => boolean,
24) {
25 const [target, setIntent] = useIntentTarget(isListed);
26 const reference =
27 target === null
28 ? null
29 : pullRequestPanelReference({ ...target, host: target.host.toLowerCase() });
30 useEnvironmentQuery(
31 target === null || reference === null
32 ? null
33 : pullRequestEnvironment.detail({
34 environmentId: target.environmentId,
35 input: { ...reference, allowStale: false },
36 }),
37 );
38 useEnvironmentQuery(
39 target === null || reference === null
40 ? null
41 : pullRequestEnvironment.activity({ environmentId: target.environmentId, input: reference }),
42 );
43 return setIntent;