ref: create type for recentTracks response
This commit is contained in:
parent
18201da104
commit
13ad6645f0
@ -2,8 +2,26 @@ import { api } from "../lib/axios";
|
|||||||
|
|
||||||
const api_key = import.meta.env.VITE_LASTFM_API_KEY
|
const api_key = import.meta.env.VITE_LASTFM_API_KEY
|
||||||
|
|
||||||
|
export interface getRecentTracksResponse {
|
||||||
|
recenttracks: {
|
||||||
|
track: [
|
||||||
|
{
|
||||||
|
artist: {
|
||||||
|
mbid: string,
|
||||||
|
"#text": string
|
||||||
|
},
|
||||||
|
streamable: string,
|
||||||
|
image: [],
|
||||||
|
mbid: string,
|
||||||
|
name: string,
|
||||||
|
url: string,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function getRecentTracks() {
|
export async function getRecentTracks() {
|
||||||
const response = await api.get('/', {
|
const response = await api.get<getRecentTracksResponse>('/', {
|
||||||
params: {
|
params: {
|
||||||
api_key,
|
api_key,
|
||||||
method: 'user.getrecenttracks',
|
method: 'user.getrecenttracks',
|
||||||
|
@ -8,13 +8,12 @@ export default function Music() {
|
|||||||
queryKey: ['song'],
|
queryKey: ['song'],
|
||||||
queryFn: getRecentTracks
|
queryFn: getRecentTracks
|
||||||
})
|
})
|
||||||
const { recenttracks } = lastResponse
|
|
||||||
const { track } = recenttracks
|
|
||||||
const lastTrack = track[0]
|
|
||||||
return (
|
return (
|
||||||
<MainContainer>
|
<MainContainer>
|
||||||
<h1>My Last FM Status</h1>
|
<h1>My Last FM Status</h1>
|
||||||
<Paragraph>{lastTrack.name} - {lastTrack.artist["#text"]}</Paragraph>
|
<h2>Check my last played song!</h2>
|
||||||
|
<Paragraph>{lastResponse?.recenttracks?.track[0].name} - {lastResponse?.recenttracks?.track[0].artist["#text"]}</Paragraph>
|
||||||
|
<a href={lastResponse?.recenttracks?.track[0].url}>Check this song on LastFM</a>
|
||||||
</MainContainer>
|
</MainContainer>
|
||||||
)
|
)
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user