Skip to content

Commit c15a199

Browse files
perf: defer README + BIDS tree to /api endpoints
1 parent 1879a96 commit c15a199

8 files changed

Lines changed: 566 additions & 373 deletions

File tree

‎src/components/BidsDirChildren.astro‎

Lines changed: 0 additions & 157 deletions
This file was deleted.

‎src/components/BidsTree.astro‎

Lines changed: 84 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,45 @@
11
---
2-
import type { TreeNode } from "../lib/bids-tree";
3-
import { classifyFile } from "../lib/bids-tree";
4-
import { formatBytes } from "../lib/format";
5-
import BidsDirChildren from "./BidsDirChildren.astro";
6-
72
interface Props {
8-
root: TreeNode;
9-
basePath: string;
3+
datasetId: string;
4+
version: string | null;
105
}
116
12-
const { root, basePath } = Astro.props;
13-
const topLevel = root.children;
14-
const rootFiles = root.files;
15-
16-
function countFilesDeep(n: TreeNode): number {
17-
let total = n.files.length;
18-
for (const c of n.children) total += countFilesDeep(c);
19-
return total;
20-
}
7+
const { datasetId, version } = Astro.props;
218
---
229

23-
<section class="tree" aria-label="Dataset file tree">
24-
<header class="tree__head">
25-
<h2>Files</h2>
26-
<span class="tree__meta">
27-
{root.children.length + root.files.length} top-level entries · {formatBytes(root.totalSize)} total
28-
</span>
29-
</header>
30-
31-
{rootFiles.length > 0 && (
32-
<ul class="tree__list tree__list--root" role="list">
33-
{rootFiles.map((f) => {
34-
const cls = classifyFile(f.path);
35-
return (
36-
<li class="tree__row">
37-
<span class="tree__icon" aria-hidden="true">▪</span>
38-
<a
39-
class="tree__name"
40-
href={`${basePath}/${encodeURI(f.path)}`}
41-
rel="external"
42-
download={f.path.split("/").pop()}
43-
title={`Download ${f.path}`}
44-
>
45-
{f.path}
46-
</a>
47-
<span class="tree__size">{formatBytes(f.size)}</span>
48-
{cls.isReadme && <span class="tree__tag">README</span>}
49-
{cls.isJSON && <span class="tree__tag">JSON</span>}
50-
</li>
51-
);
52-
})}
53-
</ul>
54-
)}
10+
{version ? (
11+
<section class="tree" aria-label="Dataset file tree" data-tree-defer data-id={datasetId} data-version={version} aria-busy="true">
12+
<header class="tree__head">
13+
<h2>Files</h2>
14+
<span class="tree__meta">Loading file index…</span>
15+
</header>
16+
<div class="tree__skeleton" aria-hidden="true">
17+
<div class="tree__skeleton-row"></div>
18+
<div class="tree__skeleton-row"></div>
19+
<div class="tree__skeleton-row"></div>
20+
<div class="tree__skeleton-row"></div>
21+
<div class="tree__skeleton-row"></div>
22+
<div class="tree__skeleton-row"></div>
23+
<div class="tree__skeleton-row"></div>
24+
</div>
25+
<noscript>
26+
<p style="padding: var(--space-5)">File tree requires JavaScript. <a href={`/api/dataset/${datasetId}/tree?v=${encodeURIComponent(version)}`}>View raw HTML</a>.</p>
27+
</noscript>
28+
</section>
29+
) : (
30+
<section class="tree" aria-label="Dataset file tree">
31+
<header class="tree__head">
32+
<h2>Files</h2>
33+
<span class="tree__meta">No version selected</span>
34+
</header>
35+
</section>
36+
)}
5537

56-
<ul class="tree__list" role="list">
57-
{topLevel.map((node) => (
58-
<li>
59-
<details class="tree__dir" open={topLevel.length <= 3}>
60-
<summary class="tree__row tree__row--dir">
61-
<svg class="tree__chevron" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
62-
<path d="m9 6 6 6-6 6"/>
63-
</svg>
64-
<span class="tree__icon" aria-hidden="true">▸</span>
65-
<span class="tree__name">{node.name}</span>
66-
<span class="tree__counts">
67-
{node.children.length} dirs · {countFilesDeep(node)} files
68-
</span>
69-
<span class="tree__size">{formatBytes(node.totalSize)}</span>
70-
</summary>
71-
<BidsDirChildren node={node} basePath={basePath} depth={1} />
72-
</details>
73-
</li>
74-
))}
75-
</ul>
76-
</section>
77-
78-
<style>
38+
<style is:global>
39+
/* is:global because the tree HTML can be rendered server-side by the
40+
/api/dataset/<id>/tree endpoint and injected client-side, in which case
41+
it doesn't carry Astro's component-scope data attribute. .tree__ prefix
42+
keeps collision risk low. Keep in sync with BidsDirChildren styles. */
7943
.tree {
8044
border: 1px solid var(--color-border);
8145
border-radius: var(--radius-lg);
@@ -100,6 +64,35 @@ function countFilesDeep(n: TreeNode): number {
10064
font-size: var(--fs-xs);
10165
font-family: var(--font-mono);
10266
}
67+
.tree__skeleton {
68+
display: flex;
69+
flex-direction: column;
70+
padding: 0 var(--space-5);
71+
}
72+
.tree__skeleton-row {
73+
block-size: 1.25em;
74+
margin-block: 8px;
75+
border-radius: var(--radius-sm);
76+
background: linear-gradient(
77+
90deg,
78+
var(--color-bg-subtle) 0%,
79+
var(--color-bg-elevated) 50%,
80+
var(--color-bg-subtle) 100%
81+
);
82+
background-size: 200% 100%;
83+
animation: tree-shimmer 1.4s ease-in-out infinite;
84+
}
85+
.tree__skeleton-row:nth-child(1) { inline-size: 45%; }
86+
.tree__skeleton-row:nth-child(2) { inline-size: 80%; }
87+
.tree__skeleton-row:nth-child(3) { inline-size: 65%; }
88+
.tree__skeleton-row:nth-child(4) { inline-size: 88%; }
89+
.tree__skeleton-row:nth-child(5) { inline-size: 55%; }
90+
.tree__skeleton-row:nth-child(6) { inline-size: 72%; }
91+
.tree__skeleton-row:nth-child(7) { inline-size: 40%; }
92+
@keyframes tree-shimmer {
93+
0% { background-position: 100% 0; }
94+
100% { background-position: -100% 0; }
95+
}
10396
.tree__list {
10497
list-style: none;
10598
padding: 0;
@@ -183,4 +176,24 @@ function countFilesDeep(n: TreeNode): number {
183176
color: var(--color-fg-muted);
184177
font-family: var(--font-mono);
185178
}
179+
/* Empty-state banner shown when the tree endpoint returns no manifest. */
180+
.detail__no-manifest {
181+
padding: var(--space-6);
182+
border: 1px solid color-mix(in srgb, var(--color-warning) 30%, transparent);
183+
background: color-mix(in srgb, var(--color-warning) 5%, var(--color-bg));
184+
border-radius: var(--radius-lg);
185+
}
186+
.detail__no-manifest h2 {
187+
font-size: var(--fs-lg);
188+
margin-block-end: var(--space-2);
189+
}
190+
.detail__no-manifest p {
191+
color: var(--color-fg-muted);
192+
line-height: var(--lh-relaxed);
193+
}
194+
.detail__no-manifest code {
195+
background: var(--color-bg-subtle);
196+
padding: 1px 6px;
197+
border-radius: var(--radius-sm);
198+
}
186199
</style>

0 commit comments

Comments
 (0)