From ed3e81906e95b8b1ea40ac1ed2bff1f4f6acb164 Mon Sep 17 00:00:00 2001 From: Alex Frantz Date: Sat, 3 Jan 2026 13:32:14 -0500 Subject: [PATCH] add dedicated stat module --- src/components/info/TVComponent.tsx | 73 --------- src/components/modules/InfoModule.tsx | 6 - src/components/modules/StatModule.tsx | 214 ++++++++++++++++++++++++++ src/pages/App.tsx | 2 + 4 files changed, 216 insertions(+), 79 deletions(-) delete mode 100644 src/components/info/TVComponent.tsx create mode 100644 src/components/modules/StatModule.tsx diff --git a/src/components/info/TVComponent.tsx b/src/components/info/TVComponent.tsx deleted file mode 100644 index e1cd8d5..0000000 --- a/src/components/info/TVComponent.tsx +++ /dev/null @@ -1,73 +0,0 @@ -import { useState, useEffect } from "react"; - -type TVObject = { - id: number; - type: string; - title: string; - author: string | null; - description: string; - image: string; - paused: boolean; - episode: string; - tmdbId: string; - finished: boolean; - yearReleased: string; - genre: string; - startedOn: string; -}; - -export default function TVComponent() { - const [show, setShow] = useState(null); - const [failedFetch, setFailedFetch] = useState(false); - - useEffect(() => { - async function fetchMusic() { - const response = await fetch( - "https://api.alexav.gg/v4/tracker/items?type=TV&sort=desc&limit=1" - ); - if (response.ok) { - const data = await response.json(); - if (data && data.length <= 0) { - setFailedFetch(true); - } else setShow(data[0] as TVObject); - } else setFailedFetch(true); - } - - setTimeout(() => { - fetchMusic(); - }, 60000); - fetchMusic(); - }, []); - - if (show) { - return ( -
- -

- {show.title} -
- {show.finished ? "finished" : show.paused ? "paused" : show.episode} -

-
-
- ); - } else { - if (failedFetch) { - return ( -
-

failed to get show :(

-
- ); - } else { - return ( -
-

loading show..

-
- ); - } - } -} diff --git a/src/components/modules/InfoModule.tsx b/src/components/modules/InfoModule.tsx index 7bc6d95..84a4b99 100644 --- a/src/components/modules/InfoModule.tsx +++ b/src/components/modules/InfoModule.tsx @@ -1,5 +1,4 @@ import MusicComponent from "../info/MusicComponent"; -import TVComponent from "../info/TVComponent"; export default function InfoModule() { return ( @@ -41,11 +40,6 @@ export default function InfoModule() {

obsessed with

dexter, tlou, twd

- -
- -

status

- diff --git a/src/components/modules/StatModule.tsx b/src/components/modules/StatModule.tsx new file mode 100644 index 0000000..c81ab6c --- /dev/null +++ b/src/components/modules/StatModule.tsx @@ -0,0 +1,214 @@ +import { useState, useEffect } from "react"; + +type ContentObject = { + id: number; + type: string; + title: string; + author: string | null; + description: string; + image: string; + paused: boolean; + episode: string; + tmdbId: string; + finished: boolean; + yearReleased: string; + genre: string; + startedOn: string; +}; + +export default function StatModule() { + const [show, setShow] = useState(null); + const [game, setGame] = useState(null); + const [book, setBook] = useState(null); + + const [failedFetch, setFailedFetch] = useState({ + tv: false, + book: false, + game: false, + }); + + const ErrorState = () => { + return ( +
+

Uh oh :(

+

Something went wrong loading this stat

+
+ ); + }; + + useEffect(() => { + async function fetchTV() { + const response = await fetch( + "https://api.alexav.gg/v4/tracker/items?type=TV&sort=desc&limit=1&started=true" + ); + if (response.ok) { + const data = await response.json(); + if (data && data.length <= 0) { + setFailedFetch((prev) => { + return { + ...prev, + tv: true, + }; + }); + } else setShow(data.data[0] as ContentObject); + } else + setFailedFetch((prev) => { + return { + ...prev, + tv: true, + }; + }); + } + async function fetchBook() { + const response = await fetch( + "https://api.alexav.gg/v4/tracker/items?type=BOOK&sort=desc&limit=1&started=true" + ); + if (response.ok) { + const data = await response.json(); + if (data && data.length <= 0) { + setFailedFetch((prev) => { + return { + ...prev, + book: true, + }; + }); + } else setBook(data.data[0] as ContentObject); + } else + setFailedFetch((prev) => { + return { + ...prev, + book: true, + }; + }); + } + async function fetchGame() { + const response = await fetch( + "https://api.alexav.gg/v4/tracker/items?type=GAME&sort=desc&limit=1&started=true" + ); + if (response.ok) { + const data = await response.json(); + if (data && data.length <= 0) { + setFailedFetch((prev) => { + return { + ...prev, + game: true, + }; + }); + } else setGame(data.data[0] as ContentObject); + } else + setFailedFetch((prev) => { + return { + ...prev, + game: true, + }; + }); + } + + fetchTV(); + fetchBook(); + fetchGame(); + }, []); + + return ( + + ); + + // if (show) { + // return ( + //
+ //
+ // ); + // } else { + // if (failedFetch) { + // return ( + //
+ //

failed to get show :(

+ //
+ // ); + // } else { + // return ( + //
+ //

loading show..

+ //
+ // ); + // } + // } +} diff --git a/src/pages/App.tsx b/src/pages/App.tsx index af2c3bd..7c27ccd 100644 --- a/src/pages/App.tsx +++ b/src/pages/App.tsx @@ -7,6 +7,7 @@ import InfoModule from "../components/modules/InfoModule"; import WelcomeModule from "../components/modules/WelcomeModule"; import FantasyStatus from "../components/FantasyStatus"; import ScoreModule from "../components/modules/ScoreModule"; +import StatModule from "../components/modules/StatModule"; export default function App() { const [selectedImage, setSelectedImage] = useState(""); @@ -38,6 +39,7 @@ export default function App() { + setSelectedImage(url)} />