main
Last change
on this file since c68150f was c68150f, checked in by unknown <mlviktor23@…>, 2 years ago |
left: moderation, oAuth, messaging
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | import React, { useState, useEffect } from "react";
|
---|
2 | import JSOG from "jsog";
|
---|
3 | import axios from "../api/axios";
|
---|
4 | import Logout from "./Logout";
|
---|
5 |
|
---|
6 | function UserHeader({}) {
|
---|
7 | const [user, setUser] = useState(null);
|
---|
8 | const [loadedUser, setLoadedUser] = useState(false);
|
---|
9 | const [fetchError, setFetchError] = useState(false);
|
---|
10 |
|
---|
11 | useEffect(() => {
|
---|
12 | const url = `http://192.168.0.17:8080/secure/currentUser`;
|
---|
13 |
|
---|
14 | const fetchUser = async () => {
|
---|
15 | try {
|
---|
16 | const response = await axios.get(url, { withCredentials: true });
|
---|
17 | var cyclicGraph = await response.data;
|
---|
18 | var jsogStructure = JSOG.encode(cyclicGraph);
|
---|
19 | cyclicGraph = JSOG.decode(jsogStructure);
|
---|
20 | setUser(cyclicGraph);
|
---|
21 | setLoadedUser(true);
|
---|
22 | } catch (error) {
|
---|
23 | setFetchError(true);
|
---|
24 | }
|
---|
25 | };
|
---|
26 |
|
---|
27 | fetchUser();
|
---|
28 | }, []);
|
---|
29 |
|
---|
30 | return loadedUser ? (
|
---|
31 | <div style={{ float: "left", marginTop: 20, marginLeft: 40 }}>
|
---|
32 | Најавен/а: <a href="/user_dashboard">{user.username}</a> <Logout />{" "}
|
---|
33 | </div>
|
---|
34 | ) : (
|
---|
35 | <div style={{ float: "left", marginTop: 25, marginLeft: 60 }}>
|
---|
36 | се вчитува...
|
---|
37 | </div>
|
---|
38 | );
|
---|
39 | }
|
---|
40 |
|
---|
41 | export default UserHeader;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.