From 0e38f4949383b2fc206d24be696392a300c13074 Mon Sep 17 00:00:00 2001 From: Cobular <22972550+Cobular@users.noreply.github.com> Date: Sun, 17 Jan 2021 01:55:39 -0800 Subject: [PATCH] Add now playing thing --- src/components/AboutMe.tsx | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/components/AboutMe.tsx b/src/components/AboutMe.tsx index 4eb944c..e74376f 100644 --- a/src/components/AboutMe.tsx +++ b/src/components/AboutMe.tsx @@ -4,17 +4,32 @@ import { Tooltip } from "antd"; import { useState, useEffect } from "react"; import axios from "axios"; +interface NowPlayingData { + introduction: string, + lastfm: { + artist: string, + track: string, + playing: boolean + } +} + function LastFmLi() { - const [nowPlayingSong, setNowPlayingSong] = useState("nothing"); - const [nowPlayingArtist, setNowPlayingArtist] = useState("no-one"); + const [nowPlayingData, setNowPlayingData] = useState({ + introduction: "", + lastfm: { + artist: "nobody", + playing: false, + track: "nothing" + } + }); async function updateNowPlaying() { try { - const songData = await axios.get( - "https://jsonplaceholder.typicode.com/posts" + const songRequestData = await axios.get( + "https://api.jakecover.me" ); - console.log(songData.data); + setNowPlayingData(songRequestData.data) } catch (err) { console.error(err); } @@ -29,7 +44,10 @@ function LastFmLi() { clearInterval(interval); }; }, []); - return
  • listening to ____ by ____
  • ; + if (nowPlayingData.lastfm.playing) { + return
  • listening to {nowPlayingData.lastfm.track} by {nowPlayingData.lastfm.artist}
  • ; + } + return
  • not listening to anything right now.
  • ; }; function Age() {