Changeset 6221ab6 for reactapp/src/Pages
- Timestamp:
- 08/20/22 21:12:04 (2 years ago)
- Branches:
- main
- Children:
- 2fcbde4
- Parents:
- 702ca77
- Location:
- reactapp/src/Pages
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
reactapp/src/Pages/Home.js
r702ca77 r6221ab6 6 6 import AuthApi from "../api/AuthApi"; 7 7 8 function Home( ) {8 function Home({ user, userLoaded }) { 9 9 const { auth, setAuth } = useContext(AuthApi); 10 10 … … 24 24 </a>{" "} 25 25 <Search /> 26 {auth && <UserHeader />}26 {auth && <UserHeader user={user} userLoaded={userLoaded} />} 27 27 <div style={{ marginTop: "140px" }}></div> 28 28 <Outlet /> -
reactapp/src/Pages/Professor.js
r702ca77 r6221ab6 22 22 import AuthApi from "../api/AuthApi"; 23 23 import { useNavigate } from "react-router-dom"; 24 import axios from "../api/axios"; 24 25 25 function Professor( ) {26 function Professor(user, userLoaded) { 26 27 let params = useParams(); 27 28 28 29 let [professor, setProfessor] = useState(null); 29 30 let [loaded, setLoaded] = useState(null); 30 let [ modalDisplay, setModalDisplay] = useState("none");31 let [postModalDisplay, setPostModalDisplay] = useState("none"); 31 32 let navigate = useNavigate(); 32 33 const { auth, setAuth } = useContext(AuthApi); 33 const [ addPostTitle, setAddPostTitle] = useState("");34 const [ addPostContent, setAddPostContent] = useState("");34 const [postTitle, setPostTitle] = useState(""); 35 const [postContent, setPostContent] = useState(""); 35 36 36 37 useEffect(() => { 37 const url = `http://192.168.0.1 7:8080/public/professor/${params.professorId}`;38 const url = `http://192.168.0.19:8080/public/professor/${params.professorId}`; 38 39 39 40 const fetchData = async () => { … … 55 56 const handleAddOpinionButtonClick = () => { 56 57 if (auth) { 57 set ModalDisplay("block");58 setPostModalDisplay("block"); 58 59 } else { 59 60 navigate("/login"); … … 62 63 63 64 const handleModalCloseClick = () => { 64 setModalDisplay("none"); 65 console.log("here"); 65 setPostModalDisplay("none"); 66 66 }; 67 67 68 const handlePostSubmit = () => {}; 68 const handlePostSubmit = async (e) => { 69 e.preventDefault(); 70 71 const response = await axios( 72 `http://192.168.0.19:8080/secure/professor/${professor.professorId}/addOpinion`, 73 { 74 method: "post", 75 data: { 76 title: postTitle, 77 content: postContent, 78 }, 79 withCredentials: true, 80 } 81 ); 82 83 window.location.reload(false); 84 }; 69 85 70 86 const handleTitleChange = (e) => { 71 set AddPostTitle(e.target.value);87 setPostTitle(e.target.value); 72 88 }; 73 89 74 90 const handleContentChange = (e) => { 75 set AddPostContent(e.target.value);91 setPostContent(e.target.value); 76 92 }; 77 93 … … 100 116 {professor.relatedOpinions.length !== 1 ? "мислења" : "мислење"} 101 117 </h3> 102 <AddOpinionButton onClick={handleAddOpinionButtonClick}> 103 Објави мислење 104 </AddOpinionButton> 118 {auth && ( 119 <AddOpinionButton onClick={handleAddOpinionButtonClick}> 120 Објави мислење 121 </AddOpinionButton> 122 )} 105 123 </div> 106 124 107 <Modal display={ modalDisplay}>125 <Modal display={postModalDisplay}> 108 126 <ModalContent> 109 127 <ModalHeader> … … 113 131 </h3> 114 132 </ModalHeader> 115 < ModalBody>116 < form onSubmit={handlePostSubmit}>117 <label for="title">133 <form onSubmit={handlePostSubmit}> 134 <ModalBody> 135 <label htmlFor="title"> 118 136 <b>Наслов</b>: 119 137 <ModalInput 120 138 id="title" 121 139 type="text" 122 value={ addPostTitle}140 value={postTitle} 123 141 onChange={handleTitleChange} 124 142 /> 125 143 </label> 126 <label for="content">144 <label htmlFor="content"> 127 145 <b>Содржина</b>: 128 146 <ModalTextarea … … 130 148 rows="8" 131 149 cols="100" 132 value={ addPostContent}150 value={postContent} 133 151 onChange={handleContentChange} 134 152 /> 135 153 </label> 136 </form> 137 </ModalBody> 138 <ModalFooter> 139 <h2 style={{ textAlign: "center" }}>ОБЈАВИ</h2> 140 </ModalFooter> 154 </ModalBody> 155 <ModalFooter type="submit">ОБЈАВИ</ModalFooter> 156 </form> 141 157 </ModalContent> 142 158 </Modal> 143 159 144 160 <div className="opinionTree"> 145 <OpinionTree professor={professor} /> 161 <OpinionTree 162 professor={professor} 163 user={user} 164 userLoaded={userLoaded} 165 /> 146 166 </div> 147 167 <Outlet /> -
reactapp/src/Pages/UserDashboard.js
r702ca77 r6221ab6 1 import React, { useState, useEffect } from "react"; 2 import JSOG from "jsog"; 3 import axios from "../api/axios"; 1 import React, { useEffect } from "react"; 4 2 import { 5 3 OpinionCard, … … 14 12 import { dateConverter } from "../Util/dateConverter"; 15 13 16 function UserDashboard() { 17 const [user, setUser] = useState(null); 18 const [loaded, setLoaded] = useState(false); 19 14 function UserDashboard({ user, userLoaded }) { 20 15 useEffect(() => { 21 const fetchData = async () => { 22 try { 23 const response = await axios.get( 24 "http://192.168.0.17:8080/secure/currentUser", 25 { withCredentials: true } 26 ); 27 var cyclicGraph = await response.data; 28 var jsogStructure = JSOG.encode(cyclicGraph); 29 cyclicGraph = JSOG.decode(jsogStructure); 30 setUser(cyclicGraph); 31 setLoaded(true); 32 } catch (error) { 33 console.log("Fetching error", error); 34 } 35 }; 36 37 fetchData(); 16 const timer = setTimeout(() => { 17 if (user === null) window.location.reload(false); 18 }, 3000); 19 return () => clearTimeout(timer); 38 20 }, []); 39 21 40 return loaded ? (22 return userLoaded ? ( 41 23 <> 42 24 <h3>Кориснички податоци:</h3>
Note:
See TracChangeset
for help on using the changeset viewer.