1 | import React, { useState, useEffect } from "react";
|
---|
2 | import JSOG from "jsog";
|
---|
3 | import axios from "../api/axios";
|
---|
4 | import {
|
---|
5 | OpinionCard,
|
---|
6 | OpinionCardContent,
|
---|
7 | OpinionCardContentTime,
|
---|
8 | OpinionCardContentTitle,
|
---|
9 | } from "../Components/Styled/OpinionCard.style";
|
---|
10 | import {
|
---|
11 | UserDetailsCard,
|
---|
12 | UserDetailsCardContent,
|
---|
13 | } from "../Components/Styled/UserDetails.style";
|
---|
14 | import { dateConverter } from "../Util/dateConverter";
|
---|
15 |
|
---|
16 | function UserDashboard() {
|
---|
17 | const [user, setUser] = useState(null);
|
---|
18 | const [loaded, setLoaded] = useState(false);
|
---|
19 |
|
---|
20 | useEffect(() => {
|
---|
21 | const fetchData = async () => {
|
---|
22 | try {
|
---|
23 | const response = await axios.get(
|
---|
24 | "http://192.168.0.17:8080/secure/currentUser",
|
---|
25 | { withCredentials: true }
|
---|
26 | );
|
---|
27 | var cyclicGraph = await response.data;
|
---|
28 | var jsogStructure = JSOG.encode(cyclicGraph);
|
---|
29 | cyclicGraph = JSOG.decode(jsogStructure);
|
---|
30 | setUser(cyclicGraph);
|
---|
31 | setLoaded(true);
|
---|
32 | } catch (error) {
|
---|
33 | console.log("Fetching error", error);
|
---|
34 | }
|
---|
35 | };
|
---|
36 |
|
---|
37 | fetchData();
|
---|
38 | }, []);
|
---|
39 |
|
---|
40 | return loaded ? (
|
---|
41 | <>
|
---|
42 | <h3>Кориснички податоци:</h3>
|
---|
43 | <UserDetailsCard>
|
---|
44 | <UserDetailsCardContent>
|
---|
45 | <b>Име:</b> {user.fullName}{" "}
|
---|
46 | <i style={{ fontSize: 14, color: "#0066cc" }}>
|
---|
47 | (<u>промени</u>)
|
---|
48 | </i>
|
---|
49 | </UserDetailsCardContent>
|
---|
50 | <UserDetailsCardContent>
|
---|
51 | <b>Корисничко име:</b> {user.username}{" "}
|
---|
52 | <i style={{ fontSize: 14, color: "#0066cc" }}>
|
---|
53 | (<u>промени</u>)
|
---|
54 | </i>
|
---|
55 | </UserDetailsCardContent>
|
---|
56 | <UserDetailsCardContent>
|
---|
57 | <b>E-mail:</b> {user.email}
|
---|
58 | </UserDetailsCardContent>
|
---|
59 | <UserDetailsCardContent>
|
---|
60 | <b>Карма:</b> {user.karma}
|
---|
61 | </UserDetailsCardContent>
|
---|
62 | </UserDetailsCard>
|
---|
63 | {user.authoredPosts.length > 0 ? (
|
---|
64 | <h3 style={{ marginBottom: "10px" }}>Ваши мислења:</h3>
|
---|
65 | ) : (
|
---|
66 | <h3>Немате објавени мислења</h3>
|
---|
67 | )}
|
---|
68 | {user.authoredPosts.map((post) => {
|
---|
69 | return (
|
---|
70 | <div key={post.postId}>
|
---|
71 | <OpinionCard>
|
---|
72 | <OpinionCardContent>
|
---|
73 | <p>
|
---|
74 | Во дискусија за{" "}
|
---|
75 | <a href={"/professor/" + post.targetProfessor.professorId}>
|
---|
76 | {post.targetProfessor.professorName}
|
---|
77 | </a>
|
---|
78 | </p>
|
---|
79 | <OpinionCardContentTitle>{post.title}</OpinionCardContentTitle>
|
---|
80 | <p>{post.content}</p>
|
---|
81 | <OpinionCardContentTime>
|
---|
82 | {dateConverter(
|
---|
83 | new Date(post.timePosted).toString().slice(4, -43)
|
---|
84 | )}
|
---|
85 | </OpinionCardContentTime>
|
---|
86 | </OpinionCardContent>
|
---|
87 | </OpinionCard>
|
---|
88 | </div>
|
---|
89 | );
|
---|
90 | })}
|
---|
91 | </>
|
---|
92 | ) : (
|
---|
93 | <>се вчитува...</>
|
---|
94 | );
|
---|
95 | }
|
---|
96 |
|
---|
97 | export default UserDashboard;
|
---|