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 expandedElRef = useRef(null);
|
||||
|
||||
// posts bruts accumulés
|
||||
// posts bruts accumulés (tous ceux qu'on a déjà chargés)
|
||||
const allPostsRef = useRef([]);
|
||||
|
||||
// dernière zone fetchée
|
||||
|
|
@ -249,6 +249,7 @@ export default function MapView() {
|
|||
|
||||
/* ================= 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 map = mapRef.current;
|
||||
if (!map) return;
|
||||
|
|
@ -279,6 +280,13 @@ export default function MapView() {
|
|||
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) ================= */
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -352,6 +360,7 @@ export default function MapView() {
|
|||
filterKey,
|
||||
};
|
||||
|
||||
// Une fois le backend répondu, on met à jour les markers + Sociowall
|
||||
rebuildMarkersForFilters(timeFilter);
|
||||
setLoadingPosts(false);
|
||||
} catch (err) {
|
||||
|
|
@ -372,6 +381,7 @@ export default function MapView() {
|
|||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [viewParams, mainFilter, subFilter]);
|
||||
|
||||
// Quand on change le filtre temps, on réapplique directement
|
||||
useEffect(() => {
|
||||
rebuildMarkersForFilters(timeFilter);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
|
|
@ -402,27 +412,20 @@ export default function MapView() {
|
|||
if (msg.type === "new_post" && 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);
|
||||
if (catCode) {
|
||||
const pc = (p.category || p.Category || "").toString().toUpperCase();
|
||||
if (pc !== catCode) return;
|
||||
}
|
||||
|
||||
if (!matchesSubFilter(p, subFilter)) return;
|
||||
if (!matchesTimeFilter(p.created_at || p.CreatedAt, timeFilter)) {
|
||||
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);
|
||||
setVisiblePosts((current) => [...current, p]);
|
||||
}
|
||||
|
|
@ -734,7 +737,7 @@ export default function MapView() {
|
|||
</div>
|
||||
)}
|
||||
|
||||
{/* SOCIOWALL + CHAT EN BAS (overlay) */}
|
||||
{/* SOCIOWALL + CHAT EN BAS */}
|
||||
<div className="map-overlay map-overlay-wall">
|
||||
<div className="sociowall-panel">
|
||||
<div className="sociowall-header">Sociowall</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue