From 5acf3b30c7295c76e7c1643d6db3cf2cad54ea13 Mon Sep 17 00:00:00 2001 From: Alex Frantz Date: Sat, 23 Mar 2024 22:55:38 -0400 Subject: [PATCH] new music card --- src/components/BlogCard.tsx | 26 -------------- src/components/Dropdown.tsx | 22 ------------ src/components/MusicCard.tsx | 63 ++++++++++++++++++++++------------ src/pages/index.tsx | 5 +++ src/server/api/routers/misc.ts | 38 +++++++++++--------- 5 files changed, 67 insertions(+), 87 deletions(-) delete mode 100644 src/components/BlogCard.tsx delete mode 100644 src/components/Dropdown.tsx diff --git a/src/components/BlogCard.tsx b/src/components/BlogCard.tsx deleted file mode 100644 index b9d5fbb..0000000 --- a/src/components/BlogCard.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import Image from 'next/image' -import Link from 'next/link'; - -type BlogCardProps = { - image: string, - name: string, - tagline: string, - id: number -} -export default function BlogCard(props: BlogCardProps) { - return ( - -
-
-
- Blog Cover -
-
-

{props.name}

-

{props.tagline}

-
-
-
- - ) -} \ No newline at end of file diff --git a/src/components/Dropdown.tsx b/src/components/Dropdown.tsx deleted file mode 100644 index a4db05d..0000000 --- a/src/components/Dropdown.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import React, {useState} from 'react'; - -type DropdownProps = { - name: string, - content: React.JSX.Element[] -} - -export default function Dropdown(props: DropdownProps) { - const [active, setActive] = useState(false) - return ( - <> -
active ? setActive(false) : setActive(true)}> - {props.name} -
-
- -
- {props.content} -
- - ) -} \ No newline at end of file diff --git a/src/components/MusicCard.tsx b/src/components/MusicCard.tsx index 0e7ec33..cae1d1b 100644 --- a/src/components/MusicCard.tsx +++ b/src/components/MusicCard.tsx @@ -3,28 +3,47 @@ import Link from "next/link"; import { api } from "@/utils/api"; export default function MusicCard() { - const musicFetch = api.misc.song.useQuery() + const {data: musicData, fetchStatus} = api.misc.song.useQuery() - if (musicFetch.data) { - return ( - -
-
-
- Cover Art -
-
-

{musicFetch.data.track.name}

-

{musicFetch.data.track.artist["#text"]}

-
-
-
+ return ( +
+

Listening To

+ + {/* link to lastfm */} + + Powered by Last.fm - ) - } + + { + fetchStatus !== "fetching" ? +
+ { + musicData?.track.map((v,k) => { + return
+ {`${v.name} +
+ +

{v.name}

+ +

{v.artist["#text"]}

+
+
+ }) + } +
+ : +

Hold tight, fetching..

+ } +
+ ) } \ No newline at end of file diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 6ae54d3..a6f5aa9 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,4 +1,5 @@ import RootLayout from "@/components/RootLayout"; +import MusicCard from "@/components/MusicCard"; import Link from 'next/link'; import { Cli } from "grommet-icons"; @@ -51,6 +52,10 @@ export default function Home() {
+ +
+ +
) diff --git a/src/server/api/routers/misc.ts b/src/server/api/routers/misc.ts index 4de389c..cd69eb2 100644 --- a/src/server/api/routers/misc.ts +++ b/src/server/api/routers/misc.ts @@ -10,30 +10,34 @@ type ImageListType = { "#text": string } -type LastTrackType = { +type TrackResponseType = { status: number, - track: { - "@attr": object, - "album": { - "mbid": string, - "#text": string - }, - "artist": { - "mbid": string, - "#text": string, - }, - "image": ImageListType[], + track: LastTrackType[] +} + +type LastTrackType = { + "@attr": { + "nowplaying": string + }, + "album": { "mbid": string, - "name": string, - "streamable": number, - "url": string - } + "#text": string + }, + "artist": { + "mbid": string, + "#text": string, + }, + "image": ImageListType[], + "mbid": string, + "name": string, + "streamable": number, + "url": string } export const miscRouter = createTRPCRouter({ song: publicProcedure .query(async () => { - const response = await axios.get("https://api.thatalex.dev/v3/music/last-track") + const response = await axios.get("https://api.thatalex.dev/v3/music/last-track") return response.data }), }) \ No newline at end of file