diff --git a/src/components/Map/MapView.jsx b/src/components/Map/MapView.jsx index c4cf18b..268a452 100644 --- a/src/components/Map/MapView.jsx +++ b/src/components/Map/MapView.jsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from "react"; +import React, { useEffect, useRef, useState } from "react"; import "maplibre-gl/dist/maplibre-gl.css"; import "../../styles/mapMarkers.css"; @@ -34,6 +34,9 @@ export default function MapView({ const [timeFilter, setTimeFilter] = useState("RECENT"); const [subFilter, setSubFilter] = useState("All"); + const stageRef = useRef(null); + const [showSubcats, setShowSubcats] = useState(true); + const userPosition = useUserPosition(mapRef, hasLastView); const { status, visiblePosts, loadingPosts, loadError, handleIncomingPost } = usePostsEngine({ @@ -89,6 +92,23 @@ export default function MapView({ }, [selectedPost, mapRef]); // Websocket for new posts + useEffect(() => { + const el = stageRef.current; + if (!el || typeof IntersectionObserver === "undefined") return; + + const obs = new IntersectionObserver( + (entries) => { + const e = entries && entries[0]; + const ok = !!(e && e.isIntersecting && e.intersectionRatio > 0.15); + setShowSubcats(ok); + }, + { threshold: [0, 0.15, 0.3, 0.6] } + ); + + obs.observe(el); + return () => obs.disconnect(); + }, []); + useEffect(() => { const proto = window.location.protocol === "https:" ? "wss" : "ws"; const host = @@ -224,7 +244,7 @@ export default function MapView({ return (