From b97f3b42e1bad5753728315b5c7ebdacf6f81172 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Mon, 6 Jan 2025 23:48:56 -0800 Subject: initial commit --- app/components/DateWeatherLinks.tsx | 47 +++++++++++++++ app/components/QuickLinks.tsx | 49 ++++++++++++++++ app/components/WhoisChart.tsx | 111 ++++++++++++++++++++++++++++++++++++ 3 files changed, 207 insertions(+) create mode 100644 app/components/DateWeatherLinks.tsx create mode 100644 app/components/QuickLinks.tsx create mode 100644 app/components/WhoisChart.tsx (limited to 'app/components') diff --git a/app/components/DateWeatherLinks.tsx b/app/components/DateWeatherLinks.tsx new file mode 100644 index 0000000..1c004fa --- /dev/null +++ b/app/components/DateWeatherLinks.tsx @@ -0,0 +1,47 @@ +"use client"; + +import { useState, useEffect, useContext } from "react"; +import QuickLinks from "./QuickLinks"; +import { DataContext } from "@/lib/data-context"; + +export default function DateWeatherLinksWelcome() { + const [date, setDate] = useState(new Date()); + const data = useContext(DataContext); + + useEffect(() => { + const timer = setInterval(() => setDate(new Date()), 1000); + return () => clearInterval(timer); + }, []); + + return ( +
+
+
+

+ {date.toLocaleDateString(undefined, { + weekday: "long", + year: "numeric", + month: "long", + day: "numeric", + })} +

+

+ {date.toLocaleTimeString()} +

+
+
+

+ {data?.weather + ? Math.round(data.weather.temperature * (9 / 5) + 32) + "°F" + : "--"} +

+

+ {data?.weather ? data.weather.description : "--"} +

+
+
+
+ +
+ ); +} diff --git a/app/components/QuickLinks.tsx b/app/components/QuickLinks.tsx new file mode 100644 index 0000000..8a853cf --- /dev/null +++ b/app/components/QuickLinks.tsx @@ -0,0 +1,49 @@ +import { + Skull, + Search, + GitPullRequest, + Mail, + Fish, + ChartArea, +} from "lucide-react"; + +export default function QuickLinks() { + const links = [ + { name: "Google", url: "https://www.google.com", icon: Search }, + { name: "Gitea", url: "https://git.simponic.xyz", icon: GitPullRequest }, + { + name: "Mail", + url: "https://roundcube.internal.simponic.xyz", + icon: Mail, + }, + { + name: "Jellyfin", + url: "https://jellyfin.internal.simponic.xyz", + icon: Fish, + }, + { + name: "Uptime Kuma", + url: "https://uptime.internal.simponic.xyz", + icon: ChartArea, + }, + ]; + + return ( +
+ {links.map((link) => { + const Icon = link.icon; + return ( + + + {link.name} + + ); + })} +
+ ); +} diff --git a/app/components/WhoisChart.tsx b/app/components/WhoisChart.tsx new file mode 100644 index 0000000..43f5eb9 --- /dev/null +++ b/app/components/WhoisChart.tsx @@ -0,0 +1,111 @@ +"use client"; + +import { useContext } from "react"; +import { + LineChart, + Line, + XAxis, + YAxis, + CartesianGrid, + ResponsiveContainer, +} from "recharts"; +import { DataContext } from "@/lib/data-context"; +import { greet } from "@/lib/utils"; + +const colors: Record = { + lizzy: "#d985e6", + alex: "#66d1c3", +}; + +export default function UpdateChart() { + const data = useContext(DataContext); + if (!data.whois) return null; + + const groupedData: { [name: string]: { time: number; value: number }[] } = {}; + data.whois.forEach((update, i, arr) => { + if (!(update.name in groupedData)) groupedData[update.name] = []; + const msPerHour = 60 * 60 * 1000; + + if (i === arr.length - 1) { + const now = new Date(); + groupedData[update.name].push({ time: update.time, value: 0 }); + groupedData[update.name].push({ + time: now.getTime(), + value: (now.getTime() - update.time) / msPerHour, + }); + } + + if (i === 0) return; + const prev = arr[i - 1]; + + groupedData[prev.name].push({ time: prev.time, value: 0 }); + groupedData[prev.name].push({ + time: update.time, + value: (update.time - prev.time) / msPerHour, + }); + groupedData[prev.name].push({ time: update.time, value: 0 }); + }); + + const uniqueNames = Object.keys(groupedData); + const chartData = Object.entries(groupedData) + .flatMap(([name, dataPoints]) => + dataPoints.map((data) => ({ time: data.time, name, [name]: data.value })) + ) + .sort((a, b) => a.time - b.time); + + return ( +
+
+

+ {greet(data.whois ? data.whois[0].name : "Friend", new Date())} +

+
+ +
+ + + + new Date(tick).toLocaleTimeString()} + stroke="rgba(var(--foreground), 0.6)" + /> + (tick === 0 ? "" : `${tick} hrs`)} + /> + {uniqueNames.map((uniqueName, index) => ( + name === uniqueName)} + name={uniqueName} + stroke={colors[uniqueName] ?? "#ff0000"} + strokeWidth={3} + dot={false} + isAnimationActive={false} + /> + ))} + + +
+
+ {Object.keys(groupedData).map((name) => ( + + {name} + + ))} +
+
+ ); +} -- cgit v1.2.3-70-g09d2