blob: 34766c3932ef7c35ba2d604e1d0890509b8efb19 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
import { useContext } from 'react';
import { AuthContext } from '../Authentication/ContextProvider';
import { User } from '../Authentication/Models';
import { AllowedLanguages, LanguageContext } from '../Locales/Context';
import { GetLocalizedString } from '../Locales/Locales';
import './Elements.css';
import SidebarListElement from './SidebarElement';
type SidebarProps = {
setLang: (newLang: AllowedLanguages) => void;
};
function Sidebar({setLang}: SidebarProps) {
var user = useContext(AuthContext);
var lang = useContext(LanguageContext);
return (
<nav className='Sidebar'>
<div className='SidebarContents'>
<h1> {GetLocalizedString("contents", lang)} </h1>
<ul className='ContentsList'>
<SidebarListElement Href='/' Text='Home' />
<SidebarListElement Href='/classes' Text='Classes' />
<SidebarListElement Href='/weapons' Text='Weapons' />
{ AuthElement(user) }
</ul>
<button onClick={() => {
setLang("ru");
window.location.reload();
}}> ru </button>
<button onClick={() => {
setLang("en");
window.location.reload();
}}> en </button>
</div>
</nav>
);
}
function AuthElement(user: User | null) {
if (user != null) {
return (
<SidebarListElement Href='/logout' Text='Logout' />
);
}
return (
<SidebarListElement Href='/login' Text='Login' />
);
}
export default Sidebar;
|