diff --git a/netlify/functions/anilist.ts b/netlify/functions/anilist.ts index 4c31507..f149d2f 100644 --- a/netlify/functions/anilist.ts +++ b/netlify/functions/anilist.ts @@ -45,14 +45,6 @@ const handler: Handler = async () => { }, }), }); - if (anilist.status !== 200) { - // log the issue in netlify, return 404 to the user anyway - console.log(await anilist.json()); - return { - statusCode: 404, - body: "", - }; - } const json = (await anilist.json() as any).data.MediaList; const anime: AnilistInfo = { diff --git a/src/components/Info.tsx b/src/components/Info.tsx index 15a6e97..8da094c 100644 --- a/src/components/Info.tsx +++ b/src/components/Info.tsx @@ -14,7 +14,7 @@ export default function Info({ }>; error?: boolean; }) { - const [height, setHeight] = useState(0); + const [height, setHeight] = useState(3); const sections = websites.map((w, i) => { setTimeout(() => { // somehow necessary to not always rerender diff --git a/src/components/Info/Anilist.tsx b/src/components/Info/Anilist.tsx index 2d4334d..bd5b607 100644 --- a/src/components/Info/Anilist.tsx +++ b/src/components/Info/Anilist.tsx @@ -17,18 +17,28 @@ export type AnilistInfo = { export default function Anilist() { const [anilist, setAnilist]: [AnilistInfo, React.Dispatch>] = useState(); + const [error, setError] = useState(false); + const getAnilist = async () => { - const response = await fetch("/.netlify/functions/anilist").then(async r => r.json()); // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - setAnilist(response); + setAnilist(await fetch("/.netlify/functions/anilist").then(async r => r.json())); }; useEffect(() => { - void getAnilist(); + getAnilist().catch(() => { + setError(true); + }); }, []); - if (anilist === undefined) { - return <>; + + if (!anilist) { + return ( + + ); } return ( diff --git a/src/components/Info/Lastfm.tsx b/src/components/Info/Lastfm.tsx index 4a57b94..347662f 100644 --- a/src/components/Info/Lastfm.tsx +++ b/src/components/Info/Lastfm.tsx @@ -12,18 +12,39 @@ export type LastfmInfo = { export default function Lastfm() { const [lastfm, setLastfm]: [LastfmInfo, React.Dispatch>] = useState(); + const [error, setError] = useState(false); + const getLastfm = async () => { - const response = await fetch("/.netlify/functions/lastfm").then(async r => r.json()); // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - setLastfm(response); + setLastfm(await fetch("/.netlify/functions/lastfm").then(async r => r.json())); + }; + + const updateLastFm = () => { + getLastfm().catch(() => { + setError(true); + }); }; useEffect(() => { - void getLastfm(); + updateLastFm(); + + const timer = setInterval(() => { + updateLastFm(); + }, 2 * 60 * 1000); + return () => { + clearInterval(timer); + }; }, []); - if (lastfm === undefined) { - return <>; + + if (!lastfm) { + return ( + + ); } return ( diff --git a/src/components/Info/Speedruncom.tsx b/src/components/Info/Speedruncom.tsx index 810653b..4568905 100644 --- a/src/components/Info/Speedruncom.tsx +++ b/src/components/Info/Speedruncom.tsx @@ -12,21 +12,29 @@ export type SpeedruncomInfo = { export default function Speedruncom() { const [speedruncom, setSpeedruncom]: [SpeedruncomInfo, React.Dispatch>] = useState(); + const [error, setError] = useState(false); + const getSpeedruncom = async () => { - const response = await fetch("/.netlify/functions/speedruncom").then(async r => r.json()); // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - setSpeedruncom(response); + setSpeedruncom(await fetch("/.netlify/functions/speedruncom").then(async r => r.json())); }; useEffect(() => { - void getSpeedruncom(); + getSpeedruncom().catch(() => { + setError(true); + }); }, []); - if (speedruncom === undefined) { - return <>; - } - const details = speedruncom.details.map((d, i) =>

{d}

); + if (!speedruncom) { + return ( + + ); + } return (

Placed #{speedruncom.place} on:

{speedruncom.game}

- {details} + {speedruncom.details.map((d, i) =>

{d}

)} ,

{speedruncom.date}

,