update frontend

This commit is contained in:
Your Name 2025-12-13 01:51:15 -05:00
parent 8249aa7e16
commit 5918e7aea5
3 changed files with 49 additions and 31 deletions

View File

@ -176,7 +176,7 @@ export default function MapView({ theme = "dark" }) {
{ {
title: draftTitle.trim(), title: draftTitle.trim(),
snippet: draftBody.trim() || draftTitle.trim(), snippet: draftBody.trim() || draftTitle.trim(),
category: draftCategory.toUpperCase(), category: (draftCategory === "Events" ? "EVENT" : draftCategory.toUpperCase()),
sub_category: draftSubCategory || "ALL", sub_category: draftSubCategory || "ALL",
lat, lat,
lon: lng, lon: lng,

View File

@ -8,7 +8,7 @@ export function categoryCode(mainFilter) {
case "Friends": case "Friends":
return "FRIENDS"; return "FRIENDS";
case "Events": case "Events":
return "EVENT"; // backend: EVENT return "EVENT"; // backend attendu
case "Market": case "Market":
return "MARKET"; return "MARKET";
case "All": case "All":
@ -40,6 +40,29 @@ export function matchesSubFilter(post, subFilter) {
return sub === subFilter.toLowerCase(); return sub === subFilter.toLowerCase();
} }
// Parse date backend safely:
// - "YYYY-MM-DD HH:MM:SS" => treated as LOCAL (pas de "Z" qui décale)
// - ISO string garde ce que JS sait faire
function parseCreatedAt(createdAt) {
if (!createdAt) return null;
if (createdAt instanceof Date) return createdAt;
const s = String(createdAt).trim();
if (!s) return null;
// "YYYY-MM-DD HH:MM:SS" (sans timezone)
if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s)) {
// local time
const isoLocal = s.replace(" ", "T");
const d = new Date(isoLocal);
return Number.isNaN(d.getTime()) ? null : d;
}
const d = new Date(s);
return Number.isNaN(d.getTime()) ? null : d;
}
// time filter local règles demandées : // time filter local règles demandées :
// NOW = dernière 1h // NOW = dernière 1h
// TODAY = dernière 24h // TODAY = dernière 24h
@ -47,26 +70,20 @@ export function matchesSubFilter(post, subFilter) {
// PAST = ALL (pas de filtre de temps) // PAST = ALL (pas de filtre de temps)
export function matchesTimeFilter(createdAt, timeFilter) { export function matchesTimeFilter(createdAt, timeFilter) {
if (!timeFilter) return true; if (!timeFilter) return true;
if (!createdAt) return true;
let d;
if (typeof createdAt === "string") {
// backend renvoie souvent "YYYY-MM-DD HH:MM:SS"
if (createdAt.includes(" ")) {
d = new Date(createdAt.replace(" ", "T") + "Z");
} else {
d = new Date(createdAt);
}
} else {
d = new Date(createdAt);
}
if (Number.isNaN(d.getTime())) return true;
// PAST = ALL => aucun filtre temps // PAST = ALL => aucun filtre temps
if (timeFilter === "PAST") return true; if (timeFilter === "PAST") return true;
const now = new Date(); const d = parseCreatedAt(createdAt);
const diffMs = now.getTime() - d.getTime(); if (!d) return true;
const now = Date.now();
const diffMs = now - d.getTime();
if (!Number.isFinite(diffMs)) return true;
// si date future (clock/UTC weird) -> on laisse passer
if (diffMs < 0) return true;
const diffHours = diffMs / 3600000; const diffHours = diffMs / 3600000;
const diffDays = diffMs / 86400000; const diffDays = diffMs / 86400000;

View File

@ -11,16 +11,13 @@ function getBaseStyle(theme) {
switch (t) { switch (t) {
case "light": case "light":
// fond clair
tiles = ["https://a.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png"]; tiles = ["https://a.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png"];
break; break;
case "blue": case "blue":
// style plus coloré
tiles = ["https://a.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png"]; tiles = ["https://a.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png"];
break; break;
case "dark": case "dark":
default: default:
// fond sombre (comme avant)
tiles = ["https://a.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png"]; tiles = ["https://a.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png"];
break; break;
} }
@ -49,7 +46,6 @@ export function useMapCore(theme) {
const containerRef = useRef(null); const containerRef = useRef(null);
const mapRef = useRef(null); const mapRef = useRef(null);
// pour les markers (utilisé aussi par usePostsEngine + MapView)
const markersRef = useRef([]); const markersRef = useRef([]);
const expandedElRef = useRef(null); const expandedElRef = useRef(null);
@ -59,7 +55,14 @@ export function useMapCore(theme) {
}); });
const [hasLastView, setHasLastView] = useState(false); const [hasLastView, setHasLastView] = useState(false);
// création de la map function closeExpandedIfAny() {
const el = expandedElRef.current;
if (el && el.__setExpanded) {
el.__setExpanded(false);
}
expandedElRef.current = null;
}
useEffect(() => { useEffect(() => {
if (!containerRef.current) return; if (!containerRef.current) return;
@ -89,9 +92,7 @@ export function useMapCore(theme) {
hadLastView = true; hadLastView = true;
} }
} }
} catch { } catch {}
// ignore
}
setHasLastView(hadLastView); setHasLastView(hadLastView);
map.addControl(new maplibregl.NavigationControl(), "top-right"); map.addControl(new maplibregl.NavigationControl(), "top-right");
@ -115,21 +116,21 @@ export function useMapCore(theme) {
zoom: map.getZoom(), zoom: map.getZoom(),
}) })
); );
} catch { } catch {}
// ignore
}
}); });
// IMPORTANT: click/drag sur la map => fermer le gros post
map.on("click", () => closeExpandedIfAny());
map.on("dragstart", () => closeExpandedIfAny());
return () => { return () => {
clearAllMarkers(markersRef, expandedElRef); clearAllMarkers(markersRef, expandedElRef);
map.remove(); map.remove();
mapRef.current = null; mapRef.current = null;
}; };
// on ne met PAS theme ici, sinon la map serait recréée
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, []); }, []);
// quand le thème change → on change juste le style de la map
useEffect(() => { useEffect(() => {
const map = mapRef.current; const map = mapRef.current;
if (!map) return; if (!map) return;