+2
-1
biome.json
+2
-1
biome.json
+10
-14
src/routes/repo/blob.tsx
+10
-14
src/routes/repo/blob.tsx
···
4
useNavigate,
5
useParams,
6
} from "@solidjs/router";
7
-
import { Show, Suspense } from "solid-js";
8
import { CodeBlock } from "../../elements/code_block";
9
import { getLanguage } from "../../util/get_language";
10
import { useDid } from "./context";
11
import { Header } from "./main";
12
import { getRepoBlob } from "./main.data";
13
-
import { figureOutDid } from "../../util/handle";
14
15
export async function preloadRepoBlob({ params }: { params: Params }) {
16
-
const did = await figureOutDid(params.user)
17
if (!did) return;
18
getRepoBlob(did, params.repo, params.ref, params.path);
19
}
···
40
41
return (
42
<div class="mx-auto max-w-5xl">
43
-
<Show when={did()}>
44
-
{(did) => <Header did={did()} user={params.user} repo={params.repo} />}
45
-
</Show>
46
-
<Suspense>
47
<Show when={blob()} keyed>
48
{(data) => (
49
-
<div class="flex flex-col rounded bg-white dark:bg-gray-800">
50
-
<CodeBlock
51
-
code={data.content}
52
-
language={getLanguage(data.path.split("/").pop()) || "text"}
53
-
/>
54
-
</div>
55
)}
56
</Show>
57
-
</Suspense>
58
</div>
59
);
60
}
···
4
useNavigate,
5
useParams,
6
} from "@solidjs/router";
7
+
import { Show } from "solid-js";
8
import { CodeBlock } from "../../elements/code_block";
9
import { getLanguage } from "../../util/get_language";
10
+
import { figureOutDid } from "../../util/handle";
11
import { useDid } from "./context";
12
import { Header } from "./main";
13
import { getRepoBlob } from "./main.data";
14
15
export async function preloadRepoBlob({ params }: { params: Params }) {
16
+
const did = await figureOutDid(params.user);
17
if (!did) return;
18
getRepoBlob(did, params.repo, params.ref, params.path);
19
}
···
40
41
return (
42
<div class="mx-auto max-w-5xl">
43
+
<Header user={params.user} repo={params.repo} />
44
+
<div class="flex flex-col rounded bg-white dark:bg-gray-800">
45
<Show when={blob()} keyed>
46
{(data) => (
47
+
<CodeBlock
48
+
code={data.content}
49
+
language={getLanguage(data.path.split("/").pop()) || "text"}
50
+
/>
51
)}
52
</Show>
53
+
</div>
54
</div>
55
);
56
}
+4
-8
src/routes/repo/commit/commit.tsx
+4
-8
src/routes/repo/commit/commit.tsx
···
237
}
238
239
function CommitHeader(props: {
240
-
did: DID;
241
user: string;
242
repo: string;
243
message: { title: string; content: string };
···
245
}) {
246
return (
247
<div>
248
-
<Header did={props.did} user={props.user} repo={props.repo} />
249
<div class="mx-1 flex flex-col gap-2 rounded bg-white p-4 dark:bg-gray-800">
250
<div>{props.message.title}</div>
251
<Show when={props.message.content}>
···
310
311
const headerData = createMemo(() => {
312
const c = commit();
313
-
const d = did();
314
-
315
-
if (!(c && d)) return;
316
317
const titleEnd = c.diff.commit.message.indexOf("\n");
318
const message = {
···
320
content: c.diff.commit.message.slice(titleEnd + 1),
321
};
322
323
-
return [c, d, message] as const;
324
});
325
326
onMount(() => {
···
335
<div class="mx-auto max-w-10xl">
336
<Suspense>
337
<Show when={headerData()} keyed>
338
-
{([commit, did, message]) => (
339
<CommitHeader
340
-
did={did}
341
user={params.user}
342
repo={params.repo}
343
message={message}
···
237
}
238
239
function CommitHeader(props: {
240
user: string;
241
repo: string;
242
message: { title: string; content: string };
···
244
}) {
245
return (
246
<div>
247
+
<Header user={props.user} repo={props.repo} />
248
<div class="mx-1 flex flex-col gap-2 rounded bg-white p-4 dark:bg-gray-800">
249
<div>{props.message.title}</div>
250
<Show when={props.message.content}>
···
309
310
const headerData = createMemo(() => {
311
const c = commit();
312
+
if (!c) return;
313
314
const titleEnd = c.diff.commit.message.indexOf("\n");
315
const message = {
···
317
content: c.diff.commit.message.slice(titleEnd + 1),
318
};
319
320
+
return [c, message] as const;
321
});
322
323
onMount(() => {
···
332
<div class="mx-auto max-w-10xl">
333
<Suspense>
334
<Show when={headerData()} keyed>
335
+
{([commit, message]) => (
336
<CommitHeader
337
user={params.user}
338
repo={params.repo}
339
message={message}
+1
-2
src/routes/repo/main.tsx
+1
-2
src/routes/repo/main.tsx
···
1
import { type Accessor, createMemo, Show } from "solid-js";
2
-
import type { DID } from "../../util/types";
3
import { useRepoInfo } from "./context";
4
5
function HeaderItem(props: {
···
19
);
20
}
21
22
-
export function Header(props: { did: DID; user: string; repo: string }) {
23
const repoInfo = useRepoInfo();
24
const path = createMemo(() => {
25
const path = window.location.pathname.split("/")[3];
···
1
import { type Accessor, createMemo, Show } from "solid-js";
2
import { useRepoInfo } from "./context";
3
4
function HeaderItem(props: {
···
18
);
19
}
20
21
+
export function Header(props: { user: string; repo: string }) {
22
const repoInfo = useRepoInfo();
23
const path = createMemo(() => {
24
const path = window.location.pathname.split("/")[3];
+4
-8
src/routes/repo/tree.tsx
+4
-8
src/routes/repo/tree.tsx
···
99
const [filesInOrder] = createResource(tree, (tree) => {
100
if (!tree.files) return;
101
return tree.files.sort((a, b) => {
102
-
// Directories before files
103
if (!a.is_file === b.is_file) return !a.is_file ? -1 : 1;
104
105
-
// Dotfiles first
106
const aDot = a.name.startsWith(".");
107
const bDot = b.name.startsWith(".");
108
if (aDot !== bDot) return aDot ? -1 : 1;
109
110
-
// Name sorting (natural order)
111
return a.name.localeCompare(b.name, undefined, { numeric: true });
112
});
113
});
···
115
const repoData = createMemo(() => {
116
const db = defaultBranch();
117
const l = languages();
118
-
const d = did();
119
-
if (!(db && l && d)) return;
120
-
return [db, l, d] as const;
121
});
122
123
const pathData = createMemo(() => {
···
132
return (
133
<div class="mx-auto max-w-5xl">
134
<Show when={repoData()} keyed>
135
-
{([defaultBranch, languages, did]) => (
136
<Show when={pathData()} keyed>
137
{([tree, files, readme, logs]) => (
138
<div>
139
-
<Header did={did} user={params.user} repo={params.repo} />
140
<div class="mb-4 flex flex-col rounded bg-white dark:bg-gray-800">
141
<LanguageLine languages={languages} />
142
<div class="flex flex-row">
···
99
const [filesInOrder] = createResource(tree, (tree) => {
100
if (!tree.files) return;
101
return tree.files.sort((a, b) => {
102
if (!a.is_file === b.is_file) return !a.is_file ? -1 : 1;
103
104
const aDot = a.name.startsWith(".");
105
const bDot = b.name.startsWith(".");
106
if (aDot !== bDot) return aDot ? -1 : 1;
107
108
return a.name.localeCompare(b.name, undefined, { numeric: true });
109
});
110
});
···
112
const repoData = createMemo(() => {
113
const db = defaultBranch();
114
const l = languages();
115
+
if (!(db && l)) return;
116
+
return [db, l] as const;
117
});
118
119
const pathData = createMemo(() => {
···
128
return (
129
<div class="mx-auto max-w-5xl">
130
<Show when={repoData()} keyed>
131
+
{([defaultBranch, languages]) => (
132
<Show when={pathData()} keyed>
133
{([tree, files, readme, logs]) => (
134
<div>
135
+
<Header user={params.user} repo={params.repo} />
136
<div class="mb-4 flex flex-col rounded bg-white dark:bg-gray-800">
137
<LanguageLine languages={languages} />
138
<div class="flex flex-row">
+13
-12
src/util/handle.ts
+13
-12
src/util/handle.ts
···
24
export const figureOutDid = query(async (user: string): Promise<DID> => {
25
const isDid = user.startsWith("did:");
26
if (!isDid && user.includes(".")) {
27
-
let res = didMap.get(user);
28
-
if (!res && useSlingshot)
29
-
res = (
30
-
await (
31
-
await fetch(
32
-
`${slingshotUrl}/xrpc/com.atproto.identity.resolveHandle?handle=${user}`,
33
-
)
34
-
).json()
35
-
).did;
36
-
if (!res) res = await handleResolver.resolve(user as `${string}.${string}`);
37
-
didMap.set(user, res);
38
-
return res;
39
}
40
return user as DID;
41
}, "handles");
···
24
export const figureOutDid = query(async (user: string): Promise<DID> => {
25
const isDid = user.startsWith("did:");
26
if (!isDid && user.includes(".")) {
27
+
let did = didMap.get(user);
28
+
if (!did && useSlingshot) {
29
+
const res = await fetch(
30
+
`${slingshotUrl}/xrpc/com.atproto.identity.resolveHandle?handle=${user}`,
31
+
);
32
+
if (res.ok) {
33
+
const json = await res.json();
34
+
if ("did" in json && typeof json.did === "string") did = json.did;
35
+
}
36
+
}
37
+
if (!did) did = await handleResolver.resolve(user as `${string}.${string}`);
38
+
didMap.set(user, did);
39
+
return did;
40
}
41
return user as DID;
42
}, "handles");