Skip to content

Commit

Permalink
WIP: fix login and fix user image
Browse files Browse the repository at this point in the history
Signed-off-by: Vallari Agrawal <[email protected]>
  • Loading branch information
VallariAg committed Sep 13, 2024
1 parent 6e2c080 commit ae9008e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
22 changes: 9 additions & 13 deletions src/components/Login/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ import Menu from '@mui/material/Menu';
import MenuItem from '@mui/material/MenuItem';
import GitHubIcon from '@mui/icons-material/GitHub';

import { doLogin, doLogout, useSession, useUserData } from "../../lib/teuthologyAPI";
import { doLogin, doLogout, useSession, getUserData } from "../../lib/teuthologyAPI";


export default function Login() {
const sessionQuery = useSession();
const userData = useUserData();
const [anchorEl, setAnchorEl] = useState(null);
const open = Boolean(anchorEl);
const userData = getUserData();
const [dropMenuAnchor, setDropMenuAnchor] = useState(null);
const open = Boolean(dropMenuAnchor);
const handleClick = (event) => {
setAnchorEl(event.currentTarget);
setDropMenuAnchor(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
setDropMenuAnchor(null);
};

if ( ! sessionQuery.isSuccess ) return null;
console.log(userData);

return (
<div>
Expand All @@ -30,23 +31,18 @@ export default function Login() {
alt={userData.get("username") || ""}
src={userData.get("avatar_url") || ""}
onClick={handleClick}
aria-controls={open ? 'basic-menu' : undefined}
aria-expanded={open ? 'true' : undefined}
/>
<Menu
id="basic-menu"
anchorEl={anchorEl}
anchorEl={dropMenuAnchor}
open={open}
onClose={handleClose}
MenuListProps={{
'aria-labelledby': 'basic-button',
}}
>
<MenuItem onClick={doLogout}>Logout</MenuItem>
</Menu>
</div>
: <Button
variant="contained"
color="success"
onClick={doLogin}
startIcon={<GitHubIcon fontSize="small" /> }
disabled={sessionQuery.isError}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/teuthologyAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function useSession(): UseQueryResult<Session> {
return query;
}

function useUserData(): Map<string, string> {
function getUserData(): Map<string, string> {
const cookies = new Cookies();
const cookie = cookies.get(GH_USER_COOKIE);
if (cookie) {
Expand Down Expand Up @@ -75,6 +75,6 @@ export {
doLogin,
doLogout,
useSession,
useUserData,
getUserData,
useRunKill,
}

0 comments on commit ae9008e

Please sign in to comment.