Updated to the correct API

pull/13/head
Cobular 4 years ago
parent 84dcf7f441
commit aa63944899
No known key found for this signature in database
GPG Key ID: 8A55E11B548F0594

@ -1 +1 @@
jakecover.me cobular.com

@ -48,7 +48,7 @@
"react-app/jest" "react-app/jest"
] ]
}, },
"homepage": "https://jakecover.me", "homepage": "https://cobular.com",
"name": "personal-website-static", "name": "personal-website-static",
"private": true, "private": true,
"scripts": { "scripts": {

@ -59,7 +59,7 @@
ul { ul {
text-align: left; text-align: left;
padding-left: 40px; padding-left: 30px;
margin-bottom: 0; margin-bottom: 0;
} }
@ -68,7 +68,9 @@
font-size: 18px; font-size: 18px;
list-style-type: symbols("+"); list-style-type: symbols("+");
list-style-position: inside; list-style-position: inside;
}
li::-moz-list-bullet {
content: "+ ";
} }
} }
@ -99,8 +101,12 @@
&:hover, &:focus, &:focus-visible { &:hover, &:focus, &:focus-visible {
text-decoration-color: var(--link-color); text-decoration-color: var(--link-color);
} }
}
#now-playing {
max-width: 25ch;
margin-left: 1.2ch;
text-indent: -1.2ch;
} }
} }

@ -1,32 +1,55 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import axios from "axios";
interface NowPlayingData { interface NowPlayingData {
introduction: string;
lastfm: {
artist: string; artist: string;
track: string; track: string;
playing: boolean; playing: boolean;
url: string | undefined; url: string | undefined;
};
} }
export function LastFmLi() { export function LastFmLi() {
const [nowPlayingData, setNowPlayingData] = useState<NowPlayingData>({ const [nowPlayingData, setNowPlayingData] = useState<NowPlayingData>({
introduction: "",
lastfm: {
artist: "nobody", artist: "nobody",
playing: false, playing: false,
track: "nothing", track: "nothing",
url: undefined, url: undefined,
},
}); });
async function updateNowPlaying() { async function updateNowPlaying() {
try { try {
const songRequestData = await axios.get("https://api.jakecover.me"); const songRequestData = await fetch("https://api.cobular.com/graphql", {
body: JSON.stringify({
query: `
query {
nowPlaying {
track {
... on Track {
title
artists {
name
}
link
}
}
}
}
setNowPlayingData(songRequestData.data); `,
}),
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Dnt: "1",
},
method: "POST",
});
const data: any = await songRequestData.json();
setNowPlayingData({
playing: true,
artist: data["data"]["nowPlaying"]["track"]["artists"][0]["name"],
track: data["data"]["nowPlaying"]["track"]["title"],
url: data["data"]["nowPlaying"]["track"]["link"],
});
} catch (err) { } catch (err) {
console.error(err); console.error(err);
} }
@ -42,20 +65,15 @@ export function LastFmLi() {
}; };
}, []); }, []);
if (nowPlayingData.lastfm.playing) { if (nowPlayingData.playing) {
return ( return (
<li> <li id={"now-playing"}>
<a listening to{" "}
href={nowPlayingData.lastfm.url} <a href={nowPlayingData.url} target={"_blank"} rel="noreferrer">
target={"_blank"} {nowPlayingData.track} by {nowPlayingData.artist}
rel="noreferrer"
style={{color: "inherit", textDecoration: "inherit"}}
>
listening to {nowPlayingData.lastfm.track} by{" "}
{nowPlayingData.lastfm.artist}
</a> </a>
</li> </li>
); );
} }
return <li>not listening to anything right now.</li>; return <li>not listening to anything right now. <br/></li>;
} }
Loading…
Cancel
Save