tangled
alpha
login
or
join now
vielle.dev
/
site
0
fork
atom
Personal Site
0
fork
atom
overview
issues
pulls
pipelines
Create types for use on the client to type data from sse
vielle.dev
7 months ago
b6e76820
a98cf368
verified
This commit was signed with the committer's
known signature
.
vielle.dev
SSH Key Fingerprint:
SHA256:/4bvxqoEh9iMdjAPgcgAgXKZZQTROL3ULiPt6nH9RSs=
+41
-2
1 changed file
expand all
collapse all
unified
split
src
components
home
playing
spotify
client.ts
+41
-2
src/components/home/playing/spotify/client.ts
···
1
1
-
/**
1
1
+
/**
2
2
* types & type guards for front end logic when received from now-playing-sse
3
3
-
*/
3
3
+
*/
4
4
+
5
5
+
import { isObj } from "/utils";
6
6
+
7
7
+
export type nowPlaying = {
8
8
+
id: string;
9
9
+
name: string;
10
10
+
href: string;
11
11
+
album: string;
12
12
+
art: string;
13
13
+
artists: {
14
14
+
name: string;
15
15
+
href: string;
16
16
+
}[];
17
17
+
} | null;
18
18
+
19
19
+
export const isNowPlaying = (playing: any): playing is nowPlaying =>
20
20
+
playing === null ||
21
21
+
(isObj(playing) &&
22
22
+
"id" in playing &&
23
23
+
typeof playing.id === "string" &&
24
24
+
"name" in playing &&
25
25
+
typeof playing.name === "string" &&
26
26
+
"href" in playing &&
27
27
+
typeof playing.href === "string" &&
28
28
+
"album" in playing &&
29
29
+
typeof playing.album === "string" &&
30
30
+
"art" in playing &&
31
31
+
typeof playing.art === "string" &&
32
32
+
"artists" in playing &&
33
33
+
Array.isArray(playing.artists) &&
34
34
+
playing.artists.reduce(
35
35
+
(acc, curr) =>
36
36
+
acc &&
37
37
+
"name" in curr &&
38
38
+
typeof curr.name === "string" &&
39
39
+
"href" in curr &&
40
40
+
typeof curr.href === "string",
41
41
+
),
42
42
+
true);