Changeset 9bf1f8d for reactapp/src/Components/OpinionTree.js
- Timestamp:
- 01/20/23 22:57:18 (21 months ago)
- Branches:
- main
- Children:
- 8dffe02
- Parents:
- 4abf55a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
reactapp/src/Components/OpinionTree.js
r4abf55a r9bf1f8d 26 26 import axios from "../api/axios"; 27 27 28 function OpinionTree({ professor }){28 const OpinionTree = ({professor, relatedOpinions}) => { 29 29 var renderedOpinionIds = []; 30 30 var postCount; // za da ne go pokazuva ispod postot … … 35 35 const [replyModalDisplay, setReplyModalDisplay] = useState("none"); 36 36 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 38 42 const [user, setUser] = useState(null); 39 43 const [loadedUser, setLoadedUser] = useState(false); … … 42 46 43 47 useEffect(() => { 44 const url = `http://192.168. 0.29:8080/secure/currentUser`;48 const url = `http://192.168.1.254:8080/secure/currentUser`; 45 49 46 50 const fetchUser = async () => { … … 68 72 ) { 69 73 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}`, 71 75 { 72 76 method: "get", … … 91 95 ) { 92 96 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}`, 94 98 { 95 99 method: "get", … … 110 114 if (auth) { 111 115 setReplyModalDisplay("block"); 112 setPostFor Modal(opinion);116 setPostForReplyModal(opinion); 113 117 document.body.style.overflowY = "hidden"; 114 118 } else { … … 116 120 } 117 121 }; 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 } 118 132 119 133 const handleModalCloseClick = () => { 120 134 setReplyModalDisplay("none"); 135 setReportModalDisplay("none"); 121 136 document.body.style.overflowY = "auto"; 122 137 }; 123 138 124 const handle ContentChange = (e) => {139 const handleReplyContentChange = (e) => { 125 140 setReplyContent(e.target.value); 141 }; 142 143 const handleReportContentChange = (e) => { 144 setReportContent(e.target.value); 126 145 }; 127 146 … … 131 150 if (!replyContent.length < 1) { 132 151 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}`, 134 153 { 135 154 method: "post", … … 147 166 }; 148 167 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 149 189 function displayChildPosts(child, parentPostAuthorUsername, replyIndent) { 150 190 if (child == null) return; 151 postCount = renderedOpinionIds.push(child.postId);191 if (!renderedOpinionIds.includes(child.postId)) {postCount = renderedOpinionIds.push(child.postId);} 152 192 return ( 153 193 <div key={child.postId}> … … 158 198 му реплицирал на {parentPostAuthorUsername} 159 199 </p> 160 <p style={{ marginBottom: "10px", maxWidth: " 90%" }}>200 <p style={{ marginBottom: "10px", maxWidth: "85%" }}> 161 201 {child.content} 162 202 </p> … … 228 268 onClick={() => handleReply(child)} 229 269 /> 270 271 <StyledFontAwesomeIcon 272 icon={solid("flag")} 273 right={130 + "px"} 274 color="darkgrey" 275 onClick={() => handleReport(child)} 276 /> 230 277 </div> 231 278 </OpinionReplyCardContent> … … 244 291 return ( 245 292 <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) { 248 295 postCount = renderedOpinionIds.push(opinion.postId); 249 296 return ( … … 257 304 напишал 258 305 </p> 259 <p style={{ marginBottom: "10px", maxWidth: " 90%" }}>306 <p style={{ marginBottom: "10px", maxWidth: "85%" }}> 260 307 {opinion.content} 261 308 </p> … … 335 382 onClick={() => handleReply(opinion)} 336 383 /> 384 385 <StyledFontAwesomeIcon 386 icon={solid("flag")} 387 right={130 + "px"} 388 color="darkgrey" 389 onClick={() => handleReport(opinion)} 390 /> 337 391 </div> 338 392 </OpinionCardContent> … … 346 400 return null; 347 401 })} 348 {postFor Modal && (402 {postForReplyModal && ( 349 403 <Modal display={replyModalDisplay}> 350 404 <ModalContent> … … 352 406 <ModalClose onClick={handleModalCloseClick}>×</ModalClose> 353 407 <h3 style={{ marginTop: "5px" }}> 354 Реплика на {postFor Modal.author.username}408 Реплика на {postForReplyModal.author.username} 355 409 </h3> 356 410 </ModalHeader> 357 <form onSubmit={(e) => handleReplySubmit(e, postFor Modal.postId)}>411 <form onSubmit={(e) => handleReplySubmit(e, postForReplyModal.postId)}> 358 412 <ModalBody> 359 413 <label htmlFor="content"> … … 364 418 cols="100" 365 419 value={replyContent} 366 onChange={handle ContentChange}420 onChange={handleReplyContentChange} 367 421 spellCheck={false} 368 422 /> … … 379 433 </Modal> 380 434 )} 435 {postForReportModal && ( 436 <Modal display={reportModalDisplay}> 437 <ModalContent> 438 <ModalHeader> 439 <ModalClose onClick={handleModalCloseClick}>×</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 )} 381 468 </div> 382 469 );
Note:
See TracChangeset
for help on using the changeset viewer.