From d3f91c2ff1c5d58f967fb1785dc7a41037421a6f Mon Sep 17 00:00:00 2001 From: Alex Frantz Date: Tue, 24 Dec 2024 01:11:29 -0500 Subject: [PATCH] update to new content tracker endpoints --- .../ProjectComponents/RecentBook.tsx | 28 ++++-------------- .../ProjectComponents/RecentWatch.tsx | 21 ++++++-------- src/utils/types.ts | 29 +++++++++++++------ 3 files changed, 35 insertions(+), 43 deletions(-) diff --git a/src/components/ProjectComponents/RecentBook.tsx b/src/components/ProjectComponents/RecentBook.tsx index 1a03624..cb49db4 100644 --- a/src/components/ProjectComponents/RecentBook.tsx +++ b/src/components/ProjectComponents/RecentBook.tsx @@ -1,37 +1,21 @@ import { useState, useEffect } from 'react'; import ProjectComponent from '../ProjectComponent'; - -type BookDataResponse = { - status: number, - data: BookData -}; -type BookData = { - id: number, - title: string, - author: string, - description: string, - imageKey: string, - finished: boolean, - startedOn: Date, - createdAt: Date, - updatedAt: Date, - createdById: string -} +import type { ContentTrackerItem } from '../../utils/types'; export default function RecentBook() { - const [ data, setData ] = useState(null); + const [ data, setData ] = useState(null); const [ loading, setLoading ] = useState(true); const [ errorState, setErrorState ] = useState(""); useEffect(() => { - fetch("https://api.alexav.gg/v4/social/books", { + fetch("https://api.alexav.gg/v4/tracker/latest/book", { method: 'get' }) .then(async (res) => { if (res.ok) { - const json = await res.json() as BookDataResponse; + const json = await res.json(); setData(json.data); - setLoading(false) + setLoading(false); } else { setErrorState("Failed to fetch data!"); setLoading(false); @@ -61,7 +45,7 @@ export default function RecentBook() { projectHeader={data.title} projectSubheader={getDateString(data.startedOn, data.finished)} url={"https://tracker.alexav.gg/?type=books&id=" + data.id} - projectImage={data.imageKey} + projectImage={data.image} /> ) } else { diff --git a/src/components/ProjectComponents/RecentWatch.tsx b/src/components/ProjectComponents/RecentWatch.tsx index df6b7c1..9e7d3e0 100644 --- a/src/components/ProjectComponents/RecentWatch.tsx +++ b/src/components/ProjectComponents/RecentWatch.tsx @@ -1,19 +1,16 @@ import { useState, useEffect } from 'react'; import ProjectComponent from '../ProjectComponent'; -type WatchDataResponse = { - status: number, - data: WatchData -}; type WatchData = { id: number, title: string, description: string, - imageKey: string, - currentEpisode: string, - tmdbID: string, + author?: string, + image: string, + episode?: string, + tmdbId?: string, finished: boolean, - startedOn: Date, + startedOn?: Date, createdAt: Date, updatedAt: Date, createdById: string @@ -25,12 +22,12 @@ export default function RecentWatch() { const [ errorState, setErrorState ] = useState(""); useEffect(() => { - fetch("https://api.alexav.gg/v4/social/watch", { + fetch("https://api.alexav.gg/v4/tracker/latest/tv", { method: 'get' }) .then(async (res) => { if (res.ok) { - const json = await res.json() as WatchDataResponse; + const json = await res.json(); setData(json.data); setLoading(false) } else { @@ -48,7 +45,7 @@ export default function RecentWatch() { if (data?.finished) { return "Finished!" } else if (data?.startedOn) { - return "Started on " + new Date(data.startedOn).toLocaleDateString() + return "Last update on " + new Date(data.updatedAt).toLocaleDateString() } else { return "Just Added" } @@ -61,7 +58,7 @@ export default function RecentWatch() { projectHeader={data.title} projectSubheader={ getSubheaderText() } url={"https://tracker.alexav.gg/?type=tv&id=" + data.id} - projectImage={data.imageKey} + projectImage={data.image} /> ) } else { diff --git a/src/utils/types.ts b/src/utils/types.ts index 618c63f..794e6ad 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -1,9 +1,4 @@ -type MusicAPIResponse = { - data: { - tracks: MusicData[] - } -} - +// music type type MusicData = { artist: { mbid: string, @@ -18,13 +13,29 @@ type MusicData = { url: string, image: MusicImage[] } - type MusicImage = { size: string, "#text": string } +// tracker type +type ContentTrackerItem = { + id: number, + title: string, + author?: string, + description: string, + episode?: string, + image: string, + type: "tv" | "book" | "game", + tmdbId?: string, + yearReleased: number, + updatedAt: Date, + genre: string, + startedOn: Date, + finished: boolean +} + export type { - MusicAPIResponse, - MusicData + MusicData, + ContentTrackerItem } \ No newline at end of file