earthquakes on home page

This commit is contained in:
IZZY 2025-05-31 11:55:57 +01:00
parent 17672177c6
commit b73114afd1
3 changed files with 226 additions and 139 deletions

View File

@ -94,7 +94,7 @@ export default function Earthquakes() {
const [searchModalOpen, setSearchModalOpen] = useState(false); const [searchModalOpen, setSearchModalOpen] = useState(false);
// Fetch recent earthquakes as before // Fetch recent earthquakes as before
const { data, error, isLoading } = useSWR("/api/earthquakes", createPoster({ rangeDaysPrev: 5 })); const { data, error, isLoading } = useSWR("/api/earthquakes", createPoster({ rangeDaysPrev: 10 }));
// Prepare events for maps/sidebar // Prepare events for maps/sidebar
const earthquakeEvents = useMemo( const earthquakeEvents = useMemo(
@ -144,7 +144,7 @@ export default function Earthquakes() {
setHoveredEventId={setHoveredEventId} setHoveredEventId={setHoveredEventId}
button1Name="Log an Earthquake" button1Name="Log an Earthquake"
button2Name="Search Earthquakes" button2Name="Search Earthquakes"
onButton2Click={() => setSearchModalOpen(true)} // <-- important! onButton2Click={() => setSearchModalOpen(true)}
/> />
<EarthquakeSearchModal <EarthquakeSearchModal
open={searchModalOpen} open={searchModalOpen}

View File

@ -1,18 +1,38 @@
"use client";
import useSWR from "swr";
import Image from "next/image"; import Image from "next/image";
import Link from "next/link"; import Link from "next/link";
import BottomFooter from "@components/BottomFooter"; import BottomFooter from "@components/BottomFooter";
import { createPoster } from "@utils/axiosHelpers";
// formats the date
function getRelativeDate(dateString: string): string {
const date = new Date(dateString);
const now = new Date();
const diffMs = now.getTime() - date.getTime();
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
if (diffDays === 0) return "today";
if (diffDays === 1) return "yesterday";
return date.toLocaleDateString();
}
export default function Home() { export default function Home() {
const { data, error, isLoading } = useSWR("/api/earthquakes", createPoster({ rangeDaysPrev: 6 }));
// Take 5 most recent
const recents = (data?.earthquakes ?? [])
.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())
.slice(0, 5);
return ( return (
<main className="min-h-screen text-black"> <main className="min-h-screen text-black">
<div className="w-full relative"> <div className="w-full relative">
<div className=""> <div>
<Image height={2000} width={2000} alt="Background Image" src="/lava_flows.jpg"></Image> <Image height={2000} width={2000} alt="Background Image" src="/lava_flows.jpg" />
</div> </div>
<div className="absolute inset-0 bg-gradient-to-b from-transparent via-black/10 to-black/40"></div> <div className="absolute inset-0 bg-gradient-to-b from-transparent via-black/10 to-black/40"></div>
<div className="absolute inset-0 top-[30%]"> <div className="absolute inset-0 top-[30%]">
<Image className="mx-auto" height={300} width={1000} alt="Title Image" src="/tremortrackertext.png"></Image> <Image className="mx-auto" height={300} width={1000} alt="Title Image" src="/tremortrackertext.png" />
</div> </div>
</div> </div>
<p className="mt-2"></p> <p className="mt-2"></p>
@ -45,8 +65,8 @@ export default function Home() {
<p className="mt-18"></p> <p className="mt-18"></p>
<section className="min-h-screen text-black"> <section className="min-h-screen text-black">
<div className="w-full relative z-40"> <div className="w-full relative z-40">
<div className=""> <div>
<Image height={2500} width={2000} alt="Background Image" src="/earthquakesMap.jpg"></Image> <Image height={2500} width={2000} alt="Background Image" src="/earthquakesMap.jpg" />
</div> </div>
<div className="border absolute top-0 inset-0 bg-gradient-to-b from-transparent via-black/10 to-black/40"> <div className="border absolute top-0 inset-0 bg-gradient-to-b from-transparent via-black/10 to-black/40">
<section className="relative z-10 flex flex-col items-center text-center w-full px-4 py-14 mt-6"> <section className="relative z-10 flex flex-col items-center text-center w-full px-4 py-14 mt-6">
@ -84,23 +104,68 @@ export default function Home() {
</section> </section>
<p className="mt-20"></p> <p className="mt-20"></p>
<section className="relative z-10 flex flex-col items-start text-left w-5/6 mx-auto px-2 -mt-5 mb-2"> <section className="relative z-10 flex flex-col items-start text-left w-5/6 mx-auto px-2 -mt-5 mb-2">
<h1 className="text-3xl md:text-3xl font-bold text-black drop-shadow-lg mb-3 tracking-tight">Recent Earthquake Events</h1> <h1 className="text-3xl md:text-3xl font-bold text-black drop-shadow-lg mb-3 tracking-tight">
Recent Earthquake Events
</h1>
<p className="text-lg md:text-xl text-black drop-shadow-md"> <p className="text-lg md:text-xl text-black drop-shadow-md">
Learn about the most recent earthquake events from around the world: Learn about the most recent earthquake events from around the world:
</p> </p>
</section> </section>
<p className="mt-6"></p> <p className="mt-6"></p>
<div className="mx-auto w-5/6 px-2 border border-black divide-y bg-white bg-opacity-90 rounded-xl shadow-md"> <div className="mx-auto w-5/6 px-2">
{["Earthquake 1", "Earthquake 2", "Earthquake 3", "Earthquake 4", "Earthquake 5"].map((name) => ( {error && (
<div className="px-5 py-5" key={name}> <div className="border rounded-xl bg-white bg-opacity-90 shadow-md p-4 mb-2">
<p className="ml-3">{name}</p> <p>Failed to load earthquakes.</p>
<p></p> </div>
)}
{isLoading && (
<div className="border rounded-xl bg-white bg-opacity-90 shadow-md p-4 mb-2">
<p>Loading...</p>
</div>
)}
{!isLoading && recents.length === 0 && (
<div className="border rounded-xl bg-white bg-opacity-90 shadow-md p-4 mb-2">
<p>No earthquakes found.</p>
</div>
)}
<div className="flex flex-col gap-4">
{recents.map((eq) => (
<div
key={eq.code}
className="flex items-center justify-between p-4 bg-white rounded-xl shadow border"
>
<div>
<div className="font-semibold">
Earthquake in {eq.location || (eq.code && eq.code.split("-")[2])}
</div>
<div className="text-sm text-gray-500">
{getRelativeDate(eq.date)}
</div>
</div>
<span
className={`flex items-center justify-center font-bold text-md ml-2 rounded-full border-2 border-current
${
eq.magnitude >= 7
? "text-red-600 border-red-600"
: eq.magnitude >= 6
? "text-orange-500 border-orange-500"
: "text-yellow-500 border-yellow-500"
}
min-w-[2.8rem] min-h-[2.8rem] max-h-12 max-w-12`}
style={{ aspectRatio: "1 / 1" }}
title={`Magnitude ${eq.magnitude}`}
>
{eq.magnitude}
</span>
</div> </div>
))} ))}
</div> </div>
</div>
<p className="mt-20"></p> <p className="mt-20"></p>
<section className="relative z-10 flex flex-col items-start text-left w-5/6 mx-auto px-2 -mt-5 mb-2"> <section className="relative z-10 flex flex-col items-start text-left w-5/6 mx-auto px-2 -mt-5 mb-2">
<h1 className="text-3xl md:text-3xl font-bold text-black drop-shadow-lg mb-3 tracking-tight">Contact Information</h1> <h1 className="text-3xl md:text-3xl font-bold text-black drop-shadow-lg mb-3 tracking-tight">
Contact Information
</h1>
<p className="text-lg md:text-xl text-black drop-shadow-md"> <p className="text-lg md:text-xl text-black drop-shadow-md">
Learn about Tremor Tracker's mission, our team or contact us directly: Learn about Tremor Tracker's mission, our team or contact us directly:
</p> </p>
@ -132,8 +197,8 @@ export default function Home() {
<p className="mt-10"></p> <p className="mt-10"></p>
<section style={{ height: 500 }} className="text-black"> <section style={{ height: 500 }} className="text-black">
<div className="w-full relative overflow-hidden z=10"> <div className="w-full relative overflow-hidden z=10">
<div className=""> <div>
<Image height={1000} width={2000} alt="Background Image" src="/scientists.png"></Image> <Image height={1000} width={2000} alt="Background Image" src="/scientists.png" />
</div> </div>
<BottomFooter /> <BottomFooter />
</div> </div>
@ -141,6 +206,7 @@ export default function Home() {
</main> </main>
); );
// return ( // return (
// <div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]"> // <div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]">
// <main className="flex flex-col gap-8 row-start-2 items-center sm:items-start"> // <main className="flex flex-col gap-8 row-start-2 items-center sm:items-start">

21
src/databases/Users.csv Normal file
View File

@ -0,0 +1,21 @@
name,email,password,level
undefined,undefined,undefined,undefined
undefined,undefined,undefined,undefined
undefined,undefined,undefined,undefined
undefined,undefined,undefined,undefined
undefined,undefined,undefined,undefined
undefined,undefined,undefined,undefined
undefined,undefined,undefined,undefined
undefined,undefined,undefined,undefined
undefined,undefined,undefined,undefined
undefined,undefined,undefined,undefined
undefined,undefined,undefined,undefined
undefined,undefined,undefined,undefined
undefined,undefined,undefined,undefined
undefined,undefined,undefined,undefined
undefined,undefined,undefined,undefined
undefined,undefined,undefined,undefined
undefined,undefined,undefined,undefined
undefined,undefined,undefined,undefined
undefined,undefined,undefined,undefined
undefined,undefined,undefined,undefined
1 name email password level
2 undefined undefined undefined undefined
3 undefined undefined undefined undefined
4 undefined undefined undefined undefined
5 undefined undefined undefined undefined
6 undefined undefined undefined undefined
7 undefined undefined undefined undefined
8 undefined undefined undefined undefined
9 undefined undefined undefined undefined
10 undefined undefined undefined undefined
11 undefined undefined undefined undefined
12 undefined undefined undefined undefined
13 undefined undefined undefined undefined
14 undefined undefined undefined undefined
15 undefined undefined undefined undefined
16 undefined undefined undefined undefined
17 undefined undefined undefined undefined
18 undefined undefined undefined undefined
19 undefined undefined undefined undefined
20 undefined undefined undefined undefined
21 undefined undefined undefined undefined