From b9d5fbdad5db9e02256aa9e3366dde0a57f1c6da Mon Sep 17 00:00:00 2001 From: Alex Frantz Date: Sun, 21 Jul 2024 03:50:59 -0400 Subject: [PATCH] add recent photos --- src/components/Footer.tsx | 2 +- src/components/RecentPhoto.tsx | 87 ++++++++++++++++++++++++++++++++++ src/components/RecentWatch.tsx | 3 +- src/index.tsx | 21 +++++++- 4 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 src/components/RecentPhoto.tsx diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index 44670fa..dcfcef7 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -11,7 +11,7 @@ export default function Footer() { }, [mailState]) return ( -
+

© {new Date().getFullYear()}, Alex Frantz. All Rights Reserved

All logos & images on this page belong to their respective owners.

diff --git a/src/components/RecentPhoto.tsx b/src/components/RecentPhoto.tsx new file mode 100644 index 0000000..f7f6ae3 --- /dev/null +++ b/src/components/RecentPhoto.tsx @@ -0,0 +1,87 @@ +import { useState, useEffect } from 'react'; + +type PhotoDataResponse = { + result: { + data: { + json: PhotoData[] + } + } +}; +type PhotoData = { + id: number, + name: string, + imageUrl: string, + dateTaken: Date +} + +export default function RecentPhoto() { + const [ data, setData ] = useState(null); + const [ loading, setLoading ] = useState(true); + const [ errorState, setErrorState ] = useState(null); + + useEffect(() => { + console.log(data) + }, [data]) + + useEffect(() => { + fetch("https://photos-cors.alexav.gg", { + method: 'get', + headers: { + 'content-type': 'application/json' + } + }) + .then(async (res) => { + if (res.ok) { + console.log("ok!") + console.log(errorState) + const json = await res.json() as PhotoDataResponse[]; + setData(json[0].result.data.json); + setLoading(false) + } else { + console.log("not ok :(") + 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()}`; + } + + return ( + + + + ) + +} \ No newline at end of file diff --git a/src/components/RecentWatch.tsx b/src/components/RecentWatch.tsx index b301b12..8d598ec 100644 --- a/src/components/RecentWatch.tsx +++ b/src/components/RecentWatch.tsx @@ -53,7 +53,7 @@ export default function RecentWatch() { return ( -
+
{ loading ? (

Loading..

@@ -81,6 +81,7 @@ export default function RecentWatch() { <>

Failed to fetch :(

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

+

{errorState}

) } diff --git a/src/index.tsx b/src/index.tsx index 5eaf376..c4bf901 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -4,6 +4,7 @@ import ListBox from "./components/ListBox"; import Project from "./components/Project"; import ContactForm from "./components/ContactForm"; import RecentWatch from "./components/RecentWatch"; +import RecentPhoto from "./components/RecentPhoto"; export default function Home() { return ( @@ -41,14 +42,30 @@ export default function Home() {
-

What am I watching?

+
+

What am I watching?

+

Cool shows and movies I'm watching

+
-
+
+
+
+
+

What am I picturing?

+

Cool game photos I've taken recently

+
+
+
+ +
+
+
+