Add now playing thing

pull/4/head
Julie 5 years ago
parent 6aed3a0528
commit 732b416c05

@ -4,17 +4,32 @@ import { Tooltip } from "antd";
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import axios from "axios"; import axios from "axios";
interface NowPlayingData {
introduction: string,
lastfm: {
artist: string,
track: string,
playing: boolean
}
}
function LastFmLi() { function LastFmLi() {
const [nowPlayingSong, setNowPlayingSong] = useState<string>("nothing"); const [nowPlayingData, setNowPlayingData] = useState<NowPlayingData>({
const [nowPlayingArtist, setNowPlayingArtist] = useState<string>("no-one"); introduction: "",
lastfm: {
artist: "nobody",
playing: false,
track: "nothing"
}
});
async function updateNowPlaying() { async function updateNowPlaying() {
try { try {
const songData = await axios.get( const songRequestData = await axios.get(
"https://jsonplaceholder.typicode.com/posts" "https://api.jakecover.me"
); );
console.log(songData.data); setNowPlayingData(songRequestData.data)
} catch (err) { } catch (err) {
console.error(err); console.error(err);
} }
@ -29,7 +44,10 @@ function LastFmLi() {
clearInterval(interval); clearInterval(interval);
}; };
}, []); }, []);
return <li>listening to ____ by ____</li>; if (nowPlayingData.lastfm.playing) {
return <li>listening to {nowPlayingData.lastfm.track} by {nowPlayingData.lastfm.artist}</li>;
}
return <li>not listening to anything right now.</li>;
}; };
function Age() { function Age() {

Loading…
Cancel
Save