diff --git a/src/components/ProjectComponents/RecentBook.tsx b/src/components/ProjectComponents/RecentBook.tsx new file mode 100644 index 0000000..ff49e7e --- /dev/null +++ b/src/components/ProjectComponents/RecentBook.tsx @@ -0,0 +1,71 @@ +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 +} + +export default function RecentWatch() { + const [ data, setData ] = useState(null); + const [ loading, setLoading ] = useState(true); + const [ errorState, setErrorState ] = useState(""); + + useEffect(() => { + fetch("https://api.alexav.gg/v4/social/books", { + method: 'get' + }) + .then(async (res) => { + if (res.ok) { + const json = await res.json() as BookDataResponse; + setData(json.data); + setLoading(false) + } else { + setErrorState("Failed to fetch data!"); + setLoading(false); + } + }) + .catch((e) => { + setLoading(false); + setErrorState(e.message) + }) + }, []); + + const parseDate = (date: Date) => { + const jsDate = new Date(date); + return `${jsDate.getFullYear()}/${jsDate.getMonth() + 1}/${jsDate.getDate()}`; + } + + if (data && !loading) { + return ( + + ) + } else { + return ( + <> +

No data :(

+

Check out tracker.alexav.gg if this isn't working.

+

{errorState}

+ + ) + } +} \ No newline at end of file diff --git a/src/components/ProjectComponents/RecentWatch.tsx b/src/components/ProjectComponents/RecentWatch.tsx index 0a7c52f..772fd88 100644 --- a/src/components/ProjectComponents/RecentWatch.tsx +++ b/src/components/ProjectComponents/RecentWatch.tsx @@ -55,7 +55,7 @@ export default function RecentWatch() { header={"What I'm watching"} projectHeader={data.title} projectSubheader={ data.finished ? "Finished!" : "Started on " + parseDate(data.startedOn) } - url={"https://watch.alexav.gg/?id=" + data.id} + url={"https://tracker.alexav.gg/?type=tv&id=" + data.id} projectImage={data.imageKey} projectImageSize={"30"} /> @@ -64,7 +64,7 @@ export default function RecentWatch() { return ( <>

No data :(

-

Check out watch.alexav.gg if this isn't working.

+

Check out tracker.alexav.gg if this isn't working.

{errorState}

)