2021-04-25 15:22:52 +00:00
|
|
|
import React, { useContext } from "react"
|
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
|
|
|
|
import { faUser } from "@fortawesome/free-solid-svg-icons"
|
2021-04-29 14:58:31 +00:00
|
|
|
import ContextUser from "../../contexts/ContextUser"
|
2021-05-18 00:04:06 +00:00
|
|
|
import ContextLanguage from "../../contexts/ContextLanguage"
|
2021-04-25 15:22:52 +00:00
|
|
|
|
|
|
|
|
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 }) {
|
2021-05-11 14:37:15 +00:00
|
|
|
const { user } = useContext(ContextUser)
|
2021-05-18 00:48:34 +00:00
|
|
|
const { strings } = useContext(ContextLanguage)
|
2021-04-25 15:22:52 +00:00
|
|
|
|
2021-04-26 16:36:41 +00:00
|
|
|
if(!user) {
|
2021-04-25 15:22:52 +00:00
|
|
|
return (
|
2021-04-26 16:36:41 +00:00
|
|
|
<i {...props}>
|
2021-05-18 00:04:06 +00:00
|
|
|
{strings.notLoggedIn}
|
2021-04-25 15:22:52 +00:00
|
|
|
</i>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-04-26 16:36:41 +00:00
|
|
|
<b {...props}>
|
|
|
|
<FontAwesomeIcon icon={faUser}/> {user.username}
|
2021-04-25 15:22:52 +00:00
|
|
|
</b>
|
|
|
|
)
|
|
|
|
}
|