Spaces:
Running
Running
feat: add dark mode support to navigation and dashboard, implement mobile-first time stepper, and document grid/memory leak patterns.
Browse files- .agents/AGENTS.md +9 -0
- src/app/page.tsx +4 -4
- src/components/DashboardCharts.tsx +1 -1
- src/components/Map.tsx +55 -29
.agents/AGENTS.md
CHANGED
|
@@ -123,6 +123,7 @@ When implementing or modifying MapLibre GL map components and layer rendering:
|
|
| 123 |
2. **Avoid Arbitrary Timers for Style/Source Updates**: Do not use `setTimeout` or other custom timers to coordinate updating a map source after changing the map style (e.g. basemap). Rely on MapLibre's native `'style.load'` event listener to re-add layers and update states.
|
| 124 |
3. **Synchronous Processing for Small Datasets**: Prefer synchronous construction of GeoJSON and statistics for the project's current station datasets (normally under 5,000 items) instead of `setTimeout(..., 0)` yielding loops. Treat the item count as a current default, not a universal performance guarantee. Re-profile when dataset size, geometry complexity, target devices, or processing work changes, and use measured evidence to justify chunking or worker-based processing.
|
| 125 |
4. **Derived Map Statistics**: Calculate map-related statistics (e.g. averages/mins/maxes of visible stations) synchronously using React `useMemo` hooks derived from the current bounds and observations, rather than writing to state variables in a `useEffect` that triggers additional re-renders.
|
|
|
|
| 126 |
<!-- END:react-maplibre-sync-rule -->
|
| 127 |
|
| 128 |
<!-- BEGIN:react-dashboard-loading-rules -->
|
|
@@ -142,6 +143,14 @@ When implementing fullscreen or immersive modes:
|
|
| 142 |
3. **Dedicated Presentation Toggles:** If a "presentation" or "immersive" mode is required, implement it via an explicit user-controlled UI toggle (e.g., a collapsible sidebar button) that operates independently of the browser's fullscreen state.
|
| 143 |
<!-- END:ui-ux-fullscreen-layout-rule -->
|
| 144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
<!-- BEGIN:verification-rules -->
|
| 146 |
## Verification Requirements
|
| 147 |
|
|
|
|
| 123 |
2. **Avoid Arbitrary Timers for Style/Source Updates**: Do not use `setTimeout` or other custom timers to coordinate updating a map source after changing the map style (e.g. basemap). Rely on MapLibre's native `'style.load'` event listener to re-add layers and update states.
|
| 124 |
3. **Synchronous Processing for Small Datasets**: Prefer synchronous construction of GeoJSON and statistics for the project's current station datasets (normally under 5,000 items) instead of `setTimeout(..., 0)` yielding loops. Treat the item count as a current default, not a universal performance guarantee. Re-profile when dataset size, geometry complexity, target devices, or processing work changes, and use measured evidence to justify chunking or worker-based processing.
|
| 125 |
4. **Derived Map Statistics**: Calculate map-related statistics (e.g. averages/mins/maxes of visible stations) synchronously using React `useMemo` hooks derived from the current bounds and observations, rather than writing to state variables in a `useEffect` that triggers additional re-renders.
|
| 126 |
+
5. **Event Listener Memory Leaks**: When attaching initialization event listeners like `'load'` inside a React `useEffect`, always use `map.once('load', ...)` rather than `.on('load')` to prevent duplicate triggers on subsequent basemap/style updates. Furthermore, because map tiles load asynchronously, you MUST gate any React state updates (e.g., `setMapLoaded(true)`) inside these listeners with a local `let isMounted = true` flag that is explicitly set to `false` in the `useEffect` cleanup function.
|
| 127 |
<!-- END:react-maplibre-sync-rule -->
|
| 128 |
|
| 129 |
<!-- BEGIN:react-dashboard-loading-rules -->
|
|
|
|
| 143 |
3. **Dedicated Presentation Toggles:** If a "presentation" or "immersive" mode is required, implement it via an explicit user-controlled UI toggle (e.g., a collapsible sidebar button) that operates independently of the browser's fullscreen state.
|
| 144 |
<!-- END:ui-ux-fullscreen-layout-rule -->
|
| 145 |
|
| 146 |
+
<!-- BEGIN:ui-ux-dynamic-grids-rule -->
|
| 147 |
+
## UI/UX: Dynamic Grid Layouts
|
| 148 |
+
|
| 149 |
+
When implementing multi-column dashboards (e.g., `grid-cols-2`) where the number of child cards or charts is dynamic (based on available data):
|
| 150 |
+
1. **Prevent Orphaned Spaces**: Do not leave an empty grid cell if there is an odd number of items.
|
| 151 |
+
2. **Implementation**: Use Tailwind arbitrary variants on the grid container to force the last orphaned child to span the full width. For a 2-column grid, apply `[&>*:last-child:nth-child(odd)]:col-span-2` (or the respective responsive prefix like `xl:col-span-2`). This ensures the UI remains visually balanced.
|
| 152 |
+
<!-- END:ui-ux-dynamic-grids-rule -->
|
| 153 |
+
|
| 154 |
<!-- BEGIN:verification-rules -->
|
| 155 |
## Verification Requirements
|
| 156 |
|
src/app/page.tsx
CHANGED
|
@@ -1004,12 +1004,12 @@ function EuroMeteoApp({ initialUrlState }: { initialUrlState: InitialUrlState })
|
|
| 1004 |
{/* Main View Shell Container */}
|
| 1005 |
<main className="flex-1 h-full flex flex-col min-w-0 relative bg-slate-50 transition-all">
|
| 1006 |
{/* Floating pill navigation */}
|
| 1007 |
-
<header className="absolute left-1/2 top-3 z-30 -translate-x-1/2 flex items-center p-1.5 gap-1 bg-white/90 backdrop-blur-md border border-slate-200/50 rounded-2xl shadow-sm">
|
| 1008 |
{/* Mobile Menu Button */}
|
| 1009 |
<button
|
| 1010 |
type="button"
|
| 1011 |
onClick={() => setSidebarOpen(true)}
|
| 1012 |
-
className="lg:hidden p-2 text-slate-500 hover:text-slate-800 hover:bg-slate-50 rounded-xl transition-all min-w-[36px] min-h-[36px] flex items-center justify-center"
|
| 1013 |
aria-label="Open menu"
|
| 1014 |
>
|
| 1015 |
<Menu size={18} />
|
|
@@ -1026,7 +1026,7 @@ function EuroMeteoApp({ initialUrlState }: { initialUrlState: InitialUrlState })
|
|
| 1026 |
}
|
| 1027 |
}}
|
| 1028 |
aria-label="Reset map view"
|
| 1029 |
-
className="lg:hidden p-2 text-slate-500 hover:text-slate-800 hover:bg-slate-50 rounded-xl transition-all min-w-[36px] min-h-[36px] flex items-center justify-center"
|
| 1030 |
>
|
| 1031 |
<Home size={18} aria-hidden="true" />
|
| 1032 |
</button>
|
|
@@ -1046,7 +1046,7 @@ function EuroMeteoApp({ initialUrlState }: { initialUrlState: InitialUrlState })
|
|
| 1046 |
className={`flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-bold transition-all cursor-pointer ${
|
| 1047 |
isActive
|
| 1048 |
? "bg-blue-500 text-white shadow-md shadow-blue-500/10"
|
| 1049 |
-
: "text-slate-500 hover:bg-slate-50 hover:text-slate-700"
|
| 1050 |
}`}
|
| 1051 |
>
|
| 1052 |
<Icon size={14} />
|
|
|
|
| 1004 |
{/* Main View Shell Container */}
|
| 1005 |
<main className="flex-1 h-full flex flex-col min-w-0 relative bg-slate-50 transition-all">
|
| 1006 |
{/* Floating pill navigation */}
|
| 1007 |
+
<header className="absolute left-1/2 top-3 z-30 -translate-x-1/2 flex items-center p-1.5 gap-1 bg-slate-900/90 md:bg-white/90 backdrop-blur-md border border-slate-700/50 md:border-slate-200/50 rounded-2xl shadow-sm">
|
| 1008 |
{/* Mobile Menu Button */}
|
| 1009 |
<button
|
| 1010 |
type="button"
|
| 1011 |
onClick={() => setSidebarOpen(true)}
|
| 1012 |
+
className="lg:hidden p-2 text-slate-300 md:text-slate-500 hover:text-white md:hover:text-slate-800 hover:bg-slate-800 md:hover:bg-slate-50 rounded-xl transition-all min-w-[36px] min-h-[36px] flex items-center justify-center"
|
| 1013 |
aria-label="Open menu"
|
| 1014 |
>
|
| 1015 |
<Menu size={18} />
|
|
|
|
| 1026 |
}
|
| 1027 |
}}
|
| 1028 |
aria-label="Reset map view"
|
| 1029 |
+
className="lg:hidden p-2 text-slate-300 md:text-slate-500 hover:text-white md:hover:text-slate-800 hover:bg-slate-800 md:hover:bg-slate-50 rounded-xl transition-all min-w-[36px] min-h-[36px] flex items-center justify-center"
|
| 1030 |
>
|
| 1031 |
<Home size={18} aria-hidden="true" />
|
| 1032 |
</button>
|
|
|
|
| 1046 |
className={`flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-bold transition-all cursor-pointer ${
|
| 1047 |
isActive
|
| 1048 |
? "bg-blue-500 text-white shadow-md shadow-blue-500/10"
|
| 1049 |
+
: "text-slate-300 md:text-slate-500 hover:bg-slate-800 md:hover:bg-slate-50 hover:text-white md:hover:text-slate-700"
|
| 1050 |
}`}
|
| 1051 |
>
|
| 1052 |
<Icon size={14} />
|
src/components/DashboardCharts.tsx
CHANGED
|
@@ -440,7 +440,7 @@ const DashboardChartsComponent: React.FC<{ data: HourlyRow[]; units?: Record<str
|
|
| 440 |
</div>
|
| 441 |
)}
|
| 442 |
|
| 443 |
-
<div className="grid grid-cols-1 xl:grid-cols-2 gap-6 lazy-render [&>*:last-child:nth-child(odd)]:
|
| 444 |
{/* βββ Core Meteorological Charts βββ */}
|
| 445 |
{hasTemperature && (
|
| 446 |
<AreaChartCard
|
|
|
|
| 440 |
</div>
|
| 441 |
)}
|
| 442 |
|
| 443 |
+
<div className="grid grid-cols-1 xl:grid-cols-2 gap-6 lazy-render xl:[&>*:last-child:nth-child(odd)]:col-span-2">
|
| 444 |
{/* βββ Core Meteorological Charts βββ */}
|
| 445 |
{hasTemperature && (
|
| 446 |
<AreaChartCard
|
src/components/Map.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import React, { useEffect, useRef, useState, useCallback, useMemo } from "react";
|
| 2 |
import maplibregl from "maplibre-gl";
|
| 3 |
import "maplibre-gl/dist/maplibre-gl.css";
|
| 4 |
-
import { Layers, ShieldAlert, Home, Info, ChevronDown } from "lucide-react";
|
| 5 |
import { getColorFromPalette, getUnitForParam } from "@/utils/colors";
|
| 6 |
import { countryMatches } from "@/utils/country";
|
| 7 |
import { filterMapObservations } from "@/utils/qc";
|
|
@@ -1096,40 +1096,66 @@ const WeatherMapComponent: React.FC<MapProps> = ({
|
|
| 1096 |
)}
|
| 1097 |
|
| 1098 |
{/* Timeline slider control panel at bottom of map */}
|
| 1099 |
-
<div className="absolute bottom-1 left-1 right-1 md:bottom-6 md:left-6 md:right-6 z-10 bg-white/95 backdrop-blur-md border border-slate-200 rounded-2xl p-4 shadow-xl flex flex-col md:flex-row items-center gap-4">
|
| 1100 |
{/* Timeline Slider bar */}
|
| 1101 |
<div className="flex-1 w-full flex flex-col gap-1">
|
| 1102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1103 |
<span className="text-blue-600 bg-blue-50 border border-blue-200 shadow-sm rounded-full px-4 py-1">
|
| 1104 |
{endDate} at {selectedHour.toString().padStart(2, "0")}:00 UTC
|
| 1105 |
</span>
|
| 1106 |
</div>
|
| 1107 |
-
|
| 1108 |
-
|
| 1109 |
-
|
| 1110 |
-
|
| 1111 |
-
|
| 1112 |
-
|
| 1113 |
-
|
| 1114 |
-
|
| 1115 |
-
|
| 1116 |
-
|
| 1117 |
-
|
| 1118 |
-
|
| 1119 |
-
|
| 1120 |
-
|
| 1121 |
-
|
| 1122 |
-
|
| 1123 |
-
|
| 1124 |
-
|
| 1125 |
-
|
| 1126 |
-
|
| 1127 |
-
|
| 1128 |
-
|
| 1129 |
-
|
| 1130 |
-
|
| 1131 |
-
|
| 1132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1133 |
</div>
|
| 1134 |
</div>
|
| 1135 |
</div>
|
|
|
|
| 1 |
import React, { useEffect, useRef, useState, useCallback, useMemo } from "react";
|
| 2 |
import maplibregl from "maplibre-gl";
|
| 3 |
import "maplibre-gl/dist/maplibre-gl.css";
|
| 4 |
+
import { Layers, ShieldAlert, Home, Info, ChevronDown, ChevronLeft, ChevronRight } from "lucide-react";
|
| 5 |
import { getColorFromPalette, getUnitForParam } from "@/utils/colors";
|
| 6 |
import { countryMatches } from "@/utils/country";
|
| 7 |
import { filterMapObservations } from "@/utils/qc";
|
|
|
|
| 1096 |
)}
|
| 1097 |
|
| 1098 |
{/* Timeline slider control panel at bottom of map */}
|
| 1099 |
+
<div className="absolute bottom-1 left-1 right-1 md:bottom-6 md:left-6 md:right-6 z-10 bg-slate-900/90 md:bg-white/95 backdrop-blur-md border border-slate-700/50 md:border-slate-200 rounded-2xl p-4 shadow-xl flex flex-col md:flex-row items-center gap-4">
|
| 1100 |
{/* Timeline Slider bar */}
|
| 1101 |
<div className="flex-1 w-full flex flex-col gap-1">
|
| 1102 |
+
{/* Mobile Stepper Header (hidden on md+) */}
|
| 1103 |
+
<div className="flex md:hidden justify-between items-center text-sm font-bold w-full">
|
| 1104 |
+
<button
|
| 1105 |
+
onClick={() => setSelectedHour(prev => Math.max(0, prev - 1))}
|
| 1106 |
+
disabled={selectedHour <= 0}
|
| 1107 |
+
className="p-1.5 bg-slate-800 md:bg-white border border-slate-700 md:border-slate-200 rounded-full text-slate-300 md:text-slate-600 disabled:opacity-50 disabled:bg-slate-900/50 md:disabled:bg-slate-50 shadow-sm flex-shrink-0"
|
| 1108 |
+
>
|
| 1109 |
+
<ChevronLeft size={20} />
|
| 1110 |
+
</button>
|
| 1111 |
+
<span className="text-white md:text-blue-600 bg-slate-800 md:bg-blue-50 border border-slate-700 md:border-blue-200 shadow-sm rounded-full px-4 py-1.5 flex-1 text-center mx-2 truncate text-xs sm:text-sm">
|
| 1112 |
+
{endDate} at {selectedHour.toString().padStart(2, "0")}:00 UTC
|
| 1113 |
+
</span>
|
| 1114 |
+
<button
|
| 1115 |
+
onClick={() => setSelectedHour(prev => Math.min(maxAllowedHour, prev + 1))}
|
| 1116 |
+
disabled={selectedHour >= maxAllowedHour}
|
| 1117 |
+
className="p-1.5 bg-slate-800 md:bg-white border border-slate-700 md:border-slate-200 rounded-full text-slate-300 md:text-slate-600 disabled:opacity-50 disabled:bg-slate-900/50 md:disabled:bg-slate-50 shadow-sm flex-shrink-0"
|
| 1118 |
+
>
|
| 1119 |
+
<ChevronRight size={20} />
|
| 1120 |
+
</button>
|
| 1121 |
+
</div>
|
| 1122 |
+
|
| 1123 |
+
{/* Desktop/Tablet Header (hidden on mobile) */}
|
| 1124 |
+
<div className="hidden md:flex justify-center items-center text-sm font-bold px-1 mb-1">
|
| 1125 |
<span className="text-blue-600 bg-blue-50 border border-blue-200 shadow-sm rounded-full px-4 py-1">
|
| 1126 |
{endDate} at {selectedHour.toString().padStart(2, "0")}:00 UTC
|
| 1127 |
</span>
|
| 1128 |
</div>
|
| 1129 |
+
|
| 1130 |
+
{/* Slider & Ticks (hidden on mobile) */}
|
| 1131 |
+
<div className="hidden md:block">
|
| 1132 |
+
<input
|
| 1133 |
+
type="range"
|
| 1134 |
+
min="0"
|
| 1135 |
+
max="23"
|
| 1136 |
+
value={selectedHour}
|
| 1137 |
+
onChange={(e) => {
|
| 1138 |
+
const val = parseInt(e.target.value);
|
| 1139 |
+
if (val <= maxAllowedHour) {
|
| 1140 |
+
setSelectedHour(val);
|
| 1141 |
+
}
|
| 1142 |
+
}}
|
| 1143 |
+
className="w-full h-4 md:h-2 bg-slate-100 rounded-lg appearance-none cursor-pointer accent-blue-500"
|
| 1144 |
+
/>
|
| 1145 |
+
<div className="relative w-full h-6 mt-1 text-xs text-slate-400 font-semibold">
|
| 1146 |
+
{[0, 3, 6, 9, 12, 15, 18, 21, 23].map((h) => (
|
| 1147 |
+
<div
|
| 1148 |
+
key={h}
|
| 1149 |
+
className={`absolute top-0 flex flex-col items-center w-6 -ml-3 transition-opacity ${h > maxAllowedHour ? "opacity-30" : "opacity-100"}`}
|
| 1150 |
+
style={{
|
| 1151 |
+
left: `calc(10px + (100% - 20px) * ${h / 23})`,
|
| 1152 |
+
}}
|
| 1153 |
+
>
|
| 1154 |
+
<div className="w-[1.5px] h-1.5 bg-slate-300 mb-0.5 rounded-full" />
|
| 1155 |
+
<span>{h}</span>
|
| 1156 |
+
</div>
|
| 1157 |
+
))}
|
| 1158 |
+
</div>
|
| 1159 |
</div>
|
| 1160 |
</div>
|
| 1161 |
</div>
|