import { useEffect, useRef } from "react"; import { useSelector, useDispatch } from "react-redux"; import MessagesButton from "./sidebar/MessagesButton"; import SpaceIcon from "./sidebar/SpaceIcon"; import { navigateToSpace, navigateToMessages, openCreateSpace, openSettings, closeSettings, } from "../store/slices/appSlice"; function Sidebar() { const dispatch = useDispatch(); const appState = useSelector((state) => state.app); const { activeView, activeSpace, isSettings } = appState; const { isDark } = useSelector((state) => state.theme); const { totalUnreadCount } = useSelector((state) => state.dm); const { spaces, loading: spacesLoading, spacesFetched } = useSelector( (state) => state.space, ); const { isAuthenticated } = useSelector((state) => state.auth); const currentView = isSettings ? "settings" : activeView; console.log("[Sidebar] Render - spaces count:", spaces.length, "spacesLoading:", spacesLoading, "spaces:", spaces.map(s => ({ id: s.id, name: s.name }))); return (
{ dispatch(navigateToMessages()); }} unreadCount={totalUnreadCount} /> {spaces.map((space) => ( { dispatch(navigateToSpace(space.id)); }} title={space.name} /> ))} {spacesLoading && (
)} { dispatch(openCreateSpace()); }} title="Tạo Space mới" />
dispatch(openSettings())} title="Settings" />
); } export default Sidebar;