1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-23 05:24:18 +00:00
pds-2021-g2-nest/code/frontend/src/components/LoggedInUser.js

31 lines
732 B
JavaScript
Raw Normal View History

import React, { useContext } from "react"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faUser } from "@fortawesome/free-solid-svg-icons"
2021-04-26 16:36:41 +00:00
import ContextUser from "../contexts/ContextUser"
2021-04-26 16:36:41 +00:00
/**
* An element displaying inline the currently logged in user.
*
* @param props - Additional props to pass to the element.
* @returns {JSX.Element}
* @constructor
*/
export default function LoggedInUser({ ...props }) {
const {user} = useContext(ContextUser);
2021-04-26 16:36:41 +00:00
if(!user) {
return (
2021-04-26 16:36:41 +00:00
<i {...props}>
Not logged in
</i>
)
}
return (
2021-04-26 16:36:41 +00:00
<b {...props}>
<FontAwesomeIcon icon={faUser}/> {user.username}
</b>
)
}