2025-03-23 15:24:10 +00:00
|
|
|
"use client";
|
|
|
|
|
|
2025-05-27 13:22:42 +01:00
|
|
|
import { useMemo, useState } from "react";
|
2025-05-04 16:04:44 +01:00
|
|
|
import useSWR from "swr";
|
2025-04-28 19:03:29 +01:00
|
|
|
|
2025-05-12 13:25:57 +01:00
|
|
|
import Map from "@components/Map";
|
2025-05-04 16:04:44 +01:00
|
|
|
import Sidebar from "@components/Sidebar";
|
2025-05-27 13:22:42 +01:00
|
|
|
import { createPoster } from "@utils/axiosHelpers";
|
2025-05-27 13:12:19 +01:00
|
|
|
import { Earthquake } from "@prismaclient";
|
|
|
|
|
import { getRelativeDate } from "@utils/formatters";
|
2025-03-19 19:43:34 +00:00
|
|
|
|
2025-03-17 13:21:02 +00:00
|
|
|
export default function Earthquakes() {
|
2025-04-28 19:03:29 +01:00
|
|
|
const [selectedEventId, setSelectedEventId] = useState("");
|
|
|
|
|
const [hoveredEventId, setHoveredEventId] = useState("");
|
2025-04-29 18:50:03 +01:00
|
|
|
// todo properly integrate loading
|
2025-05-26 22:16:46 +01:00
|
|
|
const { data, error, isLoading } = useSWR("/api/earthquakes", createPoster({ rangeDaysPrev: 5 }));
|
2025-03-23 15:24:10 +00:00
|
|
|
|
2025-05-27 13:12:19 +01:00
|
|
|
const earthquakeEvents = useMemo(
|
|
|
|
|
() =>
|
|
|
|
|
data && data.earthquakes
|
|
|
|
|
? data.earthquakes.map((x: Earthquake) => ({
|
|
|
|
|
id: x.id,
|
|
|
|
|
title: `Earthquake in ${x.code.split("-")[2]}`,
|
|
|
|
|
magnitude: x.magnitude,
|
|
|
|
|
longitude: x.longitude,
|
|
|
|
|
latitude: x.latitude,
|
|
|
|
|
text2: getRelativeDate(x.date),
|
|
|
|
|
}))
|
|
|
|
|
: [],
|
|
|
|
|
[data]
|
|
|
|
|
);
|
|
|
|
|
|
2025-04-28 19:03:29 +01:00
|
|
|
return (
|
2025-05-27 13:22:42 +01:00
|
|
|
<div className="flex h-[calc(100vh-3.5rem)] w-full overflow-hidden">
|
|
|
|
|
<div className="flex-grow h-full">
|
2025-04-28 19:03:29 +01:00
|
|
|
<Map
|
2025-05-27 13:12:19 +01:00
|
|
|
events={earthquakeEvents}
|
2025-04-28 19:03:29 +01:00
|
|
|
selectedEventId={selectedEventId}
|
|
|
|
|
setSelectedEventId={setSelectedEventId}
|
|
|
|
|
hoveredEventId={hoveredEventId}
|
|
|
|
|
setHoveredEventId={setHoveredEventId}
|
|
|
|
|
mapType="Earthquakes"
|
2025-05-27 13:22:42 +01:00
|
|
|
/>
|
2025-04-28 19:03:29 +01:00
|
|
|
</div>
|
|
|
|
|
<Sidebar
|
|
|
|
|
logTitle="Log an Earthquake"
|
|
|
|
|
logSubtitle="Record new earthquakes - time/date, location, magnitude, observatory and scientists"
|
|
|
|
|
recentsTitle="Recent Earthquakes"
|
2025-05-27 13:12:19 +01:00
|
|
|
events={earthquakeEvents}
|
2025-04-28 19:03:29 +01:00
|
|
|
selectedEventId={selectedEventId}
|
|
|
|
|
setSelectedEventId={setSelectedEventId}
|
|
|
|
|
hoveredEventId={hoveredEventId}
|
|
|
|
|
setHoveredEventId={setHoveredEventId}
|
|
|
|
|
button1Name="Log an Earthquake"
|
|
|
|
|
button2Name="Search Earthquakes"
|
2025-05-27 13:22:42 +01:00
|
|
|
/>
|
2025-04-28 19:03:29 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
2025-03-19 19:20:18 +00:00
|
|
|
}
|