Skip to content

Commit 2720b75

Browse files
Address PR review feedback
1 parent f075a48 commit 2720b75

7 files changed

Lines changed: 68 additions & 28 deletions

File tree

docs/intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ Listenarr is a self-hosted audiobook automation server built to streamline the p
2929

3030
## API
3131

32-
Open the [API guide](pathname:///api/) to review the bundled OpenAPI snapshot and see how to use Swagger on your own Listenarr instance.
32+
Open the [API guide](/api/) to review the bundled OpenAPI snapshot and see how to use Swagger on your own Listenarr instance.

scripts/sync-listenarr.mjs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,17 +268,30 @@ async function bundleSwaggerUi(port) {
268268
writeFileSync(
269269
path.join(apiDir, 'swagger-initializer.js'),
270270
`window.onload = async function () {
271-
const response = await fetch('./openapi.json');
272-
const spec = await response.json();
271+
let specConfig = { url: './openapi.json' };
273272
274-
window.ui = SwaggerUIBundle({
275-
spec: {
276-
...spec,
277-
info: {
278-
...(spec.info || {}),
279-
description: ''
273+
try {
274+
const response = await fetch('./openapi.json');
275+
if (!response.ok) {
276+
throw new Error(\`Unable to load ./openapi.json: \${response.status}\`);
277+
}
278+
279+
const spec = await response.json();
280+
specConfig = {
281+
spec: {
282+
...spec,
283+
info: {
284+
...(spec.info || {}),
285+
description: ''
286+
}
280287
}
281-
},
288+
};
289+
} catch (error) {
290+
console.error('Failed to preload Listenarr OpenAPI spec for Swagger UI.', error);
291+
}
292+
293+
window.ui = SwaggerUIBundle({
294+
...specConfig,
282295
dom_id: '#swagger-ui',
283296
deepLinking: true,
284297
presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset],

src/pages/api/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ export default function ApiPage() {
164164
View Listenarr source
165165
</a>
166166
</div>
167+
<p className={styles.metaNote}>
168+
Bundled spec generated {generatedAt} from Listenarr {metadata.version} (
169+
{metadata.commit}).
170+
</p>
167171
</div>
168172

169173
<div className={styles.grid}>

src/pages/api/index.module.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
gap: 0.9rem;
4646
}
4747

48+
.metaNote {
49+
margin: 1rem 0 0;
50+
color: var(--text-muted);
51+
font-size: 0.9rem;
52+
}
53+
4854
.grid {
4955
display: grid;
5056
grid-template-columns: minmax(0, 1fr);

src/theme/Navbar/MobileSidebar/SecondaryMenu/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ export default function NavbarMobileSidebarSecondaryMenu() {
2525
}
2626

2727
return (
28-
<ErrorCauseBoundary onError={() => new Error('The mobile secondary navbar menu failed to render.')}>
28+
<ErrorCauseBoundary
29+
onError={(error) =>
30+
new Error('The mobile secondary navbar menu failed to render.', {
31+
cause: error,
32+
})
33+
}>
2934
{!isPrimaryMenuEmpty && (
3035
<SecondaryMenuBackButton onClick={() => secondaryMenu.hide()} />
3136
)}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import React from 'react';
22
import {useLockBodyScroll, useNavbarMobileSidebar} from '@docusaurus/theme-common/internal';
3+
import NavbarMobileSidebarLayout from '@theme/Navbar/MobileSidebar/Layout';
34
import NavbarMobileSidebarHeader from '@theme/Navbar/MobileSidebar/Header';
45
import NavbarMobileSidebarPrimaryMenu from '@theme/Navbar/MobileSidebar/PrimaryMenu';
6+
import NavbarMobileSidebarSecondaryMenu from '@theme/Navbar/MobileSidebar/SecondaryMenu';
57

68
export default function NavbarMobileSidebar() {
79
const mobileSidebar = useNavbarMobileSidebar();
@@ -13,13 +15,10 @@ export default function NavbarMobileSidebar() {
1315
}
1416

1517
return (
16-
<div className="navbar-sidebar">
17-
<NavbarMobileSidebarHeader />
18-
<div className="navbar-sidebar__items">
19-
<div className="navbar-sidebar__item menu">
20-
<NavbarMobileSidebarPrimaryMenu />
21-
</div>
22-
</div>
23-
</div>
18+
<NavbarMobileSidebarLayout
19+
header={<NavbarMobileSidebarHeader />}
20+
primaryMenu={<NavbarMobileSidebarPrimaryMenu />}
21+
secondaryMenu={<NavbarMobileSidebarSecondaryMenu />}
22+
/>
2423
);
2524
}

static/api-ui/swagger-initializer.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
window.onload = async function () {
2-
const response = await fetch('./openapi.json');
3-
const spec = await response.json();
2+
let specConfig = { url: './openapi.json' };
43

5-
window.ui = SwaggerUIBundle({
6-
spec: {
7-
...spec,
8-
info: {
9-
...(spec.info || {}),
10-
description: ''
4+
try {
5+
const response = await fetch('./openapi.json');
6+
if (!response.ok) {
7+
throw new Error(`Unable to load ./openapi.json: ${response.status}`);
8+
}
9+
10+
const spec = await response.json();
11+
specConfig = {
12+
spec: {
13+
...spec,
14+
info: {
15+
...(spec.info || {}),
16+
description: ''
17+
}
1118
}
12-
},
19+
};
20+
} catch (error) {
21+
console.error('Failed to preload Listenarr OpenAPI spec for Swagger UI.', error);
22+
}
23+
24+
window.ui = SwaggerUIBundle({
25+
...specConfig,
1326
dom_id: '#swagger-ui',
1427
deepLinking: true,
1528
presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset],

0 commit comments

Comments
 (0)