ref0-git 0.3.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/apps/github/.dev.vars.example +2 -1
- package/app/apps/github/generated/git-rest.ts +191 -25
- package/app/apps/github/generated/routeTree.gen.ts +21 -0
- package/app/apps/github/package.json +1 -1
- package/app/apps/github/src/branches/branch-list.tsx +8 -4
- package/app/apps/github/src/branches/branches.ts +10 -5
- package/app/apps/github/src/camo/addresses.ts +120 -0
- package/app/apps/github/src/camo/client.ts +125 -0
- package/app/apps/github/src/camo/fetch.ts +201 -0
- package/app/apps/github/src/camo/lookup.ts +23 -0
- package/app/apps/github/src/camo/node.ts +50 -0
- package/app/apps/github/src/camo/proxy.ts +116 -0
- package/app/apps/github/src/camo/sign-images.ts +307 -0
- package/app/apps/github/src/camo/signing.ts +80 -0
- package/app/apps/github/src/clients/allowed.ts +111 -18
- package/app/apps/github/src/clients/clients.ts +76 -61
- package/app/apps/github/src/clients/transport.ts +13 -0
- package/app/apps/github/src/code/code-tree.tsx +3 -1
- package/app/apps/github/src/code/file-view.tsx +15 -6
- package/app/apps/github/src/code/files.ts +26 -19
- package/app/apps/github/src/code/go-to-file.tsx +2 -1
- package/app/apps/github/src/code/load.ts +41 -23
- package/app/apps/github/src/code/markdown-files.ts +13 -2
- package/app/apps/github/src/code/ref-pages.ts +14 -5
- package/app/apps/github/src/code/ref-switcher.tsx +4 -3
- package/app/apps/github/src/code/refs.ts +42 -8
- package/app/apps/github/src/code/repo-home.tsx +6 -2
- package/app/apps/github/src/code/repo.ts +12 -6
- package/app/apps/github/src/code/saved.ts +5 -3
- package/app/apps/github/src/code/trees.ts +11 -9
- package/app/apps/github/src/components/markdown/markdown.css +6 -0
- package/app/apps/github/src/components/markdown/markdown.tsx +95 -10
- package/app/apps/github/src/components/owner-card.tsx +3 -1
- package/app/apps/github/src/components/repos/your-repos.tsx +3 -1
- package/app/apps/github/src/components/shell/owner-repos.tsx +7 -12
- package/app/apps/github/src/components/shell/repo-switcher.tsx +10 -16
- package/app/apps/github/src/components/signin/device-card.tsx +9 -2
- package/app/apps/github/src/components/user-avatar.tsx +2 -1
- package/app/apps/github/src/context/context.ts +13 -0
- package/app/apps/github/src/diffs/blobs.ts +37 -14
- package/app/apps/github/src/diffs/diff-job.ts +53 -0
- package/app/apps/github/src/diffs/diff-worker.ts +6 -0
- package/app/apps/github/src/diffs/diffing.ts +136 -0
- package/app/apps/github/src/diffs/files.ts +4 -3
- package/app/apps/github/src/diffs/hunks.tsx +101 -53
- package/app/apps/github/src/diffs/patch.ts +20 -11
- package/app/apps/github/src/history/commit-diff.ts +10 -5
- package/app/apps/github/src/history/commit-list.tsx +3 -1
- package/app/apps/github/src/history/commit-page.tsx +4 -2
- package/app/apps/github/src/history/history.ts +12 -10
- package/app/apps/github/src/hooks/allowed.ts +9 -9
- package/app/apps/github/src/hooks/avatars.ts +3 -3
- package/app/apps/github/src/hooks/open-counts.ts +5 -4
- package/app/apps/github/src/hooks/profiles.ts +26 -12
- package/app/apps/github/src/hooks/repos.ts +78 -25
- package/app/apps/github/src/inbox/count.ts +30 -29
- package/app/apps/github/src/inbox/inbox-item.tsx +3 -1
- package/app/apps/github/src/inbox/inbox-page.tsx +5 -2
- package/app/apps/github/src/inbox/marks.ts +26 -15
- package/app/apps/github/src/inbox/release-tags.ts +7 -6
- package/app/apps/github/src/inbox/subjects.ts +5 -4
- package/app/apps/github/src/inbox/subscription-controls.tsx +14 -5
- package/app/apps/github/src/inbox/subscriptions.ts +95 -35
- package/app/apps/github/src/inbox/threads.ts +6 -6
- package/app/apps/github/src/issues/changes.ts +40 -16
- package/app/apps/github/src/issues/counts.ts +8 -5
- package/app/apps/github/src/issues/issue-list.tsx +20 -6
- package/app/apps/github/src/issues/issue-page.tsx +30 -14
- package/app/apps/github/src/issues/issues.ts +195 -46
- package/app/apps/github/src/issues/label-dialog.tsx +8 -11
- package/app/apps/github/src/issues/labels-page.tsx +35 -3
- package/app/apps/github/src/issues/milestone-dialog.tsx +197 -0
- package/app/apps/github/src/issues/milestones-page.tsx +269 -0
- package/app/apps/github/src/issues/new-issue.tsx +3 -1
- package/app/apps/github/src/issues/sidebar.tsx +8 -6
- package/app/apps/github/src/markdown/README.md +22 -17
- package/app/apps/github/src/markdown/context.ts +83 -10
- package/app/apps/github/src/markdown/images.ts +3 -2
- package/app/apps/github/src/markdown/lookup.ts +9 -8
- package/app/apps/github/src/markdown/page-budget.ts +50 -0
- package/app/apps/github/src/markdown/patches.ts +74 -32
- package/app/apps/github/src/markdown/query.ts +7 -2
- package/app/apps/github/src/markdown/remote.ts +106 -0
- package/app/apps/github/src/markdown/render.ts +101 -24
- package/app/apps/github/src/markdown/texts.ts +43 -0
- package/app/apps/github/src/markdown/words-module.d.ts +5 -0
- package/app/apps/github/src/markdown/words-plugin.ts +135 -0
- package/app/apps/github/src/names/repos.ts +1 -1
- package/app/apps/github/src/palette/palette.tsx +7 -4
- package/app/apps/github/src/palette/rows.tsx +54 -33
- package/app/apps/github/src/palette/server.ts +5 -5
- package/app/apps/github/src/palette/targets.ts +1 -0
- package/app/apps/github/src/policy.ts +165 -66
- package/app/apps/github/src/private-repos.ts +2 -2
- package/app/apps/github/src/pulls/compare-page.tsx +6 -3
- package/app/apps/github/src/pulls/files-tab.tsx +480 -214
- package/app/apps/github/src/pulls/held-summary.ts +178 -0
- package/app/apps/github/src/pulls/live.ts +6 -4
- package/app/apps/github/src/pulls/merge-box.tsx +17 -10
- package/app/apps/github/src/pulls/pull-list.tsx +6 -3
- package/app/apps/github/src/pulls/pull-page.tsx +19 -10
- package/app/apps/github/src/pulls/pull.ts +68 -40
- package/app/apps/github/src/pulls/pulls.ts +39 -22
- package/app/apps/github/src/pulls/review-drafts.ts +131 -0
- package/app/apps/github/src/pulls/review.ts +374 -99
- package/app/apps/github/src/pulls/threads.tsx +152 -0
- package/app/apps/github/src/queue/queue-page.tsx +15 -8
- package/app/apps/github/src/queue/queue.ts +35 -20
- package/app/apps/github/src/releases/latest-release.tsx +3 -1
- package/app/apps/github/src/releases/overview.tsx +4 -2
- package/app/apps/github/src/releases/release-form.tsx +8 -5
- package/app/apps/github/src/releases/release-list.tsx +8 -5
- package/app/apps/github/src/releases/release-view.tsx +1 -0
- package/app/apps/github/src/releases/releases.ts +33 -23
- package/app/apps/github/src/releases/tag-list.tsx +3 -1
- package/app/apps/github/src/router.tsx +5 -2
- package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +7 -1
- package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +6 -1
- package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +2 -1
- package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +1 -1
- package/app/apps/github/src/routes/$owner/$repo/branches.tsx +5 -1
- package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +1 -1
- package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +6 -1
- package/app/apps/github/src/routes/$owner/$repo/index.tsx +1 -1
- package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +4 -2
- package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +2 -2
- package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +5 -2
- package/app/apps/github/src/routes/$owner/$repo/labels.tsx +2 -1
- package/app/apps/github/src/routes/$owner/$repo/milestones.tsx +36 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +4 -2
- package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +2 -2
- package/app/apps/github/src/routes/$owner/$repo/queue.tsx +2 -1
- package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +5 -2
- package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +2 -1
- package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +4 -2
- package/app/apps/github/src/routes/$owner/$repo/route.tsx +9 -5
- package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +3 -1
- package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +3 -1
- package/app/apps/github/src/routes/-nav.tsx +10 -2
- package/app/apps/github/src/routes/-root-testing.ts +29 -6
- package/app/apps/github/src/routes/__root.tsx +9 -4
- package/app/apps/github/src/routes/index.tsx +3 -1
- package/app/apps/github/src/routes/orgs/$owner/route.tsx +4 -1
- package/app/apps/github/src/routes/orgs/$owner/settings.tsx +4 -1
- package/app/apps/github/src/seed/acme.ts +1 -1
- package/app/apps/github/src/seed/seed.ts +199 -110
- package/app/apps/github/src/server.ts +24 -15
- package/app/apps/github/src/settings/account-avatar.tsx +4 -1
- package/app/apps/github/src/settings/general-settings.tsx +3 -1
- package/app/apps/github/src/settings/general.ts +4 -4
- package/app/apps/github/src/settings/hook-form.tsx +3 -1
- package/app/apps/github/src/settings/hook-list.tsx +5 -2
- package/app/apps/github/src/settings/hooks.ts +7 -7
- package/app/apps/github/src/settings/org-settings.tsx +3 -1
- package/app/apps/github/src/settings/orgs.ts +21 -11
- package/app/apps/github/src/settings/settings-layout.tsx +3 -1
- package/app/apps/github/src/signin/approval.ts +4 -3
- package/app/apps/github/src/signin/auth.ts +9 -2
- package/app/apps/github/src/signin/device-code.ts +8 -3
- package/app/apps/github/src/signin/device-prompt.ts +28 -3
- package/app/apps/github/src/signin/revoke.ts +36 -0
- package/app/apps/github/tsconfig.json +4 -1
- package/app/apps/github/vite.config.ts +8 -0
- package/app/pnpm-workspace.yaml +12 -5
- package/app/tsconfig.base.json +1 -0
- package/dist/cli/child.mjs +1 -1
- package/dist/cli/credentials.mjs +4 -4
- package/dist/cli/documents.mjs +32 -22
- package/dist/cli/events.mjs +1 -1
- package/dist/cli/failure.mjs +20 -7
- package/dist/cli/folders.mjs +2 -2
- package/dist/cli/git-remote-ref0.mjs +47 -22
- package/dist/cli/git.mjs +1 -1
- package/dist/cli/helpers.mjs +2 -2
- package/dist/cli/hosts.mjs +3 -3
- package/dist/cli/output.mjs +2 -2
- package/dist/cli/prompt.mjs +1 -1
- package/dist/cli/queue.mjs +7 -7
- package/dist/cli/ref0-git.mjs +2 -2
- package/dist/cli/repos.mjs +35 -18
- package/dist/cli/resources.mjs +5 -5
- package/dist/cli/retry-after.mjs +8 -0
- package/dist/cli/setup.mjs +172 -66
- package/dist/cli/sign-in.mjs +65 -23
- package/dist/cli/sign-ins.mjs +4 -4
- package/dist/cli/sqlite.mjs +2 -2
- package/dist/cli/tokens.mjs +3 -3
- package/dist/cli/vendor.mjs +1 -1
- package/dist/init/app.mjs +20 -21
- package/dist/init/choices.mjs +1 -1
- package/dist/init/cloudflare.mjs +15 -19
- package/dist/init/create.mjs +3 -2
- package/dist/init/detect.mjs +4 -4
- package/dist/init/files.mjs +120 -13
- package/dist/init/frameworks.mjs +16 -0
- package/dist/init/git-module.mjs +22 -7
- package/dist/init/jsonc.mjs +9 -7
- package/dist/init/metadata.mjs +9 -3
- package/dist/init/mounts.mjs +13 -10
- package/dist/init/next.mjs +2 -2
- package/dist/init/node-app.mjs +3 -3
- package/dist/init/node.mjs +42 -45
- package/dist/init/nuxt.mjs +153 -27
- package/dist/init/stores.mjs +14 -9
- package/dist/init/sveltekit.mjs +4 -2
- package/dist/init/template.mjs +9 -6
- package/dist/init/templates.mjs +63 -47
- package/dist/init/vercel.mjs +37 -37
- package/dist/init/versions.mjs +3 -3
- package/package.json +6 -5
|
@@ -4,18 +4,21 @@ import {
|
|
|
4
4
|
type FileDiffMetadata,
|
|
5
5
|
type SelectedLineRange,
|
|
6
6
|
} from '@pierre/diffs';
|
|
7
|
-
import { FileDiff, VirtualizerContext } from '@pierre/diffs/react';
|
|
7
|
+
import { FileDiff, VirtualizerContext, WorkerPoolContextProvider } from '@pierre/diffs/react';
|
|
8
8
|
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
|
9
9
|
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
|
10
10
|
|
|
11
11
|
import { highlightedCharsMost, highlightedLinesMost } from '#/lib/highlighting';
|
|
12
12
|
|
|
13
|
+
import { useClients } from '../clients/clients.ts';
|
|
13
14
|
import { FileIcon } from '../components/file-icons/file-icons.tsx';
|
|
14
15
|
import { useTheme } from '../components/theme-provider.tsx';
|
|
15
16
|
import { Button } from '../components/ui/button.tsx';
|
|
16
17
|
import { loadFile, type LoadedFile } from './blobs.ts';
|
|
17
18
|
import type { ChangedFile, Notes, Revisions } from './files.ts';
|
|
18
|
-
import {
|
|
19
|
+
import type { Diffed } from './diff-job.ts';
|
|
20
|
+
import { diffSides, hasWorkers, sideBytesMost } from './diffing.ts';
|
|
21
|
+
import { diffOfPatch, wordDiffedLengthMost, wordDiffOf } from './patch.ts';
|
|
19
22
|
import {
|
|
20
23
|
drawnRows,
|
|
21
24
|
endsOf,
|
|
@@ -52,49 +55,51 @@ function WindowVirtualizer({ children }: { readonly children: ReactNode }) {
|
|
|
52
55
|
);
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
/** Why a file that GitHub's REST sends with no patch shows no diff once loaded. */
|
|
56
|
-
const notShown = {
|
|
57
|
-
binary: 'Binary file not shown.',
|
|
58
|
-
'too-large': 'This file is too large to show its diff here.',
|
|
59
|
-
'too-different': 'This file changed too much to show its diff here.',
|
|
60
|
-
unchanged: "The file's contents didn't change.",
|
|
61
|
-
} as const;
|
|
62
|
-
|
|
63
|
-
/** Why `file` shows no diff once loaded: a rename with its blob unchanged says so. */
|
|
64
|
-
const notShownFor = (file: ChangedFile, kind: keyof typeof notShown) =>
|
|
65
|
-
kind === 'unchanged' && file.status === 'renamed'
|
|
66
|
-
? 'File renamed without changes.'
|
|
67
|
-
: notShown[kind];
|
|
68
|
-
|
|
69
58
|
/** What **Load diff** shows: the file's diff, or why there is none. */
|
|
70
|
-
type Loaded =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
59
|
+
type Loaded = Diffed | Exclude<LoadedFile, { readonly kind: 'text' }>;
|
|
60
|
+
|
|
61
|
+
/** `count` of `unit`, as a refusal names its limit: "1 second", "20 seconds". */
|
|
62
|
+
const counted = (count: number, unit: string) =>
|
|
63
|
+
`${count.toLocaleString('en')} ${unit}${count === 1 ? '' : 's'}`;
|
|
64
|
+
|
|
65
|
+
/** Why `file` shows no diff once loaded, naming the limit it's past: a pure rename says so. */
|
|
66
|
+
const notShownFor = (file: ChangedFile, shown: Exclude<Loaded, { readonly kind: 'diff' }>) => {
|
|
67
|
+
switch (shown.kind) {
|
|
68
|
+
case 'binary':
|
|
69
|
+
return 'Binary file not shown.';
|
|
70
|
+
case 'too-large':
|
|
71
|
+
return `This file is over ${shown.bytes / (1024 * 1024)} MiB, too large to diff here.`;
|
|
72
|
+
case 'too-different':
|
|
73
|
+
return `This file changed too much to diff in ${counted(shown.millis / 1000, 'second')}.`;
|
|
74
|
+
case 'too-many-lines':
|
|
75
|
+
return `This diff has over ${counted(shown.lines, 'changed line')}, too many to show here.`;
|
|
76
|
+
case 'unchanged':
|
|
77
|
+
return file.status === 'renamed'
|
|
78
|
+
? 'File renamed without changes.'
|
|
79
|
+
: "The file's contents didn't change.";
|
|
80
|
+
}
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
+
/** Two sides read whole, diffed off the page's thread until `signal` aborts, or why they aren't. */
|
|
84
|
+
const diffed = async (sides: LoadedFile, cacheKey: string, signal: AbortSignal): Promise<Loaded> =>
|
|
85
|
+
sides.kind === 'text' ? diffSides(sides.old, sides.new, cacheKey, signal) : sides;
|
|
86
|
+
|
|
83
87
|
/**
|
|
84
88
|
* Reads `file`'s two sides once, through the query's cache, for **Load diff** and for expanding
|
|
85
89
|
* a diff's context alike.
|
|
86
90
|
*/
|
|
87
91
|
const useSides = (file: ChangedFile, revisions: Revisions) => {
|
|
92
|
+
const clients = useClients();
|
|
88
93
|
const client = useQueryClient();
|
|
89
94
|
|
|
90
95
|
return useCallback(
|
|
91
96
|
() =>
|
|
92
97
|
client.fetchQuery({
|
|
93
98
|
queryKey: ['file-sides', revisions, file.filename, file.sha],
|
|
94
|
-
queryFn: ({ signal }) => loadFile(file, revisions, signal),
|
|
99
|
+
queryFn: ({ signal }) => loadFile(clients, file, revisions, sideBytesMost(), signal),
|
|
95
100
|
staleTime: Infinity,
|
|
96
101
|
}),
|
|
97
|
-
[client, file, revisions],
|
|
102
|
+
[client, clients, file, revisions],
|
|
98
103
|
);
|
|
99
104
|
};
|
|
100
105
|
|
|
@@ -289,10 +294,13 @@ function LoadDiff({
|
|
|
289
294
|
readonly notes: Notes | undefined;
|
|
290
295
|
}) {
|
|
291
296
|
const [asked, setAsked] = useState(false);
|
|
297
|
+
const client = useQueryClient();
|
|
292
298
|
const sides = useSides(file, revisions);
|
|
299
|
+
const queryKey = ['loaded-file', revisions, file.filename, file.sha];
|
|
300
|
+
// Its signal aborts on **Cancel**, and once the row unmounts, which terminates its Worker.
|
|
293
301
|
const loaded = useQuery({
|
|
294
|
-
queryKey
|
|
295
|
-
queryFn: async () => diffed(await sides(), cacheKey),
|
|
302
|
+
queryKey,
|
|
303
|
+
queryFn: async ({ signal }) => diffed(await sides(), cacheKey, signal),
|
|
296
304
|
enabled: asked,
|
|
297
305
|
staleTime: Infinity,
|
|
298
306
|
});
|
|
@@ -309,17 +317,28 @@ function LoadDiff({
|
|
|
309
317
|
<span className="truncate">{file.filename}</span>
|
|
310
318
|
</span>
|
|
311
319
|
{shown !== undefined ? (
|
|
312
|
-
<span className="text-muted-foreground">{notShownFor(file, shown
|
|
320
|
+
<span className="text-muted-foreground">{notShownFor(file, shown)}</span>
|
|
313
321
|
) : loaded.isError ? (
|
|
314
322
|
<span className="text-destructive">The diff didn't load.</span>
|
|
323
|
+
) : loaded.isFetching ? (
|
|
324
|
+
<span className="flex shrink-0 items-center gap-3">
|
|
325
|
+
<span role="status" className="text-muted-foreground">
|
|
326
|
+
Diffing…
|
|
327
|
+
</span>
|
|
328
|
+
<Button
|
|
329
|
+
variant="outline"
|
|
330
|
+
size="sm"
|
|
331
|
+
onClick={() => {
|
|
332
|
+
setAsked(false);
|
|
333
|
+
void client.cancelQueries({ queryKey });
|
|
334
|
+
}}
|
|
335
|
+
>
|
|
336
|
+
Cancel
|
|
337
|
+
</Button>
|
|
338
|
+
</span>
|
|
315
339
|
) : (
|
|
316
|
-
<Button
|
|
317
|
-
|
|
318
|
-
size="sm"
|
|
319
|
-
disabled={loaded.isFetching}
|
|
320
|
-
onClick={() => setAsked(true)}
|
|
321
|
-
>
|
|
322
|
-
{loaded.isFetching ? 'Loading…' : 'Load diff'}
|
|
340
|
+
<Button variant="outline" size="sm" onClick={() => setAsked(true)}>
|
|
341
|
+
Load diff
|
|
323
342
|
</Button>
|
|
324
343
|
)}
|
|
325
344
|
</div>
|
|
@@ -420,6 +439,33 @@ function End({ onEnd }: { readonly onEnd: () => void }) {
|
|
|
420
439
|
return <div ref={useNear(onEnd)} data-end="" />;
|
|
421
440
|
}
|
|
422
441
|
|
|
442
|
+
/**
|
|
443
|
+
* The Workers `@pierre/diffs` highlights in, off the page's thread: a diff shows plain, then
|
|
444
|
+
* highlighted once a Worker answers. One under `mainThreadMaxCharacters` highlights on the page's
|
|
445
|
+
* thread, where it costs less than the trip; a pool that doesn't start leaves them all there.
|
|
446
|
+
*/
|
|
447
|
+
const highlightPool = {
|
|
448
|
+
poolOptions: {
|
|
449
|
+
workerFactory: () =>
|
|
450
|
+
new Worker(new URL('@pierre/diffs/worker/worker.js', import.meta.url), {
|
|
451
|
+
type: 'module',
|
|
452
|
+
name: 'highlight',
|
|
453
|
+
}),
|
|
454
|
+
poolSize: 2,
|
|
455
|
+
mainThreadMaxCharacters: 20_000,
|
|
456
|
+
},
|
|
457
|
+
highlighterOptions: { lineDiffType: 'word-alt', maxLineDiffLength: wordDiffedLengthMost },
|
|
458
|
+
} as const;
|
|
459
|
+
|
|
460
|
+
/** `children` under the highlight Workers' pool, in a browser that runs Workers. */
|
|
461
|
+
function HighlightPool({ children }: { readonly children: ReactNode }) {
|
|
462
|
+
return hasWorkers() ? (
|
|
463
|
+
<WorkerPoolContextProvider {...highlightPool}>{children}</WorkerPoolContextProvider>
|
|
464
|
+
) : (
|
|
465
|
+
children
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
|
|
423
469
|
/**
|
|
424
470
|
* Each loaded file's hunks, drawn by `@pierre/diffs` as it nears the window, and the next page
|
|
425
471
|
* asked for as the list's end does. The browser alone loads this, and Shiki's grammars with it.
|
|
@@ -436,19 +482,21 @@ export default function Hunks({
|
|
|
436
482
|
readonly onEnd: () => void;
|
|
437
483
|
}) {
|
|
438
484
|
return (
|
|
439
|
-
<
|
|
440
|
-
<
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
485
|
+
<HighlightPool>
|
|
486
|
+
<WindowVirtualizer>
|
|
487
|
+
<div className="flex flex-col gap-4">
|
|
488
|
+
{files.map((file, index) => (
|
|
489
|
+
<FileHunks
|
|
490
|
+
key={`${index}:${file.filename}`}
|
|
491
|
+
file={file}
|
|
492
|
+
index={index}
|
|
493
|
+
revisions={revisions}
|
|
494
|
+
notes={notes}
|
|
495
|
+
/>
|
|
496
|
+
))}
|
|
497
|
+
</div>
|
|
498
|
+
<End onEnd={onEnd} />
|
|
499
|
+
</WindowVirtualizer>
|
|
500
|
+
</HighlightPool>
|
|
453
501
|
);
|
|
454
502
|
}
|
|
@@ -34,20 +34,28 @@ export const diffOfPatch = (file: ChangedFile, key: string): FileDiffMetadata |
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
* How long the
|
|
38
|
-
* the lines that differ: two 800 KB sides changed on
|
|
39
|
-
* as long, so past this it gives up.
|
|
37
|
+
* How long the page's thread may spend diffing two blobs, in milliseconds, in a browser that runs
|
|
38
|
+
* no Web Worker. Myers' diff takes time by the lines that differ: two 800 KB sides changed on
|
|
39
|
+
* every line took 134 s, and a tab stops for as long, so past this it gives up.
|
|
40
40
|
*/
|
|
41
41
|
export const diffedMillisMost = 1000;
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
44
|
+
* How long a diff Worker may spend diffing two blobs, in milliseconds: off the page's thread, a
|
|
45
|
+
* pair of 10,000 lines changed on every line finishes in 9.6 s. Past this it gives up, and it
|
|
46
|
+
* held at most 275 MB doing so on two 4 MiB sides.
|
|
47
|
+
*/
|
|
48
|
+
export const workerDiffedMillisMost = 20_000;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Two sides **Load diff** read, diffed with GitHub's 3 lines of context, or `undefined` when they
|
|
52
|
+
* differ too much to diff within `millis`.
|
|
46
53
|
*/
|
|
47
54
|
export const diffOfSides = (
|
|
48
55
|
old: Side | null,
|
|
49
56
|
changed: Side | null,
|
|
50
57
|
key: string,
|
|
58
|
+
millis: number,
|
|
51
59
|
): FileDiffMetadata | undefined => {
|
|
52
60
|
const name = changed?.name ?? old?.name ?? '';
|
|
53
61
|
const patch = createTwoFilesPatch(
|
|
@@ -59,7 +67,7 @@ export const diffOfSides = (
|
|
|
59
67
|
undefined,
|
|
60
68
|
{
|
|
61
69
|
context: 3,
|
|
62
|
-
timeout:
|
|
70
|
+
timeout: millis,
|
|
63
71
|
},
|
|
64
72
|
);
|
|
65
73
|
const parsed =
|
|
@@ -72,7 +80,7 @@ export const diffOfSides = (
|
|
|
72
80
|
};
|
|
73
81
|
|
|
74
82
|
/** The longest line `@pierre/diffs` diffs word by word, its own default. */
|
|
75
|
-
const wordDiffedLengthMost = 1000;
|
|
83
|
+
export const wordDiffedLengthMost = 1000;
|
|
76
84
|
|
|
77
85
|
/**
|
|
78
86
|
* What the words of a file's changed lines may cost to diff, as the sum of each paired line's
|
|
@@ -92,10 +100,11 @@ const lengthOf = (line: string | undefined) => {
|
|
|
92
100
|
};
|
|
93
101
|
|
|
94
102
|
/**
|
|
95
|
-
* How `@pierre/diffs` marks what changed within `diff`'s lines
|
|
96
|
-
* each pair of a removed and an added line no longer than the length
|
|
97
|
-
* longest that keeps the pairs within it under `wordDiffedMost`, so short
|
|
98
|
-
* when long ones would cost too much.
|
|
103
|
+
* How `@pierre/diffs` marks what changed within `diff`'s lines on the page's thread: word by
|
|
104
|
+
* word, as GitHub does, in each pair of a removed and an added line no longer than the length
|
|
105
|
+
* this gives. It's the longest that keeps the pairs within it under `wordDiffedMost`, so short
|
|
106
|
+
* pairs keep their marks when long ones would cost too much. A highlight Worker, which takes its
|
|
107
|
+
* pool's marks instead, marks lines up to `wordDiffedLengthMost` off the page's thread.
|
|
99
108
|
*/
|
|
100
109
|
export const wordDiffOf = (diff: FileDiffMetadata) => {
|
|
101
110
|
const pairs: { readonly longest: number; readonly cost: number }[] = [];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { queryOptions, type QueryClient } from '@tanstack/react-query';
|
|
2
2
|
import * as Schema from 'effect/Schema';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import type { Clients } from '../clients/clients.ts';
|
|
5
5
|
import type { RepoPlace } from '../code/places.ts';
|
|
6
6
|
import type { ChangedFile, FileList } from '../diffs/files.ts';
|
|
7
7
|
|
|
@@ -23,11 +23,11 @@ export interface CommitFiles {
|
|
|
23
23
|
* A commit's changed files against its first parent, or against nothing for the first commit,
|
|
24
24
|
* in one call: the drop-in answers `stats` only when the list is whole.
|
|
25
25
|
*/
|
|
26
|
-
export const commitFiles = (place: RepoPlace, sha: string) =>
|
|
26
|
+
export const commitFiles = (clients: Clients, place: RepoPlace, sha: string) =>
|
|
27
27
|
queryOptions({
|
|
28
28
|
queryKey: ['commit-files', place.owner, place.repo, sha],
|
|
29
29
|
queryFn: async ({ signal }): Promise<CommitFiles> => {
|
|
30
|
-
const answer = await github.GET('/repos/{owner}/{repo}/commits/{ref}', {
|
|
30
|
+
const answer = await clients.github.GET('/repos/{owner}/{repo}/commits/{ref}', {
|
|
31
31
|
params: { path: { ...place, ref: sha } },
|
|
32
32
|
signal,
|
|
33
33
|
});
|
|
@@ -45,10 +45,15 @@ export const commitFiles = (place: RepoPlace, sha: string) =>
|
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
/** A commit's files as `DiffView` lists them: one page, from the call its page already made. */
|
|
48
|
-
export const commitFileList = (
|
|
48
|
+
export const commitFileList = (
|
|
49
|
+
clients: Clients,
|
|
50
|
+
client: QueryClient,
|
|
51
|
+
place: RepoPlace,
|
|
52
|
+
sha: string,
|
|
53
|
+
): FileList => ({
|
|
49
54
|
key: ['commit-files', place.owner, place.repo, sha],
|
|
50
55
|
page: async () => ({
|
|
51
|
-
files: (await client.fetchQuery(commitFiles(place, sha))).files,
|
|
56
|
+
files: (await client.fetchQuery(commitFiles(clients, place, sha))).files,
|
|
52
57
|
next: undefined,
|
|
53
58
|
}),
|
|
54
59
|
});
|
|
@@ -2,6 +2,7 @@ import { useQueryClient } from '@tanstack/react-query';
|
|
|
2
2
|
import { useRouter } from '@tanstack/react-router';
|
|
3
3
|
import { CodeIcon, GitCommitIcon } from 'lucide-react';
|
|
4
4
|
|
|
5
|
+
import { useClients } from '../clients/clients.ts';
|
|
5
6
|
import { ItemList } from '../components/item-list.tsx';
|
|
6
7
|
import { RelativeTime } from '../components/relative-time.tsx';
|
|
7
8
|
import { Alert, AlertDescription } from '../components/ui/alert.tsx';
|
|
@@ -126,10 +127,11 @@ export function CommitDays({ at, rows }: { readonly at: At; readonly rows: reado
|
|
|
126
127
|
* its first page, or finds there's nothing there to read.
|
|
127
128
|
*/
|
|
128
129
|
function Changed({ at }: { readonly at: At }) {
|
|
130
|
+
const clients = useClients();
|
|
129
131
|
const client = useQueryClient();
|
|
130
132
|
const router = useRouter();
|
|
131
133
|
const reload = async () => {
|
|
132
|
-
await client.resetQueries({ queryKey: history(at, at.ref, at.path).queryKey });
|
|
134
|
+
await client.resetQueries({ queryKey: history(clients, at, at.ref, at.path).queryKey });
|
|
133
135
|
await router.invalidate();
|
|
134
136
|
};
|
|
135
137
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
|
2
2
|
import { FolderCodeIcon, HistoryIcon } from 'lucide-react';
|
|
3
3
|
|
|
4
|
+
import { useClients } from '../clients/clients.ts';
|
|
4
5
|
import { RelativeTime } from '../components/relative-time.tsx';
|
|
5
6
|
import { Alert, AlertDescription } from '../components/ui/alert.tsx';
|
|
6
7
|
import { buttonVariants } from '../components/ui/button.tsx';
|
|
@@ -26,8 +27,9 @@ import { titleOf } from './commit-list.tsx';
|
|
|
26
27
|
* shows, so a commit's patches never ride in the server's HTML; until then, a box holds its place.
|
|
27
28
|
*/
|
|
28
29
|
function CommitDiff({ place, commit }: { readonly place: RepoPlace; readonly commit: Commit }) {
|
|
30
|
+
const clients = useClients();
|
|
29
31
|
const client = useQueryClient();
|
|
30
|
-
const changed = useQuery(commitFiles(place, commit.sha));
|
|
32
|
+
const changed = useQuery(commitFiles(clients, place, commit.sha));
|
|
31
33
|
|
|
32
34
|
if (changed.isError) {
|
|
33
35
|
return (
|
|
@@ -50,7 +52,7 @@ function CommitDiff({ place, commit }: { readonly place: RepoPlace; readonly com
|
|
|
50
52
|
</p>
|
|
51
53
|
)}
|
|
52
54
|
<DiffView
|
|
53
|
-
list={commitFileList(client, place, commit.sha)}
|
|
55
|
+
list={commitFileList(clients, client, place, commit.sha)}
|
|
54
56
|
revisions={{ repo, base: commit.parents[0] ?? commit.sha, head: commit.sha }}
|
|
55
57
|
/>
|
|
56
58
|
</section>
|
|
@@ -5,7 +5,7 @@ import { atOf, refFresh, rowOf, type CommitRow } from '../code/refs.ts';
|
|
|
5
5
|
import { repoAt } from '../code/repo.ts';
|
|
6
6
|
import { nextCursor } from '../hooks/repos.ts';
|
|
7
7
|
import { cached, cachedPages } from '../clients/cached.ts';
|
|
8
|
-
import {
|
|
8
|
+
import { type Clients, useClients } from '../clients/clients.ts';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* A ref's history, or a path's at it, newest first: a page of commits at a time, each after the
|
|
@@ -28,6 +28,7 @@ const firstPage: string | undefined = undefined;
|
|
|
28
28
|
* none for `ref`, such as a tag on a tree or a blob, as GitHub's own page isn't found there.
|
|
29
29
|
*/
|
|
30
30
|
export const historyPage = async (
|
|
31
|
+
clients: Clients,
|
|
31
32
|
place: RepoPlace,
|
|
32
33
|
ref: Ref,
|
|
33
34
|
path: string,
|
|
@@ -37,7 +38,7 @@ export const historyPage = async (
|
|
|
37
38
|
// the client leaves out what's `undefined`.
|
|
38
39
|
const paging = { sha: revisionOf(ref), per_page: commitsPerPage, after };
|
|
39
40
|
const query = path === '' ? { ...paging } : { ...paging, path };
|
|
40
|
-
const answer = await github.GET('/repos/{owner}/{repo}/commits', {
|
|
41
|
+
const answer = await clients.github.GET('/repos/{owner}/{repo}/commits', {
|
|
41
42
|
params: { path: place, query },
|
|
42
43
|
});
|
|
43
44
|
if (answer.response.status === 404) return null;
|
|
@@ -50,17 +51,17 @@ export const historyPage = async (
|
|
|
50
51
|
};
|
|
51
52
|
|
|
52
53
|
/** `ref`'s history, or `path`'s, a page at a time as the reader asks for more. */
|
|
53
|
-
export const history = (place: RepoPlace, ref: Ref, path: string) => ({
|
|
54
|
+
export const history = (clients: Clients, place: RepoPlace, ref: Ref, path: string) => ({
|
|
54
55
|
queryKey: ['history', place.owner, place.repo, ref.kind, ref.name, path] as const,
|
|
55
56
|
queryFn: ({ pageParam }: { readonly pageParam: string | undefined }) =>
|
|
56
|
-
historyPage(place, ref, path, pageParam),
|
|
57
|
+
historyPage(clients, place, ref, path, pageParam),
|
|
57
58
|
initialPageParam: firstPage,
|
|
58
59
|
getNextPageParam: (last: HistoryPage | null) => last?.next,
|
|
59
60
|
staleTime: ref.kind === 'commit' ? Infinity : refFresh,
|
|
60
61
|
});
|
|
61
62
|
|
|
62
63
|
export const useHistory = (place: RepoPlace, ref: Ref, path: string) =>
|
|
63
|
-
useInfiniteQuery(history(place, ref, path));
|
|
64
|
+
useInfiniteQuery(history(useClients(), place, ref, path));
|
|
64
65
|
|
|
65
66
|
/**
|
|
66
67
|
* What a history page loads: where its splat points, the repository's default branch for none,
|
|
@@ -68,20 +69,21 @@ export const useHistory = (place: RepoPlace, ref: Ref, path: string) =>
|
|
|
68
69
|
* history.
|
|
69
70
|
*/
|
|
70
71
|
export const loadHistory = async (
|
|
72
|
+
clients: Clients,
|
|
71
73
|
client: QueryClient,
|
|
72
74
|
place: RepoPlace,
|
|
73
75
|
splat: string,
|
|
74
76
|
): Promise<{ readonly at: At } | undefined> => {
|
|
75
|
-
const repo = splat === '' ? await cached(client, repoAt(place)) : undefined;
|
|
77
|
+
const repo = splat === '' ? await cached(client, repoAt(clients, place)) : undefined;
|
|
76
78
|
if (repo === null) return undefined;
|
|
77
79
|
|
|
78
80
|
const at =
|
|
79
81
|
repo === undefined
|
|
80
|
-
? await atOf(client, place, splat)
|
|
82
|
+
? await atOf(clients, client, place, splat)
|
|
81
83
|
: { ...place, ref: { name: repo.defaultBranch, kind: 'branch' as const }, path: '' };
|
|
82
84
|
if (at === undefined) return undefined;
|
|
83
85
|
|
|
84
|
-
const read = await cachedPages(client, history(place, at.ref, at.path));
|
|
86
|
+
const read = await cachedPages(client, history(clients, place, at.ref, at.path));
|
|
85
87
|
|
|
86
88
|
return read.pages[0] === null ? undefined : { at };
|
|
87
89
|
};
|
|
@@ -99,11 +101,11 @@ export interface Commit {
|
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
/** The commit `oid`, without its diff: one call, or `null` where none is. */
|
|
102
|
-
export const commitAt = (place: RepoPlace, oid: string) =>
|
|
104
|
+
export const commitAt = (clients: Clients, place: RepoPlace, oid: string) =>
|
|
103
105
|
queryOptions({
|
|
104
106
|
queryKey: ['commit', place.owner, place.repo, oid],
|
|
105
107
|
queryFn: async (): Promise<Commit | null> => {
|
|
106
|
-
const answer = await github.GET('/repos/{owner}/{repo}/git/commits/{commit_sha}', {
|
|
108
|
+
const answer = await clients.github.GET('/repos/{owner}/{repo}/git/commits/{commit_sha}', {
|
|
107
109
|
params: { path: { ...place, commit_sha: oid } },
|
|
108
110
|
});
|
|
109
111
|
if ([404, 422].includes(answer.response.status)) return null;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { pageOperations, type PageOperation } from '../clients/allowed.ts';
|
|
4
|
+
import { type Clients, useClients } from '../clients/clients.ts';
|
|
4
5
|
|
|
5
6
|
/** The repo a page is on, by its owner and name. */
|
|
6
7
|
interface Place {
|
|
@@ -9,17 +10,16 @@ interface Place {
|
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
/** What the viewer may do on the repo, or on its issue `number`, asked once for every control. */
|
|
12
|
-
export const allowedHere = (place: Place, number?: number) =>
|
|
13
|
+
export const allowedHere = (clients: Clients, place: Place, number?: number) =>
|
|
13
14
|
queryOptions({
|
|
14
15
|
queryKey: ['allowed', place.owner, place.repo, number ?? null],
|
|
15
16
|
queryFn: async (): Promise<ReadonlySet<PageOperation>> =>
|
|
16
17
|
new Set(
|
|
17
|
-
await
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}),
|
|
18
|
+
await clients.allowed(
|
|
19
|
+
number === undefined
|
|
20
|
+
? { owner: place.owner, repo: place.repo, kinds: [...pageOperations] }
|
|
21
|
+
: { owner: place.owner, repo: place.repo, number, kinds: [...pageOperations] },
|
|
22
|
+
),
|
|
23
23
|
),
|
|
24
24
|
staleTime: 30_000,
|
|
25
25
|
});
|
|
@@ -28,4 +28,4 @@ const none: ReadonlySet<PageOperation> = new Set();
|
|
|
28
28
|
|
|
29
29
|
/** Whether the viewer may make each operation: none until the answer comes, so no control flashes. */
|
|
30
30
|
export const useAllowed = (place: Place, number?: number) =>
|
|
31
|
-
useQuery(allowedHere(place, number)).data ?? none;
|
|
31
|
+
useQuery(allowedHere(useClients(), place, number)).data ?? none;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { queryOptions } from '@tanstack/react-query';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import type { Clients } from '../clients/clients.ts';
|
|
4
4
|
|
|
5
5
|
/** Where an `avatar_url` on the app's own upload route starts: the rest is the drop-in's default. */
|
|
6
6
|
const uploads = '/icons/';
|
|
@@ -39,11 +39,11 @@ export const picturesOf = (people: readonly Named[]): Pictures =>
|
|
|
39
39
|
* the app's route with its hash, or `null` for none, when the avatar draws DiceBear's. Read once a
|
|
40
40
|
* login and kept five minutes; a page that changes one sets it at once.
|
|
41
41
|
*/
|
|
42
|
-
export const avatarAt = (login: string) =>
|
|
42
|
+
export const avatarAt = (clients: Clients, login: string) =>
|
|
43
43
|
queryOptions({
|
|
44
44
|
queryKey: ['avatar', login.toLowerCase()],
|
|
45
45
|
queryFn: async () => {
|
|
46
|
-
const read = await github.GET('/users/{username}', {
|
|
46
|
+
const read = await clients.github.GET('/users/{username}', {
|
|
47
47
|
params: { path: { username: login } },
|
|
48
48
|
});
|
|
49
49
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { queryOptions, useQueries } from '@tanstack/react-query';
|
|
2
2
|
import * as Schema from 'effect/Schema';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { type Clients, useClients } from '../clients/clients.ts';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Each repo's open issues and open pull requests, as a list's rows show them (Q779): one GraphQL
|
|
@@ -63,7 +63,7 @@ const namesOf = (fullName: string) => {
|
|
|
63
63
|
* The counts of `fullNames`, a page of rows, by full name: one read, kept under the page's names.
|
|
64
64
|
* A repo the answer leaves `null` has no counts.
|
|
65
65
|
*/
|
|
66
|
-
export const openCounts = (fullNames: readonly string[]) =>
|
|
66
|
+
export const openCounts = (clients: Clients, fullNames: readonly string[]) =>
|
|
67
67
|
queryOptions({
|
|
68
68
|
queryKey: ['open-counts', ...fullNames],
|
|
69
69
|
queryFn: async (): Promise<ReadonlyMap<string, OpenCounts>> => {
|
|
@@ -79,7 +79,7 @@ export const openCounts = (fullNames: readonly string[]) =>
|
|
|
79
79
|
]),
|
|
80
80
|
);
|
|
81
81
|
|
|
82
|
-
const answer = await query(
|
|
82
|
+
const answer = await clients.query(
|
|
83
83
|
"The open counts didn't load",
|
|
84
84
|
countsOperation(named.length),
|
|
85
85
|
variables,
|
|
@@ -116,9 +116,10 @@ export const useOpenCounts = (
|
|
|
116
116
|
pages: readonly (readonly string[])[],
|
|
117
117
|
wanted: (page: readonly string[]) => boolean,
|
|
118
118
|
): ReadonlyMap<string, OpenCounts> => {
|
|
119
|
+
const clients = useClients();
|
|
119
120
|
const answers = useQueries({
|
|
120
121
|
queries: pages.map((page) => ({
|
|
121
|
-
...openCounts(page),
|
|
122
|
+
...openCounts(clients, page),
|
|
122
123
|
enabled: page.length > 0 && wanted(page),
|
|
123
124
|
})),
|
|
124
125
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { queryOptions, type QueryClient } from '@tanstack/react-query';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import type { Clients } from '../clients/clients.ts';
|
|
4
4
|
import { avatarAt, uploadOf } from './avatars.ts';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -52,16 +52,24 @@ const profileFailed = (status: number) => new Error(`The profile didn't load (${
|
|
|
52
52
|
* The picture a profile's read named, set in `avatarAt`, which owns every avatar's picture: the
|
|
53
53
|
* card's avatar reads it there, so a page that changes the picture changes the card's too.
|
|
54
54
|
*/
|
|
55
|
-
const pictured = (
|
|
56
|
-
|
|
55
|
+
const pictured = (
|
|
56
|
+
clients: Clients,
|
|
57
|
+
client: QueryClient,
|
|
58
|
+
login: string,
|
|
59
|
+
avatarUrl: string | null | undefined,
|
|
60
|
+
) => client.setQueryData(avatarAt(clients, login).queryKey, uploadOf(avatarUrl));
|
|
57
61
|
|
|
58
62
|
/** An org's profile, from `GET /orgs/{org}`. */
|
|
59
|
-
const orgProfile = async (
|
|
60
|
-
|
|
63
|
+
const orgProfile = async (
|
|
64
|
+
clients: Clients,
|
|
65
|
+
client: QueryClient,
|
|
66
|
+
login: string,
|
|
67
|
+
): Promise<Profile> => {
|
|
68
|
+
const read = await clients.github.GET('/orgs/{org}', { params: { path: { org: login } } });
|
|
61
69
|
if (read.data === undefined) throw profileFailed(read.response.status);
|
|
62
70
|
|
|
63
71
|
const org = read.data;
|
|
64
|
-
pictured(client, org.login, org.avatar_url);
|
|
72
|
+
pictured(clients, client, org.login, org.avatar_url);
|
|
65
73
|
|
|
66
74
|
return {
|
|
67
75
|
kind: 'org',
|
|
@@ -81,14 +89,20 @@ const orgProfile = async (client: QueryClient, login: string): Promise<Profile>
|
|
|
81
89
|
* A person's profile, from `GET /users/{login}`, or an org's, when that answers one: the starter's
|
|
82
90
|
* `/users/` answers an org's login too, and only `/orgs/` holds its description.
|
|
83
91
|
*/
|
|
84
|
-
const userProfile = async (
|
|
85
|
-
|
|
92
|
+
const userProfile = async (
|
|
93
|
+
clients: Clients,
|
|
94
|
+
client: QueryClient,
|
|
95
|
+
login: string,
|
|
96
|
+
): Promise<Profile> => {
|
|
97
|
+
const read = await clients.github.GET('/users/{username}', {
|
|
98
|
+
params: { path: { username: login } },
|
|
99
|
+
});
|
|
86
100
|
if (read.data === undefined) throw profileFailed(read.response.status);
|
|
87
101
|
|
|
88
102
|
const user = read.data;
|
|
89
|
-
if (user.type === 'Organization') return orgProfile(client, user.login);
|
|
103
|
+
if (user.type === 'Organization') return orgProfile(clients, client, user.login);
|
|
90
104
|
|
|
91
|
-
pictured(client, user.login, user.avatar_url);
|
|
105
|
+
pictured(clients, client, user.login, user.avatar_url);
|
|
92
106
|
|
|
93
107
|
return {
|
|
94
108
|
kind: 'user',
|
|
@@ -109,11 +123,11 @@ const userProfile = async (client: QueryClient, login: string): Promise<Profile>
|
|
|
109
123
|
* and kept for the session, so every card for one login reads it once. `org` reads `/orgs/` at
|
|
110
124
|
* once; a person, or a login whose kind the page doesn't know, reads `/users/` first.
|
|
111
125
|
*/
|
|
112
|
-
export const profileAt = (login: string, account: 'user' | 'org') =>
|
|
126
|
+
export const profileAt = (clients: Clients, login: string, account: 'user' | 'org') =>
|
|
113
127
|
queryOptions({
|
|
114
128
|
queryKey: ['profile', login.toLowerCase()],
|
|
115
129
|
queryFn: ({ client }) =>
|
|
116
|
-
account === 'org' ? orgProfile(client, login) : userProfile(client, login),
|
|
130
|
+
account === 'org' ? orgProfile(clients, client, login) : userProfile(clients, client, login),
|
|
117
131
|
staleTime: Infinity,
|
|
118
132
|
gcTime: Infinity,
|
|
119
133
|
retry: false,
|