source: reactapp/src/Components/OpinionTree.js@ 5347491

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

styled professor page, added date translation to datePosted, added indentation for replies

  • Property mode set to 100644
File size: 2.0 KB
Line 
1import { OpinionCard, OpinionReplyCard } from "./OpinionCard.style";
2import { dateConverter } from "../Util/dateConverter";
3
4function OpinionTree({ professor }) {
5 var renderedOpinionIds = [];
6 var postCount; // za da ne go pokazuva ispod postot
7
8 function displayChildPosts(child, parentPostAuthorUsername, replyIndent) {
9 if (child == null) return;
10 postCount = renderedOpinionIds.push(child.postId);
11 return (
12 <div key={child.postId}>
13 <OpinionReplyCard indent={replyIndent + "px"}>
14 <p>
15 <a href="#">{child.author.username}</a> му реплицирал на{" "}
16 {parentPostAuthorUsername}
17 </p>
18 <p>{child.content}</p>
19 <p>
20 {dateConverter(new Date(child.timePosted).toString().slice(4, -43))}
21 </p>
22 </OpinionReplyCard>
23 {child.children.map((childOfChild) =>
24 displayChildPosts(
25 childOfChild,
26 child.author.username,
27 replyIndent + 30
28 )
29 )}
30 </div>
31 );
32 }
33
34 return (
35 <div className="opinionTree">
36 {professor.relatedOpinions.map((opinion) => {
37 if (!renderedOpinionIds.includes(opinion.postId)) {
38 postCount = renderedOpinionIds.push(opinion.postId);
39 var replyIndent = 30;
40 return (
41 <div key={opinion.postId}>
42 <OpinionCard>
43 <p>
44 <a href="#">{opinion.author.username}</a> напишал
45 </p>
46
47 <p>{opinion.title}</p>
48 <p>{opinion.content}</p>
49 <p>
50 {dateConverter(
51 new Date(opinion.timePosted).toString().slice(4, -43)
52 )}
53 </p>
54 </OpinionCard>
55 {opinion.children.map((child) =>
56 displayChildPosts(child, opinion.author.username, replyIndent)
57 )}
58 </div>
59 );
60 }
61 })}
62 </div>
63 );
64}
65
66export default OpinionTree;
Note: See TracBrowser for help on using the repository browser.