ref0-git 0.14.0 → 0.25.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/generated/git-rest.ts +170 -3
- package/app/apps/github/generated/routeTree.gen.ts +42 -21
- package/app/apps/github/src/clients/host-calls.ts +59 -34
- package/app/apps/github/src/components/states/states.tsx +1 -19
- package/app/apps/github/src/components/view-tabs.tsx +6 -2
- package/app/apps/github/src/context/context.ts +7 -4
- package/app/apps/github/src/context/host.ts +72 -36
- package/app/apps/github/src/issues/issue-list.tsx +11 -3
- package/app/apps/github/src/issues/issues.ts +11 -8
- package/app/apps/github/src/lists/across-list.tsx +358 -0
- package/app/apps/github/src/lists/across.ts +239 -0
- package/app/apps/github/src/names/owners.ts +3 -1
- package/app/apps/github/src/palette/targets.ts +3 -2
- package/app/apps/github/src/policy.ts +23 -30
- package/app/apps/github/src/private-repos.ts +24 -24
- package/app/apps/github/src/pulls/pulls.ts +2 -1
- package/app/apps/github/src/routes/-nav.tsx +40 -12
- package/app/apps/github/src/routes/issues.tsx +15 -0
- package/app/apps/github/src/routes/orgs/$owner/-org-list.ts +31 -0
- package/app/apps/github/src/routes/orgs/$owner/issues.tsx +10 -3
- package/app/apps/github/src/routes/orgs/$owner/pulls.tsx +10 -3
- package/app/apps/github/src/routes/pulls.tsx +15 -0
- package/app/apps/github/src/seed/seed.ts +104 -52
- package/app/apps/github/src/server.ts +17 -7
- package/app/apps/github/src/signin/approval.ts +24 -16
- package/app/apps/github/src/signin/attempts.ts +1 -1
- package/app/apps/github/src/signin/auth.ts +27 -19
- package/app/apps/github/src/signin/device-prompt.ts +1 -2
- package/app/apps/github/src/signin/revoke.ts +9 -17
- package/app/apps/github/src/signin/unborn.ts +33 -20
- package/app/pnpm-workspace.yaml +2 -2
- package/dist/cli/setup.mjs +3 -3
- package/dist/cli/sign-in.mjs +2 -3
- package/dist/init/app.mjs +5 -4
- package/dist/init/cloudflare.mjs +14 -8
- package/dist/init/create.mjs +1 -1
- package/dist/init/git-module.mjs +13 -5
- package/dist/init/metadata.mjs +1 -1
- package/dist/init/node.mjs +1 -1
- package/dist/init/stores.mjs +1 -1
- package/dist/init/template.mjs +3 -0
- package/dist/init/templates.mjs +34 -21
- package/dist/init/versions.mjs +1 -1
- package/package.json +5 -5
- package/app/apps/github/src/routes/orgs/$owner/releases.tsx +0 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Caller, InternalRepoId, Policy,
|
|
1
|
+
import type { Caller, InternalRepoId, Policy, Repos, Result, Tokens } from '@ref0/git';
|
|
2
2
|
import type { GitHubAuthorize, RepoRole } from '@ref0/github';
|
|
3
3
|
import type {} from '@tanstack/react-start';
|
|
4
4
|
|
|
@@ -176,10 +176,13 @@ export interface ImageSigner {
|
|
|
176
176
|
readonly sign: (urls: readonly string[]) => Promise<ReadonlyMap<string, string>>;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
/**
|
|
179
|
+
/**
|
|
180
|
+
* Git's direct calls a host call reads with, as host code, each an Effect on Git's services, which
|
|
181
|
+
* the server function runs at its edge.
|
|
182
|
+
*/
|
|
180
183
|
export interface HostGit {
|
|
181
|
-
readonly repos: Pick<
|
|
182
|
-
readonly tokens?: Pick<
|
|
184
|
+
readonly repos: Pick<Repos.Repos['Service'], 'list'>;
|
|
185
|
+
readonly tokens?: Pick<Tokens.Tokens['Service'], 'list'> | undefined;
|
|
183
186
|
}
|
|
184
187
|
|
|
185
188
|
declare module '@tanstack/react-start' {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Auth, Git, Objects, Policy, RepoRecords, Repos, Rules, Tokens } from '@ref0/git';
|
|
2
|
-
import type { GitError,
|
|
3
|
-
import { JoinedCalls } from '@ref0/git/extend';
|
|
1
|
+
import { Auth, Git, gitError, Objects, Policy, RepoRecords, Repos, Rules, Tokens } from '@ref0/git';
|
|
2
|
+
import type { GitError, InternalRepoId, PushRule, RepoName } from '@ref0/git';
|
|
4
3
|
import { GitHubPolicy, People } from '@ref0/github';
|
|
5
4
|
import type { GitHubAuthorize, PeopleFor } from '@ref0/github';
|
|
5
|
+
import type { HostRuntime } from '@ref0/infra';
|
|
6
|
+
import * as Context from 'effect/Context';
|
|
6
7
|
import * as Effect from 'effect/Effect';
|
|
7
8
|
import * as Exit from 'effect/Exit';
|
|
8
9
|
import * as Layer from 'effect/Layer';
|
|
9
|
-
import type * as ManagedRuntime from 'effect/ManagedRuntime';
|
|
10
10
|
import * as Option from 'effect/Option';
|
|
11
11
|
|
|
12
12
|
/** The host's say, which the starter's Git is made with: who calls, what they may do, and its push rules. */
|
|
@@ -22,12 +22,28 @@ export interface HostParts {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
25
|
+
* Git's `Repos` as the host's own calls, each made as `Git.host`, as Git's host calls are: the
|
|
26
|
+
* directory's lookups read every repo, and ask no policy.
|
|
27
|
+
*/
|
|
28
|
+
const hostRepos = (repos: Repos.Repos['Service']): Parameters<PeopleFor>[0]['git']['repos'] => ({
|
|
29
|
+
create: (input) => repos.create(input, Git.host),
|
|
30
|
+
get: (repo, input) => repos.get(repo, input, Git.host),
|
|
31
|
+
importState: (repo, input) => repos.importState(repo, input, Git.host),
|
|
32
|
+
list: (input) => repos.list(input, Git.host),
|
|
33
|
+
update: (repo, input) => repos.update(repo, input, Git.host),
|
|
34
|
+
rename: (repo, input) => repos.rename(repo, input, Git.host),
|
|
35
|
+
delete: (repo, input) => repos.delete(repo, input, Git.host),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The host's directory as the drop-in's `People`, made over Git's `Repos` as the host's own calls,
|
|
40
|
+
* which its own lookups don't list through.
|
|
27
41
|
*/
|
|
28
42
|
export const peopleOver = (people: PeopleFor) =>
|
|
29
43
|
People.layer(
|
|
30
|
-
Effect.map(Effect.service(
|
|
44
|
+
Effect.map(Effect.service(Repos.Repos), (repos) =>
|
|
45
|
+
people({ git: { repos: hostRepos(repos) } }),
|
|
46
|
+
),
|
|
31
47
|
);
|
|
32
48
|
|
|
33
49
|
/**
|
|
@@ -67,9 +83,10 @@ export const hostLayer = <A, E, O, OE, OR, F, FE, FR>(
|
|
|
67
83
|
/**
|
|
68
84
|
* Git's routes on `runtime`, the drop-in's among them, as the server's ingress reads them: `route`
|
|
69
85
|
* answers `undefined` for a URL none owns, and `fetch` answers it Git's JSON `404`. Neither
|
|
70
|
-
* rejects: a runtime whose build failed answers `fetch`'s refusal
|
|
86
|
+
* rejects: a runtime whose build failed answers `fetch`'s refusal, `starting` while it waits to
|
|
87
|
+
* build again.
|
|
71
88
|
*/
|
|
72
|
-
export const routeOn = <E>(runtime:
|
|
89
|
+
export const routeOn = <E>(runtime: HostRuntime.HostRuntime<Git.Git, E>) => {
|
|
73
90
|
const fetch = Git.toFetch(runtime);
|
|
74
91
|
|
|
75
92
|
const route = async (request: Request) => {
|
|
@@ -81,35 +98,54 @@ export const routeOn = <E>(runtime: ManagedRuntime.ManagedRuntime<Git.Git, E>) =
|
|
|
81
98
|
return { route, fetch };
|
|
82
99
|
};
|
|
83
100
|
|
|
84
|
-
/**
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
101
|
+
/**
|
|
102
|
+
* An Effect on the host's services, in the caller's own fiber: its store calls count on the
|
|
103
|
+
* caller's request, and interrupting the caller stops it. A failed build answers `UNAVAILABLE`.
|
|
104
|
+
*/
|
|
105
|
+
export type OnHost = <A, E>(
|
|
106
|
+
effect: Effect.Effect<A, E, HostServices>,
|
|
107
|
+
) => Effect.Effect<A, E | GitError>;
|
|
89
108
|
|
|
90
|
-
/**
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
109
|
+
/**
|
|
110
|
+
* `OnHost` over the services `runtime` built, which it reads at each call, so a policy made
|
|
111
|
+
* before its runtime can hold it. Only `HostServices` are provided: the caller's own, its
|
|
112
|
+
* request's count among them, stay.
|
|
113
|
+
*/
|
|
114
|
+
export const onHost =
|
|
115
|
+
(
|
|
116
|
+
runtime: () => {
|
|
117
|
+
readonly contextEffect: Effect.Effect<Context.Context<HostServices>, unknown>;
|
|
118
|
+
},
|
|
119
|
+
): OnHost =>
|
|
120
|
+
(effect) =>
|
|
121
|
+
Effect.flatMap(
|
|
122
|
+
Effect.mapError(
|
|
123
|
+
Effect.suspend(() => runtime().contextEffect),
|
|
124
|
+
() => gitError('UNAVAILABLE', "Git's host isn't built", { hint: 'Try again' }),
|
|
125
|
+
),
|
|
126
|
+
(built) =>
|
|
127
|
+
Effect.provide(
|
|
128
|
+
effect,
|
|
129
|
+
Context.pick(Git.Git, Tokens.Tokens, Repos.Repos, RepoRecords.RepoRecords)(built),
|
|
130
|
+
),
|
|
100
131
|
);
|
|
101
132
|
|
|
102
|
-
/** Git's own tokens
|
|
103
|
-
export const
|
|
104
|
-
create: (target, input) =>
|
|
105
|
-
list: (target, input) =>
|
|
106
|
-
get: (token, input) =>
|
|
107
|
-
revoke: (token, input) =>
|
|
108
|
-
revokeKey: (target, key, input) =>
|
|
133
|
+
/** Git's own tokens over `host`, each call an Effect: Better Auth's sessions mint theirs here. */
|
|
134
|
+
export const tokensOn = (host: OnHost): Tokens.Tokens['Service'] => ({
|
|
135
|
+
create: (target, input) => host(Tokens.create(target, input)),
|
|
136
|
+
list: (target, input) => host(Tokens.list(target, input)),
|
|
137
|
+
get: (token, input) => host(Tokens.get(token, input)),
|
|
138
|
+
revoke: (token, input) => host(Tokens.revoke(token, input)),
|
|
139
|
+
revokeKey: (target, key, input) => host(Tokens.revokeKey(target, key, input)),
|
|
109
140
|
});
|
|
110
141
|
|
|
111
|
-
/**
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
142
|
+
/**
|
|
143
|
+
* What the policy reads of Git's repo records over `host`: the name a repo's internal ID holds
|
|
144
|
+
* now, and the internal ID a name holds now, `undefined` for none.
|
|
145
|
+
*/
|
|
146
|
+
export const repoRecordsOn = (host: OnHost) => ({
|
|
147
|
+
repoName: (internalId: InternalRepoId) =>
|
|
148
|
+
host(Effect.map(RepoRecords.record(internalId), (record) => record?.name)),
|
|
149
|
+
repoId: (name: RepoName) =>
|
|
150
|
+
host(Effect.map(RepoRecords.pin(name), (pinned) => pinned?.internalId)),
|
|
151
|
+
});
|
|
@@ -16,7 +16,7 @@ import { cn } from '#/lib/cn';
|
|
|
16
16
|
|
|
17
17
|
import { day, Go, usePreloaded } from '../code/controls.tsx';
|
|
18
18
|
import { useClients } from '../clients/clients.ts';
|
|
19
|
-
import type
|
|
19
|
+
import { repoHref, type RepoPlace } from '../code/places.ts';
|
|
20
20
|
import { ItemList, More } from '../components/item-list.tsx';
|
|
21
21
|
import { OwnerCard } from '../components/owner-card.tsx';
|
|
22
22
|
import { UserAvatar } from '../components/user-avatar.tsx';
|
|
@@ -71,18 +71,21 @@ export const issueHref = (place: RepoPlace, number: number) =>
|
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* An issue's or a pull request's row: `icon` for its state, its title, labels, and who opened it
|
|
74
|
-
* when, and `note` after that, such as "Draft".
|
|
74
|
+
* when, and `note` after that, such as "Draft". In a list across repos, `repo` names its repo
|
|
75
|
+
* before its title, as GitHub's own lists do.
|
|
75
76
|
*/
|
|
76
77
|
export function IssueRow({
|
|
77
78
|
href,
|
|
78
79
|
icon,
|
|
79
80
|
issue,
|
|
80
81
|
note,
|
|
82
|
+
repo,
|
|
81
83
|
}: {
|
|
82
84
|
readonly href: string;
|
|
83
85
|
readonly icon: ReactNode;
|
|
84
86
|
readonly issue: Issue;
|
|
85
87
|
readonly note?: string;
|
|
88
|
+
readonly repo?: RepoPlace;
|
|
86
89
|
}) {
|
|
87
90
|
const comments = `${issue.comments} ${issue.comments === 1 ? 'comment' : 'comments'}`;
|
|
88
91
|
|
|
@@ -91,6 +94,11 @@ export function IssueRow({
|
|
|
91
94
|
<ItemMedia>{icon}</ItemMedia>
|
|
92
95
|
<ItemContent className="min-w-0">
|
|
93
96
|
<ItemTitle className="line-clamp-none flex max-w-full flex-wrap gap-1.5 text-sm/6 font-semibold sm:text-base/6 wrap-anywhere">
|
|
97
|
+
{repo !== undefined && (
|
|
98
|
+
<Go href={repoHref(repo)} className="font-normal text-muted-foreground hover:underline">
|
|
99
|
+
{repo.owner}/{repo.repo}
|
|
100
|
+
</Go>
|
|
101
|
+
)}
|
|
94
102
|
<Go href={href} className="hover:underline">
|
|
95
103
|
{issue.title}
|
|
96
104
|
</Go>
|
|
@@ -136,7 +144,7 @@ export function IssueRow({
|
|
|
136
144
|
}
|
|
137
145
|
|
|
138
146
|
/** An issue's state, as its row's icon: open in green, closed in purple. */
|
|
139
|
-
function IssueIcon({ issue }: { readonly issue: Issue }) {
|
|
147
|
+
export function IssueIcon({ issue }: { readonly issue: Issue }) {
|
|
140
148
|
const open = issue.state === 'open';
|
|
141
149
|
const Icon = open ? CircleDotIcon : CircleCheckIcon;
|
|
142
150
|
|
|
@@ -235,10 +235,13 @@ export type Listed = IssueFields & {
|
|
|
235
235
|
readonly pull_request?: { readonly merged_at?: string | null };
|
|
236
236
|
};
|
|
237
237
|
|
|
238
|
-
/**
|
|
239
|
-
|
|
238
|
+
/**
|
|
239
|
+
* A page a list reads, from `after`: what it lists, and where the next page starts. A list across
|
|
240
|
+
* repos reads items that carry their repo's URL too.
|
|
241
|
+
*/
|
|
242
|
+
export type Lister<Item extends Listed = Listed> = (
|
|
240
243
|
after: string | undefined,
|
|
241
|
-
) => Promise<{ readonly listed: readonly
|
|
244
|
+
) => Promise<{ readonly listed: readonly Item[]; readonly next: string | undefined }>;
|
|
242
245
|
|
|
243
246
|
/** The repo's issue list under `query`, a page from `after`, the drop-in's cursor. */
|
|
244
247
|
export const listedBy =
|
|
@@ -274,8 +277,8 @@ export const searchedBy =
|
|
|
274
277
|
};
|
|
275
278
|
|
|
276
279
|
/** How a list reads on: what it keeps of each page, and up to how many pages. */
|
|
277
|
-
export interface Reading<Row> {
|
|
278
|
-
readonly keep: (listed: readonly
|
|
280
|
+
export interface Reading<Row, Item extends Listed = Listed> {
|
|
281
|
+
readonly keep: (listed: readonly Item[]) => Promise<readonly Row[]>;
|
|
279
282
|
readonly reads: number;
|
|
280
283
|
}
|
|
281
284
|
|
|
@@ -284,10 +287,10 @@ export interface Reading<Row> {
|
|
|
284
287
|
* page `keep` makes no rows of reads on to the next, so no page shows nothing while more is
|
|
285
288
|
* left, up to `reads` pages.
|
|
286
289
|
*/
|
|
287
|
-
export const readOn = async <Row>(
|
|
288
|
-
lister: Lister
|
|
290
|
+
export const readOn = async <Row, Item extends Listed = Listed>(
|
|
291
|
+
lister: Lister<Item>,
|
|
289
292
|
after: string | undefined,
|
|
290
|
-
{ keep, reads }: Reading<Row>,
|
|
293
|
+
{ keep, reads }: Reading<Row, Item>,
|
|
291
294
|
): Promise<{ readonly rows: readonly Row[]; readonly next: string | undefined }> => {
|
|
292
295
|
let cursor = after;
|
|
293
296
|
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
2
|
+
import { CircleDotIcon, GitPullRequestIcon, InfoIcon, type LucideIcon } from 'lucide-react';
|
|
3
|
+
import type { ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
import { cn } from '#/lib/cn';
|
|
6
|
+
|
|
7
|
+
import { useClients } from '../clients/clients.ts';
|
|
8
|
+
import { Go } from '../code/controls.tsx';
|
|
9
|
+
import { Count } from '../components/count.tsx';
|
|
10
|
+
import { ItemList, More } from '../components/item-list.tsx';
|
|
11
|
+
import { pullStatuses } from '../components/pull-status.tsx';
|
|
12
|
+
import {
|
|
13
|
+
Empty,
|
|
14
|
+
EmptyDescription,
|
|
15
|
+
EmptyHeader,
|
|
16
|
+
EmptyMedia,
|
|
17
|
+
EmptyTitle,
|
|
18
|
+
} from '../components/ui/empty.tsx';
|
|
19
|
+
import { Skeleton } from '../components/ui/skeleton.tsx';
|
|
20
|
+
import { Tabs } from '../components/ui/tabs.tsx';
|
|
21
|
+
import { ViewTabs } from '../components/view-tabs.tsx';
|
|
22
|
+
import { IssueIcon, IssueRow, issueHref, LoadAlert, NoneMatched } from '../issues/issue-list.tsx';
|
|
23
|
+
import { pullHref } from '../pulls/pull-list.tsx';
|
|
24
|
+
import { statusOf } from '../pulls/pulls.ts';
|
|
25
|
+
import { SignedOut } from '../components/states/states.tsx';
|
|
26
|
+
import {
|
|
27
|
+
type AcrossPage,
|
|
28
|
+
type AcrossRow,
|
|
29
|
+
type IssueFilterName,
|
|
30
|
+
issueFilters,
|
|
31
|
+
orgList,
|
|
32
|
+
pullFilters,
|
|
33
|
+
yourHref,
|
|
34
|
+
type YourFilter,
|
|
35
|
+
yourIssues,
|
|
36
|
+
yourPulls,
|
|
37
|
+
} from './across.ts';
|
|
38
|
+
|
|
39
|
+
/** A list across repos as `useInfiniteQuery` takes it, such as `yourIssues`' or `orgList`'s. */
|
|
40
|
+
type AcrossQuery = ReturnType<typeof orgList>;
|
|
41
|
+
|
|
42
|
+
/** A row of a list across repos: its repo's name, then the issue's or pull request's own row. */
|
|
43
|
+
function AcrossItem({ row }: { readonly row: AcrossRow }) {
|
|
44
|
+
if (row.kind === 'issue') {
|
|
45
|
+
return (
|
|
46
|
+
<IssueRow
|
|
47
|
+
href={issueHref(row.place, row.issue.number)}
|
|
48
|
+
icon={<IssueIcon issue={row.issue} />}
|
|
49
|
+
issue={row.issue}
|
|
50
|
+
repo={row.place}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const status = statusOf(row.issue);
|
|
56
|
+
const { Icon, name, tone } = pullStatuses[status];
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<IssueRow
|
|
60
|
+
href={pullHref(row.place, row.issue.number)}
|
|
61
|
+
icon={<Icon aria-label={name} className={cn('size-5', tone)} />}
|
|
62
|
+
issue={row.issue}
|
|
63
|
+
repo={row.place}
|
|
64
|
+
{...(status === 'draft' ? { note: name } : {})}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The line over a list whose search read only part of what it could: the drop-in's search of a
|
|
71
|
+
* person's involvement reads at most its 20 repos a page, the most recently active first.
|
|
72
|
+
*/
|
|
73
|
+
export function SomeMissing() {
|
|
74
|
+
return (
|
|
75
|
+
<p className="flex items-center gap-2 border-b px-3 py-2 text-sm text-muted-foreground sm:px-4">
|
|
76
|
+
<InfoIcon aria-hidden className="size-4 shrink-0" />
|
|
77
|
+
Some results may be missing: this search reads your 20 most recently active repositories
|
|
78
|
+
</p>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** What a list across repos says with nothing in it. */
|
|
83
|
+
export interface Nothing {
|
|
84
|
+
readonly kind: AcrossRow['kind'];
|
|
85
|
+
readonly title: string;
|
|
86
|
+
readonly description: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Each kind's icon, for a list with nothing in it. */
|
|
90
|
+
const emptyIcons: Readonly<Record<AcrossRow['kind'], LucideIcon>> = {
|
|
91
|
+
issue: CircleDotIcon,
|
|
92
|
+
pull: GitPullRequestIcon,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
function NothingHere({ nothing }: { readonly nothing: Nothing }) {
|
|
96
|
+
const Icon = emptyIcons[nothing.kind];
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<Empty>
|
|
100
|
+
<EmptyHeader>
|
|
101
|
+
<EmptyMedia variant="icon">
|
|
102
|
+
<Icon />
|
|
103
|
+
</EmptyMedia>
|
|
104
|
+
<EmptyTitle>{nothing.title}</EmptyTitle>
|
|
105
|
+
<EmptyDescription>{nothing.description}</EmptyDescription>
|
|
106
|
+
</EmptyHeader>
|
|
107
|
+
</Empty>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* A list across repos, a page at a time as the reader asks for more, each row naming its repo.
|
|
113
|
+
* A page that kept nothing while more is left says so and offers more, never that there's none.
|
|
114
|
+
*/
|
|
115
|
+
export function AcrossList({
|
|
116
|
+
list,
|
|
117
|
+
label,
|
|
118
|
+
more,
|
|
119
|
+
nothing,
|
|
120
|
+
}: {
|
|
121
|
+
readonly list: AcrossQuery;
|
|
122
|
+
readonly label: string;
|
|
123
|
+
readonly more: string;
|
|
124
|
+
readonly nothing: Nothing;
|
|
125
|
+
}) {
|
|
126
|
+
const pages = useInfiniteQuery(list);
|
|
127
|
+
const loaded: readonly AcrossPage[] = pages.data?.pages ?? [];
|
|
128
|
+
const rows = loaded.flatMap((page) => page.rows);
|
|
129
|
+
if (pages.isPending) return <Skeleton className="h-40" />;
|
|
130
|
+
|
|
131
|
+
if (pages.error !== null && rows.length === 0) return <LoadAlert message={pages.error.message} />;
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<>
|
|
135
|
+
{loaded.some((page) => page.incomplete) && <SomeMissing />}
|
|
136
|
+
{rows.length === 0 ? (
|
|
137
|
+
pages.hasNextPage ? (
|
|
138
|
+
<NoneMatched more />
|
|
139
|
+
) : (
|
|
140
|
+
<NothingHere nothing={nothing} />
|
|
141
|
+
)
|
|
142
|
+
) : (
|
|
143
|
+
<ItemList
|
|
144
|
+
aria-label={label}
|
|
145
|
+
rows={rows}
|
|
146
|
+
keyOf={(row) => `${row.place.owner}/${row.place.repo}#${row.issue.number}`}
|
|
147
|
+
row={(row) => <AcrossItem row={row} />}
|
|
148
|
+
/>
|
|
149
|
+
)}
|
|
150
|
+
<More pages={pages} label={more} />
|
|
151
|
+
</>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Each filter's tab name, as GitHub's own lists across repos name them. */
|
|
156
|
+
const filterNames: Readonly<Record<YourFilter, string>> = {
|
|
157
|
+
created: 'Created',
|
|
158
|
+
assigned: 'Assigned',
|
|
159
|
+
mentioned: 'Mentioned',
|
|
160
|
+
'review-requested': 'Review requests',
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Your issues' or Your pull requests' page: the filter tabs, each a link to its own page at
|
|
165
|
+
* `path`, the one shown raised with the count of the rows `list` has read, `+` while more is
|
|
166
|
+
* left, over `children`, the list.
|
|
167
|
+
*/
|
|
168
|
+
export function YourList({
|
|
169
|
+
path,
|
|
170
|
+
filters,
|
|
171
|
+
filter,
|
|
172
|
+
list,
|
|
173
|
+
label,
|
|
174
|
+
children,
|
|
175
|
+
}: {
|
|
176
|
+
readonly path: string;
|
|
177
|
+
readonly filters: readonly YourFilter[];
|
|
178
|
+
readonly filter: YourFilter;
|
|
179
|
+
readonly list: AcrossQuery;
|
|
180
|
+
readonly label: string;
|
|
181
|
+
readonly children: ReactNode;
|
|
182
|
+
}) {
|
|
183
|
+
const pages = useInfiniteQuery(list);
|
|
184
|
+
const read = pages.data?.pages.reduce((rows, page) => rows + page.rows.length, 0);
|
|
185
|
+
const count = read === undefined ? undefined : <Count value={read} more={pages.hasNextPage} />;
|
|
186
|
+
|
|
187
|
+
return (
|
|
188
|
+
<section aria-label={label} className="border">
|
|
189
|
+
<div className="flex flex-wrap items-center gap-2 border-b bg-muted/50 px-3 py-1.5">
|
|
190
|
+
<Tabs value={filter}>
|
|
191
|
+
<ViewTabs
|
|
192
|
+
label="Filter"
|
|
193
|
+
views={filters.map((each) => ({
|
|
194
|
+
value: each,
|
|
195
|
+
label: filterNames[each],
|
|
196
|
+
link: <Go href={yourHref(path, filters, each)} />,
|
|
197
|
+
end: each === filter ? count : undefined,
|
|
198
|
+
}))}
|
|
199
|
+
/>
|
|
200
|
+
</Tabs>
|
|
201
|
+
</div>
|
|
202
|
+
{children}
|
|
203
|
+
</section>
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** What an org's tab calls its list, its button for more, and what it lists. */
|
|
208
|
+
interface OrgWords {
|
|
209
|
+
readonly label: string;
|
|
210
|
+
readonly more: string;
|
|
211
|
+
readonly what: string;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Each kind's words on an org's tab. */
|
|
215
|
+
const orgWords: Readonly<Record<AcrossRow['kind'], OrgWords>> = {
|
|
216
|
+
issue: { label: 'Issues', more: 'More issues', what: 'issues' },
|
|
217
|
+
pull: { label: 'Pull requests', more: 'More pull requests', what: 'pull requests' },
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
/** Each kind's path on an org's level, under `/orgs/{org}/`. */
|
|
221
|
+
const orgPaths: Readonly<Record<AcrossRow['kind'], string>> = { issue: 'issues', pull: 'pulls' };
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* An org's Issues or Pull requests tab: its open ones in every repo of its the viewer may read,
|
|
225
|
+
* or, for a visitor, a sign-in, since `/orgs/{org}/issues` answers only someone signed in.
|
|
226
|
+
*/
|
|
227
|
+
export function OrgTab({
|
|
228
|
+
signedIn,
|
|
229
|
+
org,
|
|
230
|
+
kind,
|
|
231
|
+
}: {
|
|
232
|
+
readonly signedIn: boolean;
|
|
233
|
+
readonly org: string;
|
|
234
|
+
readonly kind: AcrossRow['kind'];
|
|
235
|
+
}) {
|
|
236
|
+
const clients = useClients();
|
|
237
|
+
const { label, more, what } = orgWords[kind];
|
|
238
|
+
|
|
239
|
+
if (!signedIn) {
|
|
240
|
+
return (
|
|
241
|
+
<SignedOut
|
|
242
|
+
returnTo={`/orgs/${encodeURIComponent(org)}/${orgPaths[kind]}`}
|
|
243
|
+
what={`${org}'s ${what}`}
|
|
244
|
+
/>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return (
|
|
249
|
+
<section aria-label={label} className="border">
|
|
250
|
+
<AcrossList
|
|
251
|
+
list={orgList(clients, org, kind)}
|
|
252
|
+
label={label}
|
|
253
|
+
more={more}
|
|
254
|
+
nothing={{
|
|
255
|
+
kind,
|
|
256
|
+
title: `No open ${what} in ${org}`,
|
|
257
|
+
description: `Open ${what} in ${org}'s repositories you can read come here.`,
|
|
258
|
+
}}
|
|
259
|
+
/>
|
|
260
|
+
</section>
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Your issues' words for none, under each filter. */
|
|
265
|
+
const noIssues: Readonly<Record<IssueFilterName, string>> = {
|
|
266
|
+
created: 'No open issues created by you',
|
|
267
|
+
assigned: 'No open issues assigned to you',
|
|
268
|
+
mentioned: 'No open issues mentioning you',
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Your issues: the signed-in viewer's open issues across every repo they may read, created by
|
|
273
|
+
* them, assigned to them or mentioning them; a visitor's is a sign-in.
|
|
274
|
+
*/
|
|
275
|
+
export function YourIssues({
|
|
276
|
+
signedIn,
|
|
277
|
+
filter,
|
|
278
|
+
}: {
|
|
279
|
+
readonly signedIn: boolean;
|
|
280
|
+
readonly filter: IssueFilterName;
|
|
281
|
+
}) {
|
|
282
|
+
const clients = useClients();
|
|
283
|
+
|
|
284
|
+
if (!signedIn) {
|
|
285
|
+
return <SignedOut returnTo={yourHref('/issues', issueFilters, filter)} what="your issues" />;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const list = yourIssues(clients, filter);
|
|
289
|
+
|
|
290
|
+
return (
|
|
291
|
+
<YourList path="/issues" filters={issueFilters} filter={filter} list={list} label="Your issues">
|
|
292
|
+
<AcrossList
|
|
293
|
+
key={filter}
|
|
294
|
+
list={list}
|
|
295
|
+
label="Issues"
|
|
296
|
+
more="More issues"
|
|
297
|
+
nothing={{
|
|
298
|
+
kind: 'issue',
|
|
299
|
+
title: noIssues[filter],
|
|
300
|
+
description: 'Issues in every repository you can read come here.',
|
|
301
|
+
}}
|
|
302
|
+
/>
|
|
303
|
+
</YourList>
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** Your pull requests' words for none, under each filter. */
|
|
308
|
+
const noPulls: Readonly<Record<YourFilter, string>> = {
|
|
309
|
+
created: 'No open pull requests created by you',
|
|
310
|
+
assigned: 'No open pull requests assigned to you',
|
|
311
|
+
mentioned: 'No open pull requests mentioning you',
|
|
312
|
+
'review-requested': 'No open pull requests asking for your review',
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Your pull requests: the signed-in viewer's open pull requests across every repo they may read,
|
|
317
|
+
* created by them, assigned to them, mentioning them or asking for their review; a visitor's is a
|
|
318
|
+
* sign-in.
|
|
319
|
+
*/
|
|
320
|
+
export function YourPulls({
|
|
321
|
+
signedIn,
|
|
322
|
+
filter,
|
|
323
|
+
}: {
|
|
324
|
+
readonly signedIn: boolean;
|
|
325
|
+
readonly filter: YourFilter;
|
|
326
|
+
}) {
|
|
327
|
+
const clients = useClients();
|
|
328
|
+
|
|
329
|
+
if (!signedIn) {
|
|
330
|
+
return (
|
|
331
|
+
<SignedOut returnTo={yourHref('/pulls', pullFilters, filter)} what="your pull requests" />
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const list = yourPulls(clients, filter);
|
|
336
|
+
|
|
337
|
+
return (
|
|
338
|
+
<YourList
|
|
339
|
+
path="/pulls"
|
|
340
|
+
filters={pullFilters}
|
|
341
|
+
filter={filter}
|
|
342
|
+
list={list}
|
|
343
|
+
label="Your pull requests"
|
|
344
|
+
>
|
|
345
|
+
<AcrossList
|
|
346
|
+
key={filter}
|
|
347
|
+
list={list}
|
|
348
|
+
label="Pull requests"
|
|
349
|
+
more="More pull requests"
|
|
350
|
+
nothing={{
|
|
351
|
+
kind: 'pull',
|
|
352
|
+
title: noPulls[filter],
|
|
353
|
+
description: 'Pull requests in every repository you can read come here.',
|
|
354
|
+
}}
|
|
355
|
+
/>
|
|
356
|
+
</YourList>
|
|
357
|
+
);
|
|
358
|
+
}
|