1 | import React, { useEffect } from "react";
|
---|
2 | import {
|
---|
3 | OpinionCard,
|
---|
4 | OpinionCardContent,
|
---|
5 | OpinionCardContentTime,
|
---|
6 | OpinionCardContentTitle,
|
---|
7 | } from "../Components/Styled/OpinionCard.style";
|
---|
8 | import {
|
---|
9 | UserDetailsCard,
|
---|
10 | UserDetailsCardContent,
|
---|
11 | } from "../Components/Styled/UserDetails.style";
|
---|
12 | import { dateConverter } from "../Util/dateConverter";
|
---|
13 |
|
---|
14 | function UserDashboard({ user, userLoaded }) {
|
---|
15 | useEffect(() => {
|
---|
16 | const timer = setTimeout(() => {
|
---|
17 | if (user === null) window.location.reload(false);
|
---|
18 | }, 3000);
|
---|
19 | return () => clearTimeout(timer);
|
---|
20 | }, []);
|
---|
21 |
|
---|
22 | return userLoaded ? (
|
---|
23 | <>
|
---|
24 | <h3>Кориснички податоци:</h3>
|
---|
25 | <UserDetailsCard>
|
---|
26 | {user.fullName && (
|
---|
27 | <UserDetailsCardContent>
|
---|
28 | <b>Име:</b> {user.fullName}{" "}
|
---|
29 | </UserDetailsCardContent>
|
---|
30 | )}
|
---|
31 | <UserDetailsCardContent>
|
---|
32 | <b>Корисничко име:</b> {user.username}{" "}
|
---|
33 | </UserDetailsCardContent>
|
---|
34 | <UserDetailsCardContent>
|
---|
35 | <b>E-mail:</b> {user.email}
|
---|
36 | </UserDetailsCardContent>
|
---|
37 | <UserDetailsCardContent>
|
---|
38 | <b>Карма:</b> {user.karma}
|
---|
39 | </UserDetailsCardContent>
|
---|
40 | </UserDetailsCard>
|
---|
41 | {user.authoredPosts.length > 0 ? (
|
---|
42 | <h3 style={{ marginBottom: "10px" }}>Ваши мислења:</h3>
|
---|
43 | ) : (
|
---|
44 | <h3>Немате објавени мислења</h3>
|
---|
45 | )}
|
---|
46 | {user.authoredPosts.map((post) => {
|
---|
47 | return (
|
---|
48 | <div key={post.postId}>
|
---|
49 | <OpinionCard>
|
---|
50 | <OpinionCardContent>
|
---|
51 | <p>
|
---|
52 | Во дискусија за{" "}
|
---|
53 | <a href={"/professor/" + post.targetProfessor.professorId}>
|
---|
54 | {post.targetProfessor.professorName}
|
---|
55 | </a>
|
---|
56 | </p>
|
---|
57 | <OpinionCardContentTitle>{post.title}</OpinionCardContentTitle>
|
---|
58 | <p>{post.content}</p>
|
---|
59 | <OpinionCardContentTime>
|
---|
60 | {dateConverter(
|
---|
61 | new Date(post.timePosted).toString().slice(4, -43)
|
---|
62 | )}
|
---|
63 | </OpinionCardContentTime>
|
---|
64 | </OpinionCardContent>
|
---|
65 | </OpinionCard>
|
---|
66 | </div>
|
---|
67 | );
|
---|
68 | })}
|
---|
69 | </>
|
---|
70 | ) : (
|
---|
71 | <>се вчитува...</>
|
---|
72 | );
|
---|
73 | }
|
---|
74 |
|
---|
75 | export default UserDashboard;
|
---|