Changeset 702ca77 for reactapp/src
- Timestamp:
- 08/19/22 19:10:24 (2 years ago)
- Branches:
- main
- Children:
- 6221ab6
- Parents:
- 6eba109
- Location:
- reactapp/src
- Files:
-
- 4 added
- 1 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
reactapp/src/App.js
r6eba109 r702ca77 4 4 import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom"; 5 5 import Home from "./Pages/Home"; 6 import User from "./Pages/User";6 import UserDashboard from "./Pages/UserDashboard"; 7 7 import { useEffect, useState, useMemo } from "react"; 8 8 import AuthApi from "./api/AuthApi"; … … 12 12 const [auth, setAuth] = useState(false); 13 13 const variableAuth = useMemo(() => ({ auth, setAuth }), [auth]); 14 const [authLoaded, setAuthLoaded] = useState(false); 14 15 15 const readCookie = () => {16 const readCookie = async () => { 16 17 const session = Cookies.get("JSESSIONID"); 17 18 if (session) { 18 19 setAuth(true); // go stava true ako postoi takvo cookie (zasto auth=false na sekoe renderiranje) 20 } else { 21 setAuth(false); 19 22 } 23 setAuthLoaded(true); 20 24 }; 21 25 … … 25 29 26 30 const ProtectedRoute = ({ auth, children }) => { 27 if (!auth) { 28 return <Navigate to="/login" replace />; 31 if (authLoaded) { 32 if (!auth) { 33 return <Navigate to="/login" replace />; 34 } 35 return children; 36 } else { 37 return <div>се вчитува cookie...</div>; 29 38 } 30 return children;31 39 }; 32 40 … … 42 50 <Route path="search" element={<SearchResults />}></Route> 43 51 <Route 44 path="user "52 path="user_dashboard" 45 53 element={ 46 54 <ProtectedRoute auth={auth}> 47 <User />55 <UserDashboard /> 48 56 </ProtectedRoute> 49 57 } -
reactapp/src/Components/Logout.js
r6eba109 r702ca77 2 2 import AuthApi from "../api/AuthApi"; 3 3 import Cookies from "js-cookie"; 4 import { LogoutButton } from "./Styled/UserDetails.style"; 5 import { Navigate } from "react-router-dom"; 4 6 5 7 function Logout() { … … 11 13 }; 12 14 13 return < button onClick={handleLogout}>Одјави се</button>;15 return <LogoutButton onClick={handleLogout}>Одјави се</LogoutButton>; 14 16 } 15 17 -
reactapp/src/Components/Search.js
r6eba109 r702ca77 15 15 16 16 useEffect(() => { 17 const url = `http://192.168.0.1 8:8080/public/professors/nameContains/${transliterate(17 const url = `http://192.168.0.17:8080/public/professors/nameContains/${transliterate( 18 18 query 19 19 )}`; … … 23 23 const response = await fetch(url); 24 24 var cyclicGraph = await response.json(); 25 var jsogStructure = JSOG.encode(cyclicGraph); // has { '@ref': 'ID' } links instead of cycles25 var jsogStructure = JSOG.encode(cyclicGraph); 26 26 cyclicGraph = JSOG.decode(jsogStructure); 27 27 setProfessors(cyclicGraph); 28 //setLoaded(true);29 28 } catch (error) { 30 console.log("Fetching error occured", error);29 console.log("Fetching error", error); 31 30 } 32 31 }; -
reactapp/src/Components/Styled/Main.style.js
r6eba109 r702ca77 6 6 margin: auto; 7 7 margin-top: 20px; 8 margin-bottom: 20px; 8 9 padding-left: 50px; 9 10 padding-right: 50px; -
reactapp/src/Components/Styled/Search.style.js
r6eba109 r702ca77 30 30 &:hover { 31 31 background-color: papayawhip; 32 border: 1px solid blue;33 text-decoration: underline 1px blue;32 border: 1px solid #0066cc; 33 text-decoration: underline 1px #0066cc; 34 34 } 35 35 padding: 10px; -
reactapp/src/Pages/Home.js
r6eba109 r702ca77 1 import React from "react";1 import React, { useContext } from "react"; 2 2 import { MainWrapper, MainTitle } from "../Components/Styled/Main.style"; 3 3 import { Outlet } from "react-router-dom"; 4 4 import Search from "../Components/Search"; 5 import UserHeader from "../Components/UserHeader"; 6 import AuthApi from "../api/AuthApi"; 5 7 6 8 function Home() { 9 const { auth, setAuth } = useContext(AuthApi); 10 7 11 return ( 8 12 <MainWrapper> … … 20 24 </a>{" "} 21 25 <Search /> 26 {auth && <UserHeader />} 22 27 <div style={{ marginTop: "140px" }}></div> 23 28 <Outlet /> -
reactapp/src/Pages/Login.js
r6eba109 r702ca77 45 45 }; 46 46 47 const handleLogout = () => {48 setAuth(false);49 Cookies.remove("JSESSIONID");50 };51 52 47 return auth ? ( 53 /* 54 <div style={{ marginTop: "140px" }}> 55 <h1>Успешна најава!</h1> 56 <br /> 57 <p> 58 <a href="/user">Оди на protected</a> 59 </p> 60 <button onClick={handleLogout}>Одјави се</button> 61 </div> 62 */ 63 <Navigate to="/user" /> 48 <Navigate to="/user_dashboard" /> 64 49 ) : ( 65 50 <div style={{ marginTop: "140px" }}> -
reactapp/src/Pages/Professor.js
r6eba109 r702ca77 1 import React, { useEffect, useState } from "react";1 import React, { useEffect, useState, useContext } from "react"; 2 2 import { Outlet, useParams } from "react-router-dom"; 3 3 import JSOG from "jsog"; 4 4 import OpinionTree from "../Components/OpinionTree"; 5 5 import { 6 AddOpinionButton, 7 Modal, 8 ModalContent, 9 ModalClose, 10 ModalHeader, 11 ModalBody, 12 ModalInput, 13 ModalTextarea, 14 ModalFooter, 15 } from "../Components/Styled/Modal.style"; 6 16 import { 7 17 ProfessorCard, … … 10 20 ProfessorCardSeparator, 11 21 } from "../Components/Styled/ProfessorCard.style"; 22 import AuthApi from "../api/AuthApi"; 23 import { useNavigate } from "react-router-dom"; 12 24 13 function Professor( props) {25 function Professor() { 14 26 let params = useParams(); 15 27 16 28 let [professor, setProfessor] = useState(null); 17 29 let [loaded, setLoaded] = useState(null); 30 let [modalDisplay, setModalDisplay] = useState("none"); 31 let navigate = useNavigate(); 32 const { auth, setAuth } = useContext(AuthApi); 33 const [addPostTitle, setAddPostTitle] = useState(""); 34 const [addPostContent, setAddPostContent] = useState(""); 18 35 19 36 useEffect(() => { 20 const url = `http://192.168.0.1 8:8080/public/professor/${params.professorId}`;37 const url = `http://192.168.0.17:8080/public/professor/${params.professorId}`; 21 38 22 39 const fetchData = async () => { … … 24 41 const response = await fetch(url); 25 42 var cyclicGraph = await response.json(); 26 var jsogStructure = JSOG.encode(cyclicGraph); // has { '@ref': 'ID' } links instead of cycles43 var jsogStructure = JSOG.encode(cyclicGraph); 27 44 cyclicGraph = JSOG.decode(jsogStructure); 28 45 setProfessor(cyclicGraph); 29 46 setLoaded(true); 30 47 } catch (error) { 31 console.log(" Error", error);48 console.log("Fetching error", error); 32 49 } 33 50 }; … … 35 52 fetchData(); 36 53 }, [params.professorId]); 54 55 const handleAddOpinionButtonClick = () => { 56 if (auth) { 57 setModalDisplay("block"); 58 } else { 59 navigate("/login"); 60 } 61 }; 62 63 const handleModalCloseClick = () => { 64 setModalDisplay("none"); 65 console.log("here"); 66 }; 67 68 const handlePostSubmit = () => {}; 69 70 const handleTitleChange = (e) => { 71 setAddPostTitle(e.target.value); 72 }; 73 74 const handleContentChange = (e) => { 75 setAddPostContent(e.target.value); 76 }; 37 77 38 78 if (loaded) { … … 51 91 </div> 52 92 </ProfessorCard> 53 <h3 style={{ marginBottom: "10px" }}> 54 {professor.relatedOpinions.length}{" "} 55 {professor.relatedOpinions.length !== 1 ? "мислења" : "мислење"} 56 </h3> 93 <div style={{ height: "20px", marginBottom: "30px" }}> 94 <h3 95 style={{ 96 float: "left", 97 }} 98 > 99 {professor.relatedOpinions.length}{" "} 100 {professor.relatedOpinions.length !== 1 ? "мислења" : "мислење"} 101 </h3> 102 <AddOpinionButton onClick={handleAddOpinionButtonClick}> 103 Објави мислење 104 </AddOpinionButton> 105 </div> 106 107 <Modal display={modalDisplay}> 108 <ModalContent> 109 <ModalHeader> 110 <ModalClose onClick={handleModalCloseClick}>×</ModalClose> 111 <h3 style={{ marginTop: "5px" }}> 112 Мислење за {professor.professorName} 113 </h3> 114 </ModalHeader> 115 <ModalBody> 116 <form onSubmit={handlePostSubmit}> 117 <label for="title"> 118 <b>Наслов</b>: 119 <ModalInput 120 id="title" 121 type="text" 122 value={addPostTitle} 123 onChange={handleTitleChange} 124 /> 125 </label> 126 <label for="content"> 127 <b>Содржина</b>: 128 <ModalTextarea 129 id="content" 130 rows="8" 131 cols="100" 132 value={addPostContent} 133 onChange={handleContentChange} 134 /> 135 </label> 136 </form> 137 </ModalBody> 138 <ModalFooter> 139 <h2 style={{ textAlign: "center" }}>ОБЈАВИ</h2> 140 </ModalFooter> 141 </ModalContent> 142 </Modal> 143 57 144 <div className="opinionTree"> 58 145 <OpinionTree professor={professor} /> -
reactapp/src/api/axios.js
r6eba109 r702ca77 2 2 3 3 export default axios.create({ 4 baseURL: "http://192.168.0.1 8:8080",4 baseURL: "http://192.168.0.17:8080", 5 5 });
Note:
See TracChangeset
for help on using the changeset viewer.