diff --git a/src/App.jsx b/src/App.jsx index f08b0b3..dd4df67 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -7,7 +7,7 @@ const THEME_KEY = "sociowire:theme"; export default function App() { const [theme, setTheme] = useState("dark"); - // charge le thème depuis le localStorage au démarrage + // charge le thème au démarrage useEffect(() => { if (typeof window === "undefined") return; try { @@ -23,7 +23,7 @@ export default function App() { } }, []); - // applique le thème + sauvegarde + // applique / sauvegarde le thème useEffect(() => { if (typeof window === "undefined") return; try { @@ -39,7 +39,8 @@ export default function App() {
- + {/* on passe le thème à la carte */} +
diff --git a/src/components/Map/MapView.jsx b/src/components/Map/MapView.jsx index 7c36453..62c3b82 100644 --- a/src/components/Map/MapView.jsx +++ b/src/components/Map/MapView.jsx @@ -15,7 +15,7 @@ import { useUserPosition } from "./useUserPosition"; import { usePostsEngine } from "./usePostsEngine"; import PostList from "../Posts/PostList"; -export default function MapView() { +export default function MapView({ theme = "dark" }) { const { containerRef, mapRef, @@ -23,7 +23,7 @@ export default function MapView() { expandedElRef, viewParams, hasLastView, - } = useMapCore(); + } = useMapCore(theme); const [mainFilter, setMainFilter] = useState("All"); const [timeFilter, setTimeFilter] = useState("RECENT"); @@ -88,7 +88,9 @@ export default function MapView() { if (msg.type === "new_post" && msg.post) { handleIncomingPost(msg.post); } - } catch {} + } catch { + // ignore + } }; return () => ws && ws.close(); }, [handleIncomingPost]); @@ -99,13 +101,6 @@ export default function MapView() { map.flyTo({ center: userPosition, zoom: 9, speed: 1.2 }); }; - const handlePickCenter = () => { - const map = mapRef.current; - if (!map) return; - const center = map.getCenter(); - setDraftCoords([center.lng, center.lat]); - }; - const handleOpenCreate = () => { setIsCreating(true); setDraftTitle(""); @@ -157,7 +152,9 @@ export default function MapView() { if (!map) return; const lng = post.lon ?? post.lng; const lat = post.lat ?? post.latitude; - if (lng && lat) map.flyTo({ center: [lng, lat], zoom: 8, speed: 1.4 }); + if (typeof lng === "number" && typeof lat === "number") { + map.flyTo({ center: [lng, lat], zoom: 8, speed: 1.4 }); + } }; return ( @@ -165,7 +162,7 @@ export default function MapView() {
{status &&
{status}
} - {/* TOP BAR SIMPLIFIÉE */} + {/* TOP */}
@@ -288,14 +288,18 @@ export default function MapView() { /> {saveError &&
{saveError}
}
-
)} - {/* SOCIOWALL FIXE + CHAT */} + {/* SOCIOWALL + CHAT */}
Sociowall
@@ -318,4 +322,4 @@ export default function MapView() {
); -} \ No newline at end of file +} diff --git a/src/components/Map/useMapCore.js b/src/components/Map/useMapCore.js index 9e426480..15eb91f 100644 --- a/src/components/Map/useMapCore.js +++ b/src/components/Map/useMapCore.js @@ -4,7 +4,48 @@ import { LAST_VIEW_KEY } from "./mapConfig"; import { getViewFromMap } from "./mapGeo"; import { clearAllMarkers } from "./markerManager"; -export function useMapCore() { +// renvoie le style MapLibre en fonction du thème +function getBaseStyle(theme) { + const t = theme || "dark"; + let tiles; + + switch (t) { + case "light": + // fond clair + tiles = ["https://a.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png"]; + break; + case "blue": + // style plus coloré + tiles = ["https://a.basemaps.cartocdn.com/voyager/{z}/{x}/{y}.png"]; + break; + case "dark": + default: + // fond sombre (comme avant) + tiles = ["https://a.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png"]; + break; + } + + return { + version: 8, + sources: { + "carto-base": { + type: "raster", + tiles, + tileSize: 256, + attribution: "© OpenStreetMap contributors © CARTO", + }, + }, + layers: [ + { + id: "carto-base-layer", + type: "raster", + source: "carto-base", + }, + ], + }; +} + +export function useMapCore(theme) { const containerRef = useRef(null); const mapRef = useRef(null); @@ -18,31 +59,13 @@ export function useMapCore() { }); const [hasLastView, setHasLastView] = useState(false); + // création de la map useEffect(() => { if (!containerRef.current) return; const map = new maplibregl.Map({ container: containerRef.current, - style: { - version: 8, - sources: { - "carto-dark": { - type: "raster", - tiles: [ - "https://a.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png", - ], - tileSize: 256, - attribution: "© OpenStreetMap contributors © CARTO", - }, - }, - layers: [ - { - id: "carto-dark-layer", - type: "raster", - source: "carto-dark", - }, - ], - }, + style: getBaseStyle(theme || "dark"), center: [-95, 40], zoom: 3.5, pitch: 0, @@ -102,8 +125,17 @@ export function useMapCore() { map.remove(); mapRef.current = null; }; + // on ne met PAS theme ici, sinon la map serait recréée + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); + // quand le thème change → on change juste le style de la map + useEffect(() => { + const map = mapRef.current; + if (!map) return; + map.setStyle(getBaseStyle(theme || "dark")); + }, [theme]); + return { containerRef, mapRef,