1 | import React, {useEffect, useState} from 'react';
|
---|
2 | import {UserDetailsCard, UserDetailsCardContent} from "../Components/Styled/UserDetails.style";
|
---|
3 | import {useParams} from "react-router-dom";
|
---|
4 | import JSOG from "jsog";
|
---|
5 | import LoadingSpinner from "../Components/Styled/LoadingSpinner.style";
|
---|
6 |
|
---|
7 | const PublicUserProfile = () => {
|
---|
8 | let params = useParams();
|
---|
9 |
|
---|
10 | const [publicProfile, setPublicProfile] = useState(null);
|
---|
11 | const [loadedPublicProfile, setLoadedPublicProfile] = useState(false);
|
---|
12 |
|
---|
13 | useEffect(() => {
|
---|
14 | const fetchPublicProfile = async () => {
|
---|
15 | const resp = await fetch(`http://192.168.1.254:8080/public/user/${params.userId}`)
|
---|
16 | let cyclicGraph = await resp.json();
|
---|
17 | let jsogStructure = JSOG.encode(cyclicGraph);
|
---|
18 | cyclicGraph = JSOG.decode(jsogStructure);
|
---|
19 | setPublicProfile(cyclicGraph);
|
---|
20 | setLoadedPublicProfile(true);
|
---|
21 | }
|
---|
22 | fetchPublicProfile();
|
---|
23 | },
|
---|
24 | []
|
---|
25 | )
|
---|
26 |
|
---|
27 | return <>
|
---|
28 | {loadedPublicProfile ?
|
---|
29 | (<>
|
---|
30 | <h3>Кориснички податоци за корисник #{publicProfile.id}:</h3>
|
---|
31 | <UserDetailsCard>
|
---|
32 | {publicProfile.fullName && (
|
---|
33 | <UserDetailsCardContent>
|
---|
34 | <b>Име:</b> {publicProfile.fullName}{" "}
|
---|
35 | </UserDetailsCardContent>
|
---|
36 | )}
|
---|
37 | <UserDetailsCardContent>
|
---|
38 | <b>Корисничко име:</b> {publicProfile.username}{" "}
|
---|
39 | </UserDetailsCardContent>
|
---|
40 | <UserDetailsCardContent>
|
---|
41 | <b>E-mail:</b> {publicProfile.email}
|
---|
42 | </UserDetailsCardContent>
|
---|
43 | <UserDetailsCardContent>
|
---|
44 | <b>Карма:</b>{" "}
|
---|
45 | <span style={{color: publicProfile.karma < 0 ? "indianred" : "green"}}>
|
---|
46 | {publicProfile.karma}
|
---|
47 | </span>
|
---|
48 | </UserDetailsCardContent>
|
---|
49 | </UserDetailsCard>
|
---|
50 | </>)
|
---|
51 | :
|
---|
52 | <LoadingSpinner/>
|
---|
53 | }
|
---|
54 | </>
|
---|
55 | };
|
---|
56 |
|
---|
57 | export default PublicUserProfile;
|
---|