From e6e74321b7dd62364172155e59b9c08454307f90 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 12 Mar 2021 20:36:33 +0100 Subject: friend requests are in the notification area now :tada: --- components/navbar.tsx | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) (limited to 'components') diff --git a/components/navbar.tsx b/components/navbar.tsx index c2c1299..635be86 100644 --- a/components/navbar.tsx +++ b/components/navbar.tsx @@ -1,4 +1,5 @@ import { CSSProperties, useEffect, useState, ReactNode } from "react"; +import axios from "axios"; import { LogoDark } from "../components/logo"; import { AccountAvatar } from "./account"; @@ -17,6 +18,7 @@ import CloseIcon from '@material-ui/icons/Close'; function NotificationsArea(props: { visible?: boolean; + friendRequests?: Array; }) { return props.visible && - - - - - - - + { /* here should be the game invites */ } + { props.friendRequests?.map(user => ) } } @@ -134,9 +131,31 @@ var NavBarItemStyle: CSSProperties = { export function NavBar() { var [ loggedIn, setLoggedIn ] = useState(false); - useEffect(() => setLoggedIn(document.cookie.includes("token")), []); + var [ gotData, setGotData ] = useState(false); + + var [ friendRequests, setFriendRequests ] = useState>(null); var [ notificationsAreaVisible, setNotificationsAreaVisible ] = useState(false); + var [ gotNotifications, setGotNotifications ] = useState(false); + + useEffect(() => {(async () => { + if (gotData) return; + if (typeof window === "undefined") return; + + var loggedIn = document.cookie.includes("token"); + setLoggedIn(loggedIn); + + if (loggedIn) { + var friendRequestsReq = await axios.request<{ requests: Array }>({ + method: "get", + url: `/api/social/list/requests` + }); + setFriendRequests(friendRequestsReq.data.requests); + setGotNotifications(true); + } + + setGotData(true); + })()}); return
setNotificationsAreaVisible(!notificationsAreaVisible)}> -
+ }}/> }
- + } { -- cgit v1.2.3