source: reactapp/src/Pages/UserDashboard.js@ 702ca77

main
Last change on this file since 702ca77 was 702ca77, checked in by unknown <mlviktor23@…>, 2 years ago

added current user/logout in header, display karma on user dashboard, started add post functionality in react

  • Property mode set to 100644
File size: 2.9 KB
Line 
1import React, { useState, useEffect } from "react";
2import JSOG from "jsog";
3import axios from "../api/axios";
4import {
5 OpinionCard,
6 OpinionCardContent,
7 OpinionCardContentTime,
8 OpinionCardContentTitle,
9} from "../Components/Styled/OpinionCard.style";
10import {
11 UserDetailsCard,
12 UserDetailsCardContent,
13} from "../Components/Styled/UserDetails.style";
14import { dateConverter } from "../Util/dateConverter";
15
16function 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
97export default UserDashboard;
Note: See TracBrowser for help on using the repository browser.