]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/common/Header.js
add language switcher
[alttp.git] / resources / js / components / common / Header.js
1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { Button, Container, Nav, Navbar } from 'react-bootstrap';
4 import { LinkContainer } from 'react-router-bootstrap';
5 import { withTranslation } from 'react-i18next';
6
7 import Icon from './Icon';
8 import LanguageSwitcher from './LanguageSwitcher';
9 import { getAvatarUrl } from '../../helpers/User';
10 import { withUser } from '../../helpers/UserContext';
11 import i18n from '../../i18n';
12
13 const Header = ({ doLogout, user }) =>
14         <Navbar id="header" bg="dark" variant="dark">
15                 <Container fluid>
16                         <LinkContainer to="/">
17                                 <Navbar.Brand>
18                                         ALttP
19                                 </Navbar.Brand>
20                         </LinkContainer>
21                         <Navbar.Text className="ms-auto me-2">
22                                 <LanguageSwitcher />
23                         </Navbar.Text>
24                         <Nav>
25                                 {user ?
26                                         <>
27                                                 <LinkContainer to={`/users/${user.id}`}>
28                                                         <Nav.Link>
29                                                                 <img alt="" src={getAvatarUrl(user)} />
30                                                                 {user.username}
31                                                                 <span className="text-muted">#{user.discriminator}</span>
32                                                         </Nav.Link>
33                                                 </LinkContainer>
34                                                 <Button
35                                                         onClick={doLogout}
36                                                         title={i18n.t('button.logout')}
37                                                         variant="outline-secondary"
38                                                 >
39                                                         <Icon.LOGOUT title="" />
40                                                 </Button>
41                                         </>
42                                 :
43                                         <Button href="/login" variant="discord">
44                                                 <Icon.DISCORD />
45                                                 {' '}
46                                                 {i18n.t('button.login')}
47                                         </Button>
48                                 }
49                         </Nav>
50                 </Container>
51         </Navbar>
52 ;
53
54 Header.propTypes = {
55         doLogout: PropTypes.func,
56         user: PropTypes.shape({
57                 avatar: PropTypes.string,
58                 discriminator: PropTypes.string,
59                 id: PropTypes.string,
60                 username: PropTypes.string,
61         }),
62 };
63
64 export default withTranslation()(withUser(Header));