update api url
This commit is contained in:
@@ -1,60 +1,70 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from "react";
|
||||||
|
|
||||||
type TVObject = {
|
type TVObject = {
|
||||||
id: number,
|
id: number;
|
||||||
type: string,
|
type: string;
|
||||||
title: string,
|
title: string;
|
||||||
author: string | null,
|
author: string | null;
|
||||||
description: string,
|
description: string;
|
||||||
image: string,
|
image: string;
|
||||||
episode: string,
|
episode: string;
|
||||||
tmdbId: string,
|
tmdbId: string;
|
||||||
finished: boolean,
|
finished: boolean;
|
||||||
yearReleased: string,
|
yearReleased: string;
|
||||||
genre: string,
|
genre: string;
|
||||||
startedOn: string
|
startedOn: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
export default function TVComponent() {
|
export default function TVComponent() {
|
||||||
const [ show, setShow ] = useState<TVObject | null>(null);
|
const [show, setShow] = useState<TVObject | null>(null);
|
||||||
const [ failedFetch, setFailedFetch ] = useState(false);
|
const [failedFetch, setFailedFetch] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchMusic() {
|
async function fetchMusic() {
|
||||||
const response = await fetch("https://api.alexav.gg/v4/tracker/latest/tv")
|
const response = await fetch(
|
||||||
if (response.ok) {
|
"https://api.alexav.gg/v4/tracker/items?type=tv&sort=desc"
|
||||||
const data = await response.json()
|
);
|
||||||
setShow(data.data as TVObject)
|
if (response.ok) {
|
||||||
} else setFailedFetch(true)
|
const data = await response.json();
|
||||||
}
|
if (data.data && data.data.length <= 0) {
|
||||||
|
setFailedFetch(true);
|
||||||
setTimeout(() => {
|
} else setShow(data.data[0] as TVObject);
|
||||||
fetchMusic()
|
} else setFailedFetch(true);
|
||||||
}, 60000)
|
|
||||||
fetchMusic()
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
if (show) {
|
|
||||||
return (
|
|
||||||
<div className="flex align-middle">
|
|
||||||
<a className="hover:underline" href={`https://tracker.alexav.gg/?id=${show.id}&type=${show.type}`} target="_blank">
|
|
||||||
<h1 className="lowercase">{show.title} - {show.finished ? "finished" : show.episode}</h1>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
if (failedFetch) {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<p>failed to get show :(</p>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<p>loading show..</p>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
fetchMusic();
|
||||||
|
}, 60000);
|
||||||
|
fetchMusic();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (show) {
|
||||||
|
return (
|
||||||
|
<div className="flex align-middle">
|
||||||
|
<a
|
||||||
|
className="hover:underline"
|
||||||
|
href={`https://tracker.alexav.gg/?id=${show.id}&type=${show.type}`}
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
<h1 className="lowercase">
|
||||||
|
{show.title} - {show.finished ? "finished" : show.episode}
|
||||||
|
</h1>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
if (failedFetch) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<p>failed to get show :(</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<p>loading show..</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user