From 6f26df1939fa4619f3a1b3d1f3ff672347a1f731 Mon Sep 17 00:00:00 2001 From: Xevion Date: Thu, 24 Oct 2024 04:18:16 -0500 Subject: [PATCH] Update frontend to use new IP listing feature --- frontend/src/App.tsx | 64 +++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 522232d..f451ef9 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,26 +1,32 @@ import { useEffect, useState } from 'react'; -const backendUrl = import.meta.env.PROD ? '/api' : `http://${import.meta.env.VITE_BACKEND_TARGET}/api`; +const backendUrl = import.meta.env.PROD + ? '/api' + : `http://${import.meta.env.VITE_BACKEND_TARGET}/api`; const Code = (props: JSX.IntrinsicElements['code']) => ( ); +type SeenIP = { + last_seen: string; + ip: string; + count: number; +}; + export default function App() { - const [time, setTime] = useState(null); - const [clientIp, setClientIp] = useState(null); + const [seenIps, setSeenIps] = useState([]); const refreshData = async () => { try { - const response = await fetch(`${backendUrl}/test`); + const response = await fetch(`${backendUrl}/ips`); const data = await response.json(); - const { time, ip } = data; - setTime(time); - setClientIp(ip); + setSeenIps(data.ips); + console.log('Data fetched:', data); } catch (error) { console.error('Error fetching data:', error); } @@ -30,24 +36,40 @@ export default function App() { useEffect(() => { refreshData(); - const interval = setInterval(() => { - refreshData(); - }, (import.meta.env.DEV ? 1 : 30) * 1000); + const interval = setInterval( + () => { + refreshData(); + }, + (import.meta.env.DEV ? 3 : 30) * 1000, + ); return () => clearInterval(interval); }, []); return ( -
-
-

LinkPulse

-

- The current time is: {time || 'N/A'} -

-

- Your IP address is: {clientIp || 'N/A'} -

-
+
+
+

LinkPulse

+ +
+ + + {seenIps.map((ip) => ( + + + + + + ))} + + +
+ {ip.ip} + + {ip.count} time{ip.count > 1 ? 's' : ''} + {ip.last_seen}
+
+
); }