update frontend
This commit is contained in:
parent
8e60ad833f
commit
2a66d974a2
|
|
@ -28,7 +28,7 @@ export default function MapView() {
|
||||||
const markersRef = useRef([]); // [{ id, marker, el, ... }]
|
const markersRef = useRef([]); // [{ id, marker, el, ... }]
|
||||||
const expandedElRef = useRef(null);
|
const expandedElRef = useRef(null);
|
||||||
|
|
||||||
// posts bruts accumulés
|
// posts bruts accumulés (tous ceux qu'on a déjà chargés)
|
||||||
const allPostsRef = useRef([]);
|
const allPostsRef = useRef([]);
|
||||||
|
|
||||||
// dernière zone fetchée
|
// dernière zone fetchée
|
||||||
|
|
@ -249,6 +249,7 @@ export default function MapView() {
|
||||||
|
|
||||||
/* ================= MARKERS & FILTERS ================= */
|
/* ================= MARKERS & FILTERS ================= */
|
||||||
|
|
||||||
|
// Applique TOUS les filtres (catégorie + sous-cat + temps) sur ce qu'on a déjà en mémoire.
|
||||||
const rebuildMarkersForFilters = (tf) => {
|
const rebuildMarkersForFilters = (tf) => {
|
||||||
const map = mapRef.current;
|
const map = mapRef.current;
|
||||||
if (!map) return;
|
if (!map) return;
|
||||||
|
|
@ -279,6 +280,13 @@ export default function MapView() {
|
||||||
setStatus(visible.length ? "" : "No posts found.");
|
setStatus(visible.length ? "" : "No posts found.");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ⚡ Dès qu'on change de catégorie ou sous-catégorie,
|
||||||
|
// on filtre immédiatement ce qui est déjà chargé
|
||||||
|
useEffect(() => {
|
||||||
|
rebuildMarkersForFilters(timeFilter);
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [mainFilter, subFilter]);
|
||||||
|
|
||||||
/* ================= FETCH PAR ZONE (ACCUMULATIF) ================= */
|
/* ================= FETCH PAR ZONE (ACCUMULATIF) ================= */
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -352,6 +360,7 @@ export default function MapView() {
|
||||||
filterKey,
|
filterKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Une fois le backend répondu, on met à jour les markers + Sociowall
|
||||||
rebuildMarkersForFilters(timeFilter);
|
rebuildMarkersForFilters(timeFilter);
|
||||||
setLoadingPosts(false);
|
setLoadingPosts(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -372,6 +381,7 @@ export default function MapView() {
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [viewParams, mainFilter, subFilter]);
|
}, [viewParams, mainFilter, subFilter]);
|
||||||
|
|
||||||
|
// Quand on change le filtre temps, on réapplique directement
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
rebuildMarkersForFilters(timeFilter);
|
rebuildMarkersForFilters(timeFilter);
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
|
@ -402,27 +412,20 @@ export default function MapView() {
|
||||||
if (msg.type === "new_post" && msg.post) {
|
if (msg.type === "new_post" && msg.post) {
|
||||||
const p = msg.post;
|
const p = msg.post;
|
||||||
|
|
||||||
|
// On ajoute à la liste globale
|
||||||
|
allPostsRef.current = [...allPostsRef.current, p];
|
||||||
|
|
||||||
|
// Et si le nouveau post matche les filtres courants, on l'affiche
|
||||||
const catCode = categoryCode(mainFilter);
|
const catCode = categoryCode(mainFilter);
|
||||||
if (catCode) {
|
if (catCode) {
|
||||||
const pc = (p.category || p.Category || "").toString().toUpperCase();
|
const pc = (p.category || p.Category || "").toString().toUpperCase();
|
||||||
if (pc !== catCode) return;
|
if (pc !== catCode) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!matchesSubFilter(p, subFilter)) return;
|
if (!matchesSubFilter(p, subFilter)) return;
|
||||||
if (!matchesTimeFilter(p.created_at || p.CreatedAt, timeFilter)) {
|
if (!matchesTimeFilter(p.created_at || p.CreatedAt, timeFilter)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const id = typeof p.id === "number" ? p.id : null;
|
|
||||||
if (
|
|
||||||
id !== null &&
|
|
||||||
allPostsRef.current.some((post) => post.id === id)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
allPostsRef.current = [...allPostsRef.current, p];
|
|
||||||
|
|
||||||
createMarkerForPost(p, mapRef, markersRef, expandedElRef);
|
createMarkerForPost(p, mapRef, markersRef, expandedElRef);
|
||||||
setVisiblePosts((current) => [...current, p]);
|
setVisiblePosts((current) => [...current, p]);
|
||||||
}
|
}
|
||||||
|
|
@ -734,7 +737,7 @@ export default function MapView() {
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* SOCIOWALL + CHAT EN BAS (overlay) */}
|
{/* SOCIOWALL + CHAT EN BAS */}
|
||||||
<div className="map-overlay map-overlay-wall">
|
<div className="map-overlay map-overlay-wall">
|
||||||
<div className="sociowall-panel">
|
<div className="sociowall-panel">
|
||||||
<div className="sociowall-header">Sociowall</div>
|
<div className="sociowall-header">Sociowall</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue