import React, { Suspense, useEffect, useState, useCallback } from "react"; import TopBar from "./components/Layout/TopBar"; import PostList from "./components/Posts/PostList"; import IslandUniverse from "./components/Island/IslandUniverse"; import IslandViewer from "./components/Island/IslandViewer"; const MapView = React.lazy(() => import("./components/Map/MapView")); const THEME_KEY = "sociowire:theme"; const ACTIVE_CHATS_KEY = "sociowire:activeChats"; export default function App() { const [theme, setTheme] = useState("blue"); // Wall state (lifted from MapView) const [wallPosts, setWallPosts] = useState([]); const [wallLoading, setWallLoading] = useState(false); const [wallError, setWallError] = useState(""); const [selectedPost, setSelectedPost] = useState(null); // Island Universe & Island Viewer state const [showUniverse, setShowUniverse] = useState(false); const [selectedIsland, setSelectedIsland] = useState(null); const handlePostsState = useCallback((next) => { if (!next) return; if (Array.isArray(next.posts)) setWallPosts(next.posts); setWallLoading(!!next.loading); setWallError(next.error || ""); }, []); // charge le thème au démarrage useEffect(() => { if (typeof window === "undefined") return; try { const saved = localStorage.getItem(THEME_KEY); if (saved === "dark" || saved === "blue" || saved === "light") { setTheme(saved); document.body.setAttribute("data-theme", saved); } else { setTheme("blue"); document.body.setAttribute("data-theme", "blue"); } } catch (e) { setTheme("blue"); document.body.setAttribute("data-theme", "blue"); } }, []); // applique / sauvegarde le thème useEffect(() => { if (typeof window === "undefined") return; try { document.body.setAttribute("data-theme", theme); localStorage.setItem(THEME_KEY, theme); } catch (e) { // ignore } }, [theme]); // Chats actifs (s'ajoutent quand on clique sur un contact) const [activeChats, setActiveChats] = useState([]); const [showContactsList, setShowContactsList] = useState(false); useEffect(() => { const onScroll = () => { const threshold = window.innerHeight * 0.55; const expanded = window.scrollY > threshold; document.body.classList.toggle("sw-wall-expanded", expanded); }; window.addEventListener("scroll", onScroll, { passive: true }); onScroll(); return () => window.removeEventListener("scroll", onScroll); }, []); useEffect(() => { try { const saved = localStorage.getItem(ACTIVE_CHATS_KEY); if (saved) setActiveChats(JSON.parse(saved)); } catch {} }, []); useEffect(() => { try { localStorage.setItem(ACTIVE_CHATS_KEY, JSON.stringify(activeChats)); } catch {} }, [activeChats]); // Ouvrir un chat const openChat = (name) => { if (!activeChats.includes(name)) { setActiveChats(prev => [...prev, name]); } setShowContactsList(false); }; const contactsList = ["Amely", "Nancy", "Stéphanie"]; // Island Universe handlers const handleOpenUniverse = () => { setShowUniverse(true); }; const handleCloseUniverse = () => { setShowUniverse(false); }; const handleIslandClick = (island) => { setShowUniverse(false); // Close universe setSelectedIsland(island); // Open island viewer }; return (