From 26a68ecc4afd5593d99dbc0cdf633e73d889cd58 Mon Sep 17 00:00:00 2001 From: Phill Pover Date: Sun, 6 Apr 2025 21:21:06 +0100 Subject: [PATCH] Reworking actions --- frontend/src/app/actions.tsx | 10 ++-------- frontend/src/app/album/[id]/page.tsx | 10 +++++++--- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/frontend/src/app/actions.tsx b/frontend/src/app/actions.tsx index ceb6079..46ff88d 100644 --- a/frontend/src/app/actions.tsx +++ b/frontend/src/app/actions.tsx @@ -1,10 +1,7 @@ 'use server' export async function getAlbums() { - return await fetch("https://api.anatid.net/album", { - method: "GET", - headers: { "Content-Type": "application/json" }, - }); + return await fetch('https://api.anatid.net/album'); } export async function getAlbum(id: number) { @@ -58,10 +55,7 @@ export async function deleteAlbum(formData: FormData) { } export async function getSongs() { - return await fetch(`https://api.anatid.net/song/`, { - method: "GET", - headers: { "Content-Type": "application/json" }, - }); + return await fetch("https://api.anatid.net/song/"); } export async function getSong(id: number) { diff --git a/frontend/src/app/album/[id]/page.tsx b/frontend/src/app/album/[id]/page.tsx index 05f8d0e..3496753 100644 --- a/frontend/src/app/album/[id]/page.tsx +++ b/frontend/src/app/album/[id]/page.tsx @@ -20,9 +20,13 @@ export default function Page() { useEffect(() => { async function fetchAlbum(id: string) { - const response = await getAlbum(parseInt(id)); - const data = await response.json(); - setAlbum(data); + try { + const response = await getAlbum(parseInt(id)); + const data = await response.json(); + setAlbum(data); + } catch (error) { + console.error(`Error getting album with id ${id}`, error); + } } fetchAlbum(id); }, [id]);