commit db0f300f423cf9260efbc84ed8dd1a6719d4ed75
Author: Jaroslav Hrubý <hrubyj@students.zcu.cz>
Date:   Sun May 15 18:13:34 2022 +0200

    Displaying username in navigation bar

diff --git a/webapp/api/api.ts b/webapp/api/api.ts
index 50cf8c7..319fef9 100644
--- a/webapp/api/api.ts
+++ b/webapp/api/api.ts
@@ -1160,6 +1160,25 @@ export interface UserList {
      */
     'users'?: Array<UserInfo> | null;
 }
+/**
+ * 
+ * @export
+ * @interface UserMeResponse
+ */
+export interface UserMeResponse {
+    /**
+     * 
+     * @type {string}
+     * @memberof UserMeResponse
+     */
+    'name'?: string | null;
+    /**
+     * 
+     * @type {ERole}
+     * @memberof UserMeResponse
+     */
+    'role'?: ERole;
+}
 
 /**
  * AnnotationApi - axios parameter creator
@@ -3160,6 +3179,35 @@ export const UserApiAxiosParamCreator = function (configuration?: Configuration)
 
 
     
+            setSearchParams(localVarUrlObj, localVarQueryParameter);
+            let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
+            localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
+
+            return {
+                url: toPathString(localVarUrlObj),
+                options: localVarRequestOptions,
+            };
+        },
+        /**
+         * 
+         * @param {*} [options] Override http request option.
+         * @throws {RequiredError}
+         */
+        usersMeGet: async (options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
+            const localVarPath = `/users/me`;
+            // use dummy base URL string because the URL constructor only accepts absolute URLs.
+            const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
+            let baseOptions;
+            if (configuration) {
+                baseOptions = configuration.baseOptions;
+            }
+
+            const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
+            const localVarHeaderParameter = {} as any;
+            const localVarQueryParameter = {} as any;
+
+
+    
             setSearchParams(localVarUrlObj, localVarQueryParameter);
             let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
             localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
@@ -3261,6 +3309,15 @@ export const UserApiFp = function(configuration?: Configuration) {
             const localVarAxiosArgs = await localVarAxiosParamCreator.usersGet(options);
             return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
         },
+        /**
+         * 
+         * @param {*} [options] Override http request option.
+         * @throws {RequiredError}
+         */
+        async usersMeGet(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<UserMeResponse>> {
+            const localVarAxiosArgs = await localVarAxiosParamCreator.usersMeGet(options);
+            return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
+        },
         /**
          * 
          * @param {CreateUserRequest} [createUserRequest] 
@@ -3325,6 +3382,14 @@ export const UserApiFactory = function (configuration?: Configuration, basePath?
         usersGet(options?: any): AxiosPromise<UserList> {
             return localVarFp.usersGet(options).then((request) => request(axios, basePath));
         },
+        /**
+         * 
+         * @param {*} [options] Override http request option.
+         * @throws {RequiredError}
+         */
+        usersMeGet(options?: any): AxiosPromise<UserMeResponse> {
+            return localVarFp.usersMeGet(options).then((request) => request(axios, basePath));
+        },
         /**
          * 
          * @param {CreateUserRequest} [createUserRequest] 
@@ -3398,6 +3463,16 @@ export class UserApi extends BaseAPI {
         return UserApiFp(this.configuration).usersGet(options).then((request) => request(this.axios, this.basePath));
     }
 
+    /**
+     * 
+     * @param {*} [options] Override http request option.
+     * @throws {RequiredError}
+     * @memberof UserApi
+     */
+    public usersMeGet(options?: AxiosRequestConfig) {
+        return UserApiFp(this.configuration).usersMeGet(options).then((request) => request(this.axios, this.basePath));
+    }
+
     /**
      * 
      * @param {CreateUserRequest} [createUserRequest] 
diff --git a/webapp/components/navigation/AdminNavBar.tsx b/webapp/components/navigation/AdminNavBar.tsx
index 7e5a413..29e1bd2 100644
--- a/webapp/components/navigation/AdminNavBar.tsx
+++ b/webapp/components/navigation/AdminNavBar.tsx
@@ -1,4 +1,4 @@
-import React, { useCallback, useContext } from 'react';
+import React, { useCallback, useContext, useEffect, useState } from 'react';
 import { Menu } from 'antd';
 import { useRouter } from 'next/router';
 import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
@@ -11,17 +11,29 @@ import {
     faTags,
     faBookmark,
 } from '@fortawesome/free-solid-svg-icons';
+import { userController } from '../../controllers';
+import { UserInfo } from '../../api';
 
 const AdminNavBar = () => {
     const router = useRouter();
     const { logout } = useContext(LoggedUserContext);
     const { SubMenu } = Menu;
+    const [name, setName] = useState<string>('');
 
     const handleLogout = useCallback(() => {
         logout();
         router.push('/login');
     }, [logout, router]);
 
+    async function fetchUsername() {
+        let usr = (await userController.usersMeGet()).data.name;
+        setName(usr ? usr : '');
+    }
+
+    useEffect(() => {
+        fetchUsername();
+    }, []);
+
     return (
         <Menu theme="dark" mode="horizontal">
             <Menu.Item style={{}} key="1" onClick={() => router.push('/documents/admin')}>
@@ -37,11 +49,7 @@ const AdminNavBar = () => {
                 <FontAwesomeIcon icon={faFileExport} /> Export
             </Menu.Item>
 
-            <SubMenu
-                icon={<FontAwesomeIcon icon={faUser} />}
-                key="account"
-                title={'Admin XY'} // TODO show username
-            >
+            <SubMenu icon={<FontAwesomeIcon icon={faUser} />} key="account" title={name}>
                 <Menu.Item key="setting:2" onClick={() => handleLogout()}>
                     Odhlásit se
                 </Menu.Item>
diff --git a/webapp/components/navigation/UserNavBar.tsx b/webapp/components/navigation/UserNavBar.tsx
index 83b23f0..f2bcfc7 100644
--- a/webapp/components/navigation/UserNavBar.tsx
+++ b/webapp/components/navigation/UserNavBar.tsx
@@ -1,31 +1,38 @@
-import React, { useCallback, useContext } from 'react';
+import React, { useCallback, useContext, useEffect, useState } from 'react';
 import { Menu } from 'antd';
 import { useRouter } from 'next/router';
 import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
 import { faFileLines, faUser } from '@fortawesome/free-solid-svg-icons';
 import { LoggedUserContext } from '../../contexts/LoggedUserContext';
+import { userController } from '../../controllers';
 
 const UserNavBar = () => {
     const router = useRouter();
     const { logout } = useContext(LoggedUserContext);
     const { SubMenu } = Menu;
+    const [name, setName] = useState<string>('');
 
     const handleLogout = useCallback(() => {
         logout();
         router.push('/login');
     }, [logout, router]);
 
+    async function fetchUsername() {
+        let usr = (await userController.usersMeGet()).data.name;
+        setName(usr ? usr : '');
+    }
+
+    useEffect(() => {
+        fetchUsername();
+    }, []);
+
     return (
         <Menu theme="dark" mode="horizontal">
             <Menu.Item key="1" onClick={() => router.push('/documents/annotator')}>
                 <FontAwesomeIcon icon={faFileLines} /> Dokumenty
             </Menu.Item>
 
-            <SubMenu
-                key="account"
-                icon={<FontAwesomeIcon icon={faUser} />}
-                title={'Anotátor XY'} // TODO show username
-            >
+            <SubMenu key="account" icon={<FontAwesomeIcon icon={faUser} />} title={name}>
                 <Menu.Item key="setting:2" onClick={() => handleLogout()}>
                     Odhlásit se
                 </Menu.Item>
