1
0
cvsa/packages/temp_frontend/app/routes/song/[id]/info.tsx

30 lines
787 B
TypeScript

import useSWR from "swr";
import type { Route } from "./+types/info";
const API_URL = "https://api.projectcvsa.com";
export async function clientLoader({ params }: Route.LoaderArgs) {
return { id: params.id };
}
export default function SongInfo({ loaderData }: Route.ComponentProps) {
const { data, error, isLoading } = useSWR(`${API_URL}/video/${loaderData.id}/info`, async (url) => {
const response = await fetch(url);
if (!response.ok) {
throw new Error("Failed to fetch song info");
}
return response.json();
});
if (isLoading) return <div>...</div>;
if (error) return <div>: {error.message}</div>;
if (!data) return <div></div>;
return (
<div>
<h1></h1>
<pre>{JSON.stringify(data, null, 2)}</pre>
</div>
);
}