Fixed sidebar scrolling
This commit is contained in:
parent
eb0ef3677a
commit
3d2b71c768
@ -1,11 +1,11 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
|
||||||
import Map from "@components/Map";
|
import Map from "@components/Map";
|
||||||
import Sidebar from "@components/Sidebar";
|
import Sidebar from "@components/Sidebar";
|
||||||
import { createPoster, fetcher } from "@utils/axiosHelpers";
|
import { createPoster } from "@utils/axiosHelpers";
|
||||||
import { Earthquake } from "@prismaclient";
|
import { Earthquake } from "@prismaclient";
|
||||||
import { getRelativeDate } from "@utils/formatters";
|
import { getRelativeDate } from "@utils/formatters";
|
||||||
|
|
||||||
@ -20,7 +20,6 @@ export default function Earthquakes() {
|
|||||||
data && data.earthquakes
|
data && data.earthquakes
|
||||||
? data.earthquakes.map((x: Earthquake) => ({
|
? data.earthquakes.map((x: Earthquake) => ({
|
||||||
id: x.id,
|
id: x.id,
|
||||||
// e.g Earthquake in Germany
|
|
||||||
title: `Earthquake in ${x.code.split("-")[2]}`,
|
title: `Earthquake in ${x.code.split("-")[2]}`,
|
||||||
magnitude: x.magnitude,
|
magnitude: x.magnitude,
|
||||||
longitude: x.longitude,
|
longitude: x.longitude,
|
||||||
@ -32,8 +31,8 @@ export default function Earthquakes() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-full flex overflow-hidden">
|
<div className="flex h-[calc(100vh-3.5rem)] w-full overflow-hidden">
|
||||||
<div className="flex-grow">
|
<div className="flex-grow h-full">
|
||||||
<Map
|
<Map
|
||||||
events={earthquakeEvents}
|
events={earthquakeEvents}
|
||||||
selectedEventId={selectedEventId}
|
selectedEventId={selectedEventId}
|
||||||
@ -41,7 +40,7 @@ export default function Earthquakes() {
|
|||||||
hoveredEventId={hoveredEventId}
|
hoveredEventId={hoveredEventId}
|
||||||
setHoveredEventId={setHoveredEventId}
|
setHoveredEventId={setHoveredEventId}
|
||||||
mapType="Earthquakes"
|
mapType="Earthquakes"
|
||||||
></Map>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Sidebar
|
<Sidebar
|
||||||
logTitle="Log an Earthquake"
|
logTitle="Log an Earthquake"
|
||||||
@ -54,7 +53,7 @@ export default function Earthquakes() {
|
|||||||
setHoveredEventId={setHoveredEventId}
|
setHoveredEventId={setHoveredEventId}
|
||||||
button1Name="Log an Earthquake"
|
button1Name="Log an Earthquake"
|
||||||
button2Name="Search Earthquakes"
|
button2Name="Search Earthquakes"
|
||||||
></Sidebar>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useMemo, useState } from "react";
|
import { useState } from "react";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
|
||||||
import Sidebar from "@/components/Sidebar";
|
import Sidebar from "@/components/Sidebar";
|
||||||
@ -14,8 +14,8 @@ export default function Observatories() {
|
|||||||
const { data, error, isLoading } = useSWR("/api/observatories", fetcher);
|
const { data, error, isLoading } = useSWR("/api/observatories", fetcher);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-full flex overflow-hidden">
|
<div className="flex h-[calc(100vh-3.5rem)] w-full overflow-hidden">
|
||||||
<div className="flex-grow">
|
<div className="flex-grow h-full">
|
||||||
<Map
|
<Map
|
||||||
events={data ? data.observatories : []}
|
events={data ? data.observatories : []}
|
||||||
selectedEventId={selectedEventId}
|
selectedEventId={selectedEventId}
|
||||||
@ -23,7 +23,7 @@ export default function Observatories() {
|
|||||||
hoveredEventId={hoveredEventId}
|
hoveredEventId={hoveredEventId}
|
||||||
setHoveredEventId={setHoveredEventId}
|
setHoveredEventId={setHoveredEventId}
|
||||||
mapType="observatories"
|
mapType="observatories"
|
||||||
></Map>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Sidebar
|
<Sidebar
|
||||||
logTitle="Observatory Mapping"
|
logTitle="Observatory Mapping"
|
||||||
@ -36,8 +36,7 @@ export default function Observatories() {
|
|||||||
setHoveredEventId={setHoveredEventId}
|
setHoveredEventId={setHoveredEventId}
|
||||||
button1Name="Log a New Observatory"
|
button1Name="Log a New Observatory"
|
||||||
button2Name="Search Observatories"
|
button2Name="Search Observatories"
|
||||||
></Sidebar>
|
/>
|
||||||
{/* <SidebarTest></SidebarTest> */}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,13 +19,11 @@ interface SidebarProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function MagnitudeNumber({ magnitude }: { magnitude: number }) {
|
function MagnitudeNumber({ magnitude }: { magnitude: number }) {
|
||||||
// Convert magnitude to string with one decimal place
|
|
||||||
const magnitudeStr = magnitude.toFixed(1);
|
const magnitudeStr = magnitude.toFixed(1);
|
||||||
const [whole, decimal] = magnitudeStr.split(".");
|
const [whole, decimal] = magnitudeStr.split(".");
|
||||||
|
|
||||||
// Define color based on magnitude (0-10 scale)
|
|
||||||
return (
|
return (
|
||||||
<div className={`relative`} style={{ color: getMagnitudeColor(magnitude) }}>
|
<div className="relative" style={{ color: getMagnitudeColor(magnitude) }}>
|
||||||
<TbHexagon size={40} className="drop-shadow-sm" />
|
<TbHexagon size={40} className="drop-shadow-sm" />
|
||||||
<div className="absolute inset-0 flex items-center justify-center">
|
<div className="absolute inset-0 flex items-center justify-center">
|
||||||
<div className="flex items-baseline font-mono font-bold tracking-tight">
|
<div className="flex items-baseline font-mono font-bold tracking-tight">
|
||||||
@ -50,14 +48,12 @@ export default function Sidebar({
|
|||||||
button1Name,
|
button1Name,
|
||||||
button2Name,
|
button2Name,
|
||||||
}: SidebarProps) {
|
}: SidebarProps) {
|
||||||
// todo add buttons 1 and 2 click handlers
|
|
||||||
return (
|
return (
|
||||||
<div className={`flex flex-col h-full w-80 relative bg-gradient-to-b from-neutral-100 to-neutral-50 shadow-lg`}>
|
<div className="flex flex-col h-full w-80 bg-gradient-to-b from-neutral-100 to-neutral-50 shadow-lg">
|
||||||
<div className="py-6">
|
<div className="py-6 flex flex-col h-full">
|
||||||
<div className="px-6 pb-8 border-b border-neutral-200">
|
<div className="px-6 pb-8 border-b border-neutral-200">
|
||||||
<h2 className={`text-2xl font-bold text-neutral-800 mb-2`}>{logTitle}</h2>
|
<h2 className="text-2xl font-bold text-neutral-800 mb-2">{logTitle}</h2>
|
||||||
<p className="text-sm text-neutral-600 leading-relaxed">{logSubtitle}</p>
|
<p className="text-sm text-neutral-600 leading-relaxed">{logSubtitle}</p>
|
||||||
|
|
||||||
<Link href="/">
|
<Link href="/">
|
||||||
<button className="mt-4 w-full bg-blue-600 hover:bg-blue-700 text-white py-2 px-4 rounded-lg transition-colors duration-200 font-medium">
|
<button className="mt-4 w-full bg-blue-600 hover:bg-blue-700 text-white py-2 px-4 rounded-lg transition-colors duration-200 font-medium">
|
||||||
{button1Name}
|
{button1Name}
|
||||||
@ -69,9 +65,10 @@ export default function Sidebar({
|
|||||||
</button>
|
</button>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="px-6 pt-6">
|
||||||
<div className="flex-1 px-6 pt-6 overflow-y-auto">
|
<h2 className="text-xl font-bold text-neutral-800 mb-2">{recentsTitle}</h2>
|
||||||
<h2 className="text-xl font-bold text-neutral-800 mb-4">{recentsTitle}</h2>
|
</div>
|
||||||
|
<div className="flex-1 px-6 overflow-y-auto pt-2">
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
{events.map((event) => (
|
{events.map((event) => (
|
||||||
<button
|
<button
|
||||||
@ -86,10 +83,8 @@ export default function Sidebar({
|
|||||||
onMouseLeave={() => setHoveredEventId("")}
|
onMouseLeave={() => setHoveredEventId("")}
|
||||||
>
|
>
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<p className="text-sm font-medium text-neutral-800">{event.title}</p>
|
<p className="text-sm font-medium text-neutral-800 truncate">{event.title}</p>
|
||||||
{/* Uncomment if you want to use text1 */}
|
<p className="text-xs text-neutral-500 mt-1 truncate">{event.text2}</p>
|
||||||
{/* <p className="text-xs text-neutral-600">{event.text1}</p> */}
|
|
||||||
<p className="text-xs text-neutral-500 mt-1">{event.text2}</p>
|
|
||||||
</div>
|
</div>
|
||||||
{event.magnitude ? <MagnitudeNumber magnitude={event.magnitude} /> : <></>}
|
{event.magnitude ? <MagnitudeNumber magnitude={event.magnitude} /> : <></>}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user