source: reactapp/src/Pages/UserDashboard.js@ c68150f

main
Last change on this file since c68150f was c68150f, checked in by unknown <mlviktor23@…>, 21 months ago

left: moderation, oAuth, messaging

  • Property mode set to 100644
File size: 3.7 KB
Line 
1import React, { useEffect, useState, useContext } from "react";
2import {
3 OpinionCard,
4 OpinionCardContent,
5 OpinionCardContentTime,
6} from "../Components/Styled/OpinionCard.style";
7import {
8 UserDetailsCard,
9 UserDetailsCardContent,
10} from "../Components/Styled/UserDetails.style";
11import { dateConverter } from "../Util/dateConverter";
12import axios from "../api/axios";
13import JSOG from "jsog";
14import AuthApi from "../api/AuthApi";
15
16function UserDashboard() {
17 const { auth, setAuth } = useContext(AuthApi);
18
19 const [user, setUser] = useState(null);
20 const [loadedUser, setLoadedUser] = useState(false);
21 const [fetchError, setFetchError] = useState(false);
22
23 useEffect(() => {
24 const url = `http://192.168.0.17:8080/secure/currentUser`;
25
26 const fetchUser = async () => {
27 try {
28 const response = await axios.get(url, { withCredentials: true });
29 var cyclicGraph = await response.data;
30 var jsogStructure = JSOG.encode(cyclicGraph);
31 cyclicGraph = JSOG.decode(jsogStructure);
32 setUser(cyclicGraph);
33 setLoadedUser(true);
34 } catch (error) {
35 setFetchError(true);
36 }
37 };
38
39 if (auth) fetchUser();
40 }, []);
41
42 // useEffect(() => {
43 // const timer = setTimeout(() => {
44 // if (user === null) window.location.reload(false); <---- :-)
45 // }, 3000);
46 // return () => clearTimeout(timer);
47 // }, []);
48
49 function findParentThread(post) {
50 if (post.parent === null) return post;
51 return findParentThread(post.parent);
52 }
53
54 return loadedUser ? (
55 <>
56 <h3>Кориснички податоци:</h3>
57 <UserDetailsCard>
58 {user.fullName && (
59 <UserDetailsCardContent>
60 <b>Име:</b> {user.fullName}{" "}
61 </UserDetailsCardContent>
62 )}
63 <UserDetailsCardContent>
64 <b>Корисничко име:</b> {user.username}{" "}
65 </UserDetailsCardContent>
66 <UserDetailsCardContent>
67 <b>E-mail:</b> {user.email}
68 </UserDetailsCardContent>
69 <UserDetailsCardContent>
70 <b>Карма:</b> {user.karma}
71 </UserDetailsCardContent>
72 </UserDetailsCard>
73 {user.authoredPosts.length > 0 ? (
74 <h3 style={{ marginBottom: "10px" }}>Ваши мислења:</h3>
75 ) : (
76 <h3>Немате објавени мислења</h3>
77 )}
78 {user.authoredPosts.map((post) => {
79 return (
80 <div key={post.postId}>
81 <OpinionCard>
82 <OpinionCardContent>
83 <p style={{ fontStyle: "italic", marginBottom: "10px" }}>
84 во дискусија за{" "}
85 {post.targetProfessor !== undefined ? (
86 <a href={"/professor/" + post.targetProfessor.professorId}>
87 {post.targetProfessor.professorName}
88 </a>
89 ) : (
90 <a
91 href={
92 post.parent === null
93 ? "/topic/" + post.postId
94 : "/topic/" + findParentThread(post).postId
95 }
96 >
97 {post.targetSubject.subjectName}
98 </a>
99 )}
100 </p>
101 <p style={{ marginBottom: "10px" }}>{post.content}</p>
102 <OpinionCardContentTime>
103 {dateConverter(
104 new Date(post.timePosted).toString().slice(4, -43)
105 )}
106 </OpinionCardContentTime>
107 </OpinionCardContent>
108 </OpinionCard>
109 </div>
110 );
111 })}
112 </>
113 ) : (
114 <>се вчитува...</>
115 );
116}
117
118export default UserDashboard;
Note: See TracBrowser for help on using the repository browser.