preloading for pr diffs
123345656789101112121314151617181920212223242526192021222728293031323334353637383940413042434445464748495051525354551 unmodified lineimport { useQueryClient } from '@tanstack/solid-query';import { usePreloader } from '../components/common';import { getRepo } from './api/repos';import { getRepo, type RepoContext } from './api/repos';import { getIssue } from './api/issues';import { getPull } from './api/pulls';import { repoQueryKey, issueQueryKey, pullQueryKey } from './api/keys';import { fetchPullRoundPatch, getPull } from './api/pulls';import { repoQueryKey, issueQueryKey, pullQueryKey, pullPatchQueryKey } from './api/keys';
export const useIssuePreloader = () => { const queryClient = useQueryClient(); const preload = usePreloader();
return (repoLabel: string, kind: 'issue' | 'pull', uri: string, number?: number) => { return ( repoLabel: string, kind: 'issue' | 'pull', uri: string, number?: string | number, repoContext?: RepoContext, ) => { const [owner, slug] = repoLabel.split('/'); const issueRef = String(number || uri.split('/').pop());
return preload( [kind, uri, 'prefetch'], async () => { const repo = repoContext || const repo = await queryClient.fetchQuery({ queryKey: repoQueryKey(owner, slug), queryFn: () => getRepo(owner, slug), }); (await queryClient.fetchQuery({ queryKey: repoQueryKey(owner, slug), queryFn: () => getRepo(owner, slug), }));
if (!repo) { return; }
if (kind === 'issue') { await queryClient.prefetchQuery({ queryKey: issueQueryKey(repo.repoDid, issueRef), queryFn: () => getIssue(repo, issueRef), }); } else { await queryClient.prefetchQuery({ const pullDetail = await queryClient.fetchQuery({ queryKey: pullQueryKey(repo.repoDid, issueRef), queryFn: () => getPull(repo, issueRef), });
const roundIndex = Math.max(0, pullDetail.pull.value.rounds.length - 1); await queryClient.prefetchQuery({ queryKey: pullPatchQueryKey(pullDetail.pull.uri, roundIndex), queryFn: () => fetchPullRoundPatch(pullDetail.pull, roundIndex), }); } }, ); };1 unmodified line1 unmodified line234561 unmodified lineexport const issuesQueryKey = (repoDid: string) => ['issues', repoDid] as const;export const issueQueryKey = (repoDid: string, issueRef: string) => ['issue', repoDid, issueRef] as const;export const pullsQueryKey = (repoDid: string) => ['pulls', repoDid] as const;export const pullQueryKey = (repoDid: string, pullRef: string) => ['pull', repoDid, pullRef] as const;export const pullPatchQueryKey = (pullUri: string, roundIndex: number) => ['pull-patch', pullUri, roundIndex] as const;7 unmodified lines8910111212131415161718192021222324252631 unmodified lines58596061606162636465102 unmodified linesExpand all168169170171172172173174175176177178179180181182521 unmodified linesExpand all7 unmodified linesimport { resolveActor } from '../../lib/api/identity';import { parseAtUri } from '../../lib/api/records';import type { RepoContext } from '../../lib/api/repos';import { useAuth } from '../../lib/auth';import { useIssuePreloader } from '../../lib/preloading';import { Avatar, ErrorState, PaginationControls, StateBadge, ToggleButton, buttonStyles, cardStyles, inputStyles, textareaStyles, usePreloader } from '../../components/common';import { Avatar, ErrorState, PaginationControls, StateBadge, ToggleButton, buttonStyles, cardStyles, inputStyles, textareaStyles } from '../../components/common';import { AtUriPanel, MarkdownBlock, RepoFormSkeleton, RepoListPageSkeleton, RepoListSkeleton, RepoThreadSkeleton, IssueOrPullRow, ThreadCommentView } from '../../components/repo';import { RepoFrame, issueQueryKey, issuesQueryKey, useRepoQuery } from './shared';import { REPO_LIST_PAGE_LIMIT, formatRelativeTime, getErrorMessage, issueHref, parseIntegerSearchParam, uniqueCommenters, saveRecentIssueOrPull } from '../../lib/repo-utils';import { buildIssueCommentThreads, buildIssueFilterQuery, parseIssueFilter } from './issues-helpers';
export const IssuesPage: Component = () => { const auth = useAuth(); const repoQuery = useRepoQuery(); const issuePreloader = useIssuePreloader(); const [searchParams, setSearchParams] = useSearchParams(); const filter = createMemo(() => parseIssueFilter(searchParams.q)); const stateFilter = createMemo(() => filter().state); const authorFilter = createMemo(() => filter().author);31 unmodified lines limit: String(pageLimit()), }); };
const preload = usePreloader();
const issuesQuery = createQuery(() => { const repo = repoQuery.data; return { queryKey: [...issuesQueryKey(repo?.repoDid ?? ''), stateFilter(), authorFilter(), textFilter(), pageOffset(), pageLimit()],102 unmodified linesExpand all kind="issue" author={{ did: issue.author.did, handle: issue.author.handle }} createdAt={issue.value.createdAt} href={issueHref(repoQuery.data!, issue.number || issue.rkey)} {...preload(issueQueryKey(repoQuery.data!.repoDid, String(issue.number || issue.rkey)), () => getIssue(repoQuery.data!, String(issue.number || issue.rkey)))} {...issuePreloader( `${repoQuery.data!.owner.handle}/${repoQuery.data!.slug}`, 'issue', issue.uri, issue.number || issue.rkey, repoQuery.data!, )} /> )} </For> </div>521 unmodified linesExpand all25 unmodified lines26272829303031323233343536373839404142434431 unmodified lines76777879787980818283108 unmodified linesExpand all192193194195196196197198199200201202203204205206899 unmodified linesExpand all1106110711081109110411101111111211131114530 unmodified linesExpand all25 unmodified linesimport { createPull, createPullComment, fetchPullRoundPatch, getPull, listPullsPage, mergePull, setPullStatus } from '../../lib/api/pulls';import { parseAtUri } from '../../lib/api/records';import { compareBranches, getRepoBranches, type RepoContext, compareFork, listRepoRecords } from '../../lib/api/repos';import { useAuth } from '../../lib/auth';import { useIssuePreloader } from '../../lib/preloading';import { Avatar, ErrorState, LoadingState, PaginationControls, StateBadge, ToggleButton, buttonStyles, cardStyles, textareaStyles, usePreloader } from '../../components/common';import { Avatar, ErrorState, LoadingState, PaginationControls, StateBadge, ToggleButton, buttonStyles, cardStyles, textareaStyles } from '../../components/common';import { AtUriPanel, BranchPill, DiffView, MarkdownBlock, PullComposeSkeleton, PullDiffSkeleton, PullDiffView, RepoListPageSkeleton, RepoListSkeleton, RepoThreadSkeleton, IssueOrPullRow, ThreadCommentView } from '../../components/repo';import { RepoFrame, pullQueryKey, pullsQueryKey, useRepoQuery } from './shared';import { RepoFrame, pullQueryKey, pullsQueryKey, useRepoQuery, pullPatchQueryKey } from './shared';import { REPO_LIST_PAGE_LIMIT, formatRelativeTime, getErrorMessage, parseIntegerSearchParam, pullHref, uniqueCommenters, saveRecentIssueOrPull } from '../../lib/repo-utils';import { buildPullFilterQuery, parsePastedPatchPrefill, parsePullFilter, type PullSourceMode, getRoundIndexForComment, buildPRCommentThreads } from './pulls-helpers';
export const PullsPage: Component = () => { const auth = useAuth(); const repoQuery = useRepoQuery(); const issuePreloader = useIssuePreloader(); const [searchParams, setSearchParams] = useSearchParams(); const filter = createMemo(() => parsePullFilter(searchParams.q)); const stateFilter = createMemo(() => filter().state); const authorFilter = createMemo(() => filter().author);31 unmodified lines limit: String(pageLimit()), }); };
const preload = usePreloader();
const pullsQuery = createQuery(() => { const repo = repoQuery.data; return { queryKey: [...pullsQueryKey(repo?.repoDid ?? ''), stateFilter(), authorFilter(), textFilter(), pageOffset(), pageLimit()],108 unmodified linesExpand all kind="pull" author={{ did: pull.author.did, handle: pull.author.handle }} createdAt={pull.value.createdAt} href={pullHref(repoQuery.data!, pull.number || pull.rkey)} {...preload(pullQueryKey(repoQuery.data!.repoDid, String(pull.number || pull.rkey)), () => getPull(repoQuery.data!, String(pull.number || pull.rkey)))} {...issuePreloader( `${repoQuery.data!.owner.handle}/${repoQuery.data!.slug}`, 'pull', pull.uri, pull.number || pull.rkey, repoQuery.data!, )} meta={ <> <span>·</span> <span>{pull.value.rounds.length} round{pull.value.rounds.length === 1 ? '' : 's'}</span>899 unmodified linesExpand all
const patchQuery = createQuery(() => { const detail = pullQuery.data; return { queryKey: ['pull-patch', detail?.pull.uri, roundIndex()], queryKey: pullPatchQueryKey(detail?.pull.uri ?? '', roundIndex()), enabled: Boolean(detail), queryFn: async () => fetchPullRoundPatch(detail!.pull, roundIndex()), }; });530 unmodified linesExpand all12 unmodified lines13141516171718191920212223471 unmodified linesExpand all12 unmodified linesimport { useLiveEvents } from '../../lib/live-events';import { Avatar, ErrorState, cardStyles } from '../../components/common';import { RepoFrameSkeleton, RepoTabLink } from '../../components/repo';import { getErrorMessage, saveRecentRepo, trimUri } from '../../lib/repo-utils';import { repoQueryKey, issuesQueryKey, issueQueryKey, pullsQueryKey, pullQueryKey } from '../../lib/api/keys';import { repoQueryKey, issuesQueryKey, issueQueryKey, pullsQueryKey, pullQueryKey, pullPatchQueryKey } from '../../lib/api/keys';
export { repoQueryKey, issuesQueryKey, issueQueryKey, pullsQueryKey, pullQueryKey };export { repoQueryKey, issuesQueryKey, issueQueryKey, pullsQueryKey, pullQueryKey, pullPatchQueryKey };
type OptimisticStarState = { state: 'starred'; rkey?: string } | { state: 'unstarred'; rkey: string };
const createRepoQuery = () => {471 unmodified linesExpand all