Skip to content

Commit 63b99b7

Browse files
committed
Refactor manifest shape to allow for a configuration object.
1 parent 985807a commit 63b99b7

File tree

6 files changed

+49
-27
lines changed

6 files changed

+49
-27
lines changed

cplayer.code-workspace

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
}
66
],
77
"settings": {
8-
"editor.formatOnSave": true
8+
"editor.formatOnSave": true,
9+
"editor.tabSize": 2
910
}
1011
}

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1" />
66
<meta name="theme-color" content="#000000" />
7-
<title>suncrash</title>
7+
<title>cplayer</title>
88
</head>
99
<body>
1010
<noscript>You need to enable JavaScript to run this app.</noscript>

src/AlbumManifestContext.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,22 @@ interface AlbumManifestProviderProps {
1414
export const AlbumManifestProvider: Component<AlbumManifestProviderProps> = (
1515
props
1616
) => {
17+
const [config, setConfig] = createSignal<Record<string, any>>({});
1718
const [albums, setAlbums] = createSignal<Album[]>([]);
18-
const [manifest, setManifest] = createSignal<AlbumManifest>({ albums });
19+
const [manifest, setManifest] = createSignal<AlbumManifest>({
20+
albums,
21+
config,
22+
});
1923
fetch(MANIFEST_URI).then(async (response) => {
2024
const albumManifest = await response.json();
21-
_.each(albumManifest, (album) => {
25+
_.each(albumManifest.albums, (album) => {
2226
_.each(album.tracks, (track) => {
2327
track.uri = `${PATH_PREFIX}/${track.uri}`;
2428
});
2529
});
26-
setAlbums(albumManifest);
27-
setManifest({ albums });
30+
setConfig(albumManifest.config);
31+
setAlbums(albumManifest.albums);
32+
setManifest({ albums, config });
2833
});
2934
return (
3035
<AlbumManifestContext.Provider value={manifest()}>

src/App.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import _ from "lodash";
2-
import { Component, Show, useContext } from "solid-js";
2+
import { Component, Show, useContext, createEffect } from "solid-js";
33
import { Track, Album, PlaybackState } from "./Types";
44
import { PlaybackContext } from "./PlaybackContext";
55
import { AlbumManifestContext } from "./AlbumManifestContext";
@@ -34,6 +34,13 @@ const formatDuration = (seconds: number) => {
3434
return `${Math.floor(mins)}:${Math.floor(secs).toString().padStart(2, "0")}`;
3535
};
3636

37+
const handleConfigChanged = (config: Record<string, any>) => {
38+
const pageTitle = config.pageTitle;
39+
if (pageTitle) {
40+
document.title = pageTitle;
41+
}
42+
};
43+
3744
const SeekBar: Component<SeekBarProps> = (props) => {
3845
const handleClick = (ev: any) => {
3946
const percent = Math.round(
@@ -200,6 +207,9 @@ const AlbumView: Component<AlbumViewProps> = (props) => {
200207
const App: Component = () => {
201208
const albumManifestContext = useContext(AlbumManifestContext);
202209
const manifestLoaded = () => albumManifestContext?.albums().length;
210+
createEffect(() => {
211+
handleConfigChanged(albumManifestContext?.config() ?? {});
212+
}, [albumManifestContext?.config]);
203213
return (
204214
<Show when={manifestLoaded()}>
205215
<div class={styles.App}>

src/Types.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ export interface Playback {
4141

4242
export interface AlbumManifest {
4343
albums: Accessor<Album[]>;
44+
config: Accessor<Record<string, any>>;
4445
}

src/assets/manifest-example.json

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
[
2-
{
3-
"name": "album name",
4-
"artist": "album's artist name",
5-
"tracks": [
6-
{
7-
"title": "track title 1",
8-
"uri": "relative/path/to/track1.opus"
9-
},
10-
{
11-
"title": "track title 2",
12-
"uri": "relative/path/to/track2.ogg"
13-
},
14-
{
15-
"title": "track title 3",
16-
"uri": "relative/path/to/track3.mp3"
17-
},
18-
]
19-
}
20-
]
1+
{
2+
"config": {
3+
"pageTitle": "my page title"
4+
},
5+
"albums": [
6+
{
7+
"name": "album name",
8+
"artist": "album's artist name",
9+
"tracks": [
10+
{
11+
"title": "track title 1",
12+
"uri": "relative/path/to/track1.opus"
13+
},
14+
{
15+
"title": "track title 2",
16+
"uri": "relative/path/to/track2.ogg"
17+
},
18+
{
19+
"title": "track title 3",
20+
"uri": "relative/path/to/track3.mp3"
21+
}
22+
]
23+
}
24+
]
25+
}

0 commit comments

Comments
 (0)