import { CSSProperties, useEffect, useState, useContext } from "react"; import axios from "axios"; import { LogoDark } from "../components/logo"; import { AccountAvatar } from "./account"; import { userInfo } from "../api/api"; import { NotificationsArea } from "./notificationsArea"; import { SocketContext } from "./socketContext"; import Home from '@material-ui/icons/Home'; import VideogameAssetIcon from '@material-ui/icons/VideogameAsset'; import ExtensionIcon from '@material-ui/icons/Extension'; import SearchIcon from '@material-ui/icons/Search'; import SettingsIcon from '@material-ui/icons/Settings'; import PersonIcon from '@material-ui/icons/Person'; import NotificationsIcon from '@material-ui/icons/Notifications'; var NavBarItemStyle: CSSProperties = { margin: 12, marginBottom: 16, display: "block" } export function NavBar() { var [ loggedIn, setLoggedIn ] = useState(false); var [ gotData, setGotData ] = useState(false); var [ friendRequests, setFriendRequests ] = useState>(null); var [ notificationsAreaVisible, setNotificationsAreaVisible ] = useState(false); var [ gotNotifications, setGotNotifications ] = useState(false); var { io } = useContext(SocketContext); async function getNotifications() { var friendRequestsReq = await axios.request<{ requests: Array }>({ method: "get", url: `/api/social/list/requests` }); setFriendRequests(friendRequestsReq.data.requests); setGotNotifications(friendRequestsReq.data.requests.length > 0); } useEffect(() => {(async () => { if (gotData) return; if (typeof window === "undefined") return; var loggedIn = document.cookie.includes("token"); setLoggedIn(loggedIn); if (loggedIn) { await getNotifications(); io.on("incomingFriendRequest", getNotifications); } setGotData(true); })()}, []); return
{ false && }
{ loggedIn &&
setNotificationsAreaVisible(!notificationsAreaVisible)}> { gotNotifications &&
}
} { loggedIn ? : } { loggedIn && }
}