import { useQuery } from '@tanstack/react-query'; import { Skeleton } from '#/components/atoms/skeleton.jsx'; import { ListSkeleton } from '#/components/molecules/list-skeleton.jsx'; import { PageNotice } from '#/components/molecules/page-notice.jsx'; import { Screen } from '#/components/molecules/screen.jsx'; import { diffHref, loadPulls, pullKey } from '#/lib/collab.js'; import { repoRecord } from '#/lib/git.js'; import { CommitPage } from '#/pages/commit.jsx'; const none = []; /** * One pull request's landing page, addressed by what identifies it: the DID of * the account whose copy holds the pulls, and the branch. Both survive a * rebase, so the address keeps working while the shas under it move. * * The pair names nothing directly; the pull request is found among the open * and merged pulls, which is the same read the list screen makes and shares its * cache. */ export function PullPage({ repo, did, branch, tab, commit, space }) { const record = repoRecord(repo, space); const { data: pulls, error } = useQuery({ queryKey: ['pulls', repo, space ?? ''], enabled: Boolean(record), queryFn: () => loadPulls(repo, space), }); if (!record) { return No such repository.; } if (error) { return {error.message}; } if (!pulls) { // The head the pull request opens on, in outline, so the page keeps its // shape while the list that names it arrives. return (
); } const id = pullKey(did, branch); const pull = [...pulls.open, ...pulls.merged].find( (candidate) => candidate.id === id, ); if (!pull) { return ( No branch of that name is in that account's copy. It may have been withdrawn, or renamed. ); } // One of its own commits, read under the pull request that carries it, so // the section a reader is in is the section they came from. It reads as a // commit rather than as a proposal: it is one step of the argument above, // not the argument. if (commit) { return ( ); } return ( ); }