+ setSearchModalOpen(true)} // <-- important!
+ />
+ setSearchModalOpen(false)}
+ onSelect={eq => {
+ setSelectedEventId(eq.code); // select on map/sidebar
+ // setSelectedSearchResult(eq); // you can use this if you want to show detail modal
+ }}
+ />
+
+ );
+}
\ No newline at end of file
diff --git a/src/app/earthquakes/search/route.ts b/src/app/earthquakes/search/route.ts
new file mode 100644
index 0000000..48ca6c9
--- /dev/null
+++ b/src/app/earthquakes/search/route.ts
@@ -0,0 +1,25 @@
+import { NextResponse } from "next/server";
+import { prisma } from "@utils/prisma";
+
+export async function POST(req: Request) {
+ try {
+ const { query } = await req.json();
+
+ // Find earthquakes where either code or location matches (case-insensitive)
+ const earthquakes = await prisma.earthquake.findMany({
+ where: {
+ OR: [
+ { code: { contains: query, mode: "insensitive" } },
+ { location: { contains: query, mode: "insensitive" } }
+ ],
+ },
+ orderBy: { date: "desc" },
+ take: 20, // limit results
+ });
+
+ return NextResponse.json({ earthquakes, message: "Success" });
+ } catch (error) {
+ console.error("Error in earthquake search", error);
+ return NextResponse.json({ message: "Internal Server Error" }, { status: 500 });
+ }
+}
\ No newline at end of file
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx
index d44b733..f9b439e 100644
--- a/src/components/Sidebar.tsx
+++ b/src/components/Sidebar.tsx
@@ -16,6 +16,7 @@ interface SidebarProps {
setHoveredEventId: Dispatch>;
button1Name: string;
button2Name: string;
+ onButton2Click?: () => void;
}
function MagnitudeNumber({ magnitude }: { magnitude: number }) {
@@ -47,6 +48,7 @@ export default function Sidebar({
setHoveredEventId,
button1Name,
button2Name,
+ onButton2Click,
}: SidebarProps) {
const eventsContainerRef = useRef(null);
@@ -68,17 +70,21 @@ export default function Sidebar({
{logTitle}
{logSubtitle}
-
-
-
-
-
-
-
+
+
+
+
+ {/* "Search Earthquakes" should NOT be wrapped in a Link! */}
+
+
{recentsTitle}
diff --git a/src/components/sidebar_e.tsx b/src/components/sidebar_e.tsx
index 6c1dfe6..f2dfcbc 100644
--- a/src/components/sidebar_e.tsx
+++ b/src/components/sidebar_e.tsx
@@ -1,42 +1,73 @@
import Link from "next/link";
import React from "react";
-const Sidebar = () => {
- return (
-
-
-
Log an Earthquake
-
- Record new earthquakes - time/date, location, magnitude, observatory and scientists
-
-
-
+type SidebarProps = {
+ logTitle: string;
+ logSubtitle: string;
+ recentsTitle: string;
+ events: any[]; // Or type this better if desired
+ button1Name: string;
+ button2Name: string;
+ onButton1Click?: () => void;
+ onButton2Click?: () => void;
+}
- {/* Section: Recent Events - Will need to be replaced with a link to the database*/}
-