source: reactapp/src/Components/UserHeader.js@ a5aba17

main
Last change on this file since a5aba17 was af801e3, checked in by viktor <viktor@…>, 2 years ago

finished edit/delete/displace opinion/thread from report (react); todo reporting user/opinion/thread interface, public user pages and messaging (springboot)

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[702ca77]1import React, { useState, useEffect } from "react";
2import JSOG from "jsog";
3import axios from "../api/axios";
4import Logout from "./Logout";
[af801e3]5import LoadingSpinner from "./Styled/LoadingSpinner.style";
[702ca77]6
[c68150f]7function UserHeader({}) {
8 const [user, setUser] = useState(null);
9 const [loadedUser, setLoadedUser] = useState(false);
10 const [fetchError, setFetchError] = useState(false);
11
12 useEffect(() => {
[af801e3]13 const url = `http://192.168.0.29:8080/secure/currentUser`;
[c68150f]14
15 const fetchUser = async () => {
16 try {
17 const response = await axios.get(url, { withCredentials: true });
18 var cyclicGraph = await response.data;
19 var jsogStructure = JSOG.encode(cyclicGraph);
20 cyclicGraph = JSOG.decode(jsogStructure);
21 setUser(cyclicGraph);
22 setLoadedUser(true);
23 } catch (error) {
24 setFetchError(true);
25 }
26 };
27
28 fetchUser();
29 }, []);
30
31 return loadedUser ? (
[702ca77]32 <div style={{ float: "left", marginTop: 20, marginLeft: 40 }}>
33 Најавен/а: <a href="/user_dashboard">{user.username}</a> <Logout />{" "}
34 </div>
35 ) : (
36 <div style={{ float: "left", marginTop: 25, marginLeft: 60 }}>
[af801e3]37 <LoadingSpinner/>
[702ca77]38 </div>
39 );
40}
41
42export default UserHeader;
Note: See TracBrowser for help on using the repository browser.