Ignore:
Timestamp:
01/20/23 22:57:18 (21 months ago)
Author:
viktor <viktor@…>
Branches:
main
Children:
8dffe02
Parents:
4abf55a
Message:

prefinal

File:
1 edited

Legend:

Unmodified
Added
Removed
  • reactapp/src/Components/OpinionTree.js

    r4abf55a r9bf1f8d  
    2626import axios from "../api/axios";
    2727
    28 function OpinionTree({ professor }) {
     28const OpinionTree = ({professor, relatedOpinions}) => {
    2929  var renderedOpinionIds = [];
    3030  var postCount; // za da ne go pokazuva ispod postot
     
    3535  const [replyModalDisplay, setReplyModalDisplay] = useState("none");
    3636  const [replyContent, setReplyContent] = useState("");
    37   const [postForModal, setPostForModal] = useState(null);
     37  const [postForReplyModal, setPostForReplyModal] = useState(null);
     38  const [reportModalDisplay, setReportModalDisplay] = useState("none");
     39  const [reportContent, setReportContent] = useState("")
     40  const [postForReportModal, setPostForReportModal] = useState(null);
     41
    3842  const [user, setUser] = useState(null);
    3943  const [loadedUser, setLoadedUser] = useState(false);
     
    4246
    4347  useEffect(() => {
    44     const url = `http://192.168.0.29:8080/secure/currentUser`;
     48    const url = `http://192.168.1.254:8080/secure/currentUser`;
    4549
    4650    const fetchUser = async () => {
     
    6872      ) {
    6973        const response = await axios(
    70           `http://192.168.0.29:8080/secure/upvoteOpinion/${post.postId}`,
     74          `http://192.168.1.254:8080/secure/upvoteOpinion/${post.postId}`,
    7175          {
    7276            method: "get",
     
    9195      ) {
    9296        const response = await axios(
    93           `http://192.168.0.29:8080/secure/downvoteOpinion/${post.postId}`,
     97          `http://192.168.1.254:8080/secure/downvoteOpinion/${post.postId}`,
    9498          {
    9599            method: "get",
     
    110114    if (auth) {
    111115      setReplyModalDisplay("block");
    112       setPostForModal(opinion);
     116      setPostForReplyModal(opinion);
    113117      document.body.style.overflowY = "hidden";
    114118    } else {
     
    116120    }
    117121  };
     122
     123  const handleReport = (opinion) => {
     124    if (auth) {
     125      setReportModalDisplay("block");
     126      setPostForReportModal(opinion);
     127      document.body.style.overflowY = "hidden";
     128    } else {
     129      navigate("/login");
     130    }
     131  }
    118132
    119133  const handleModalCloseClick = () => {
    120134    setReplyModalDisplay("none");
     135    setReportModalDisplay("none");
    121136    document.body.style.overflowY = "auto";
    122137  };
    123138
    124   const handleContentChange = (e) => {
     139  const handleReplyContentChange = (e) => {
    125140    setReplyContent(e.target.value);
     141  };
     142
     143  const handleReportContentChange = (e) => {
     144    setReportContent(e.target.value);
    126145  };
    127146
     
    131150    if (!replyContent.length < 1) {
    132151      const response = await axios(
    133         `http://192.168.0.29:8080/secure/professor/${professor.professorId}/replyToOpinion/${postId}`,
     152        `http://192.168.1.254:8080/secure/professor/${professor.professorId}/replyToOpinion/${postId}`,
    134153        {
    135154          method: "post",
     
    147166  };
    148167
     168  const handleReportSubmit = async (e, postId) => {
     169    e.preventDefault();
     170
     171    if (!reportContent.length < 1) {
     172      const response = await axios(
     173          `http://192.168.1.254:8080/secure/reportOpinion/${postId}`,
     174          {
     175            method: "post",
     176            data: {
     177              description: reportContent,
     178            },
     179            withCredentials: true,
     180          }
     181      );
     182      setErrorMessage("");
     183      window.location.reload();
     184    } else {
     185      setErrorMessage("Полето за содржина не смее да биде празно");
     186    }
     187  };
     188
    149189  function displayChildPosts(child, parentPostAuthorUsername, replyIndent) {
    150190    if (child == null) return;
    151     postCount = renderedOpinionIds.push(child.postId);
     191    if (!renderedOpinionIds.includes(child.postId)) {postCount = renderedOpinionIds.push(child.postId);}
    152192    return (
    153193      <div key={child.postId}>
     
    158198              му реплицирал на {parentPostAuthorUsername}
    159199            </p>
    160             <p style={{ marginBottom: "10px", maxWidth: "90%" }}>
     200            <p style={{ marginBottom: "10px", maxWidth: "85%" }}>
    161201              {child.content}
    162202            </p>
     
    228268                onClick={() => handleReply(child)}
    229269              />
     270
     271              <StyledFontAwesomeIcon
     272                  icon={solid("flag")}
     273                  right={130 + "px"}
     274                  color="darkgrey"
     275                  onClick={() => handleReport(child)}
     276              />
    230277            </div>
    231278          </OpinionReplyCardContent>
     
    244291  return (
    245292    <div className="opinionTree">
    246       {professor.relatedOpinions.map((opinion) => {
    247         if (!renderedOpinionIds.includes(opinion.postId)) {
     293      {relatedOpinions.map((opinion) => {
     294        if (!renderedOpinionIds.includes(opinion.postId) && opinion.parent === null) {
    248295          postCount = renderedOpinionIds.push(opinion.postId);
    249296          return (
     
    257304                    напишал
    258305                  </p>
    259                   <p style={{ marginBottom: "10px", maxWidth: "90%" }}>
     306                  <p style={{ marginBottom: "10px", maxWidth: "85%" }}>
    260307                    {opinion.content}
    261308                  </p>
     
    335382                      onClick={() => handleReply(opinion)}
    336383                    />
     384
     385                    <StyledFontAwesomeIcon
     386                        icon={solid("flag")}
     387                        right={130 + "px"}
     388                        color="darkgrey"
     389                        onClick={() => handleReport(opinion)}
     390                    />
    337391                  </div>
    338392                </OpinionCardContent>
     
    346400        return null;
    347401      })}
    348       {postForModal && (
     402      {postForReplyModal && (
    349403        <Modal display={replyModalDisplay}>
    350404          <ModalContent>
     
    352406              <ModalClose onClick={handleModalCloseClick}>&times;</ModalClose>
    353407              <h3 style={{ marginTop: "5px" }}>
    354                 Реплика на {postForModal.author.username}
     408                Реплика на {postForReplyModal.author.username}
    355409              </h3>
    356410            </ModalHeader>
    357             <form onSubmit={(e) => handleReplySubmit(e, postForModal.postId)}>
     411            <form onSubmit={(e) => handleReplySubmit(e, postForReplyModal.postId)}>
    358412              <ModalBody>
    359413                <label htmlFor="content">
     
    364418                    cols="100"
    365419                    value={replyContent}
    366                     onChange={handleContentChange}
     420                    onChange={handleReplyContentChange}
    367421                    spellCheck={false}
    368422                  />
     
    379433        </Modal>
    380434      )}
     435      {postForReportModal && (
     436          <Modal display={reportModalDisplay}>
     437            <ModalContent>
     438              <ModalHeader>
     439                <ModalClose onClick={handleModalCloseClick}>&times;</ModalClose>
     440                <h3 style={{ marginTop: "5px" }}>
     441                  Пријава за мислење #{postForReportModal.postId}
     442                </h3>
     443              </ModalHeader>
     444              <form onSubmit={(e) => handleReportSubmit(e, postForReportModal.postId)}>
     445                <ModalBody>
     446                  <label htmlFor="content">
     447                    <b>Наведете причина</b>:
     448                    <ModalTextarea
     449                        id="content"
     450                        rows="8"
     451                        cols="100"
     452                        value={reportContent}
     453                        onChange={handleReportContentChange}
     454                        spellCheck={false}
     455                    />
     456                  </label>
     457                </ModalBody>
     458                <p
     459                    style={{ color: "red", marginLeft: "15px", marginTop: "10px" }}
     460                >
     461                  {errorMessage}
     462                </p>
     463                <ModalFooter type="submit">ПРИЈАВИ</ModalFooter>
     464              </form>
     465            </ModalContent>
     466          </Modal>
     467      )}
    381468    </div>
    382469  );
Note: See TracChangeset for help on using the changeset viewer.