[5347491] | 1 | import { OpinionCard, OpinionReplyCard } from "./OpinionCard.style";
|
---|
| 2 | import { dateConverter } from "../Util/dateConverter";
|
---|
[e958037] | 3 |
|
---|
[3a44163] | 4 | function OpinionTree({ professor }) {
|
---|
[2998dc4] | 5 | var renderedOpinionIds = [];
|
---|
| 6 | var postCount; // za da ne go pokazuva ispod postot
|
---|
| 7 |
|
---|
[5347491] | 8 | function displayChildPosts(child, parentPostAuthorUsername, replyIndent) {
|
---|
[2998dc4] | 9 | if (child == null) return;
|
---|
| 10 | postCount = renderedOpinionIds.push(child.postId);
|
---|
[3a44163] | 11 | return (
|
---|
[2998dc4] | 12 | <div key={child.postId}>
|
---|
[5347491] | 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 | )}
|
---|
[3a44163] | 30 | </div>
|
---|
| 31 | );
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | return (
|
---|
| 35 | <div className="opinionTree">
|
---|
| 36 | {professor.relatedOpinions.map((opinion) => {
|
---|
[2998dc4] | 37 | if (!renderedOpinionIds.includes(opinion.postId)) {
|
---|
| 38 | postCount = renderedOpinionIds.push(opinion.postId);
|
---|
[5347491] | 39 | var replyIndent = 30;
|
---|
[3a44163] | 40 | return (
|
---|
| 41 | <div key={opinion.postId}>
|
---|
[e958037] | 42 | <OpinionCard>
|
---|
| 43 | <p>
|
---|
| 44 | <a href="#">{opinion.author.username}</a> напишал
|
---|
| 45 | </p>
|
---|
| 46 |
|
---|
| 47 | <p>{opinion.title}</p>
|
---|
| 48 | <p>{opinion.content}</p>
|
---|
[5347491] | 49 | <p>
|
---|
| 50 | {dateConverter(
|
---|
| 51 | new Date(opinion.timePosted).toString().slice(4, -43)
|
---|
| 52 | )}
|
---|
| 53 | </p>
|
---|
[e958037] | 54 | </OpinionCard>
|
---|
[5347491] | 55 | {opinion.children.map((child) =>
|
---|
| 56 | displayChildPosts(child, opinion.author.username, replyIndent)
|
---|
| 57 | )}
|
---|
[3a44163] | 58 | </div>
|
---|
| 59 | );
|
---|
| 60 | }
|
---|
| 61 | })}
|
---|
| 62 | </div>
|
---|
| 63 | );
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | export default OpinionTree;
|
---|