Changeset c68150f for reactapp/src/Pages/UserDashboard.js
- Timestamp:
- 10/27/22 17:35:03 (2 years ago)
- Branches:
- main
- Children:
- 3b6962d
- Parents:
- 8d83180
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
reactapp/src/Pages/UserDashboard.js
r8d83180 rc68150f 1 import React, { useEffect } from "react";1 import React, { useEffect, useState, useContext } from "react"; 2 2 import { 3 3 OpinionCard, 4 4 OpinionCardContent, 5 5 OpinionCardContentTime, 6 OpinionCardContentTitle,7 6 } from "../Components/Styled/OpinionCard.style"; 8 7 import { … … 11 10 } from "../Components/Styled/UserDetails.style"; 12 11 import { dateConverter } from "../Util/dateConverter"; 12 import axios from "../api/axios"; 13 import JSOG from "jsog"; 14 import AuthApi from "../api/AuthApi"; 13 15 14 function UserDashboard({ user, userLoaded }) { 16 function UserDashboard() { 17 const { auth, setAuth } = useContext(AuthApi); 18 19 const [user, setUser] = useState(null); 20 const [loadedUser, setLoadedUser] = useState(false); 21 const [fetchError, setFetchError] = useState(false); 22 15 23 useEffect(() => { 16 const timer = setTimeout(() => { 17 if (user === null) window.location.reload(false); 18 }, 3000); 19 return () => clearTimeout(timer); 24 const url = `http://192.168.0.17:8080/secure/currentUser`; 25 26 const fetchUser = async () => { 27 try { 28 const response = await axios.get(url, { withCredentials: true }); 29 var cyclicGraph = await response.data; 30 var jsogStructure = JSOG.encode(cyclicGraph); 31 cyclicGraph = JSOG.decode(jsogStructure); 32 setUser(cyclicGraph); 33 setLoadedUser(true); 34 } catch (error) { 35 setFetchError(true); 36 } 37 }; 38 39 if (auth) fetchUser(); 20 40 }, []); 21 41 22 return userLoaded ? ( 42 // useEffect(() => { 43 // const timer = setTimeout(() => { 44 // if (user === null) window.location.reload(false); <---- :-) 45 // }, 3000); 46 // return () => clearTimeout(timer); 47 // }, []); 48 49 function findParentThread(post) { 50 if (post.parent === null) return post; 51 return findParentThread(post.parent); 52 } 53 54 return loadedUser ? ( 23 55 <> 24 56 <h3>Кориснички податоци:</h3> … … 49 81 <OpinionCard> 50 82 <OpinionCardContent> 51 <p> 52 Во дискусија за{" "} 53 <a href={"/professor/" + post.targetProfessor.professorId}> 54 {post.targetProfessor.professorName} 55 </a> 83 <p style={{ fontStyle: "italic", marginBottom: "10px" }}> 84 во дискусија за{" "} 85 {post.targetProfessor !== undefined ? ( 86 <a href={"/professor/" + post.targetProfessor.professorId}> 87 {post.targetProfessor.professorName} 88 </a> 89 ) : ( 90 <a 91 href={ 92 post.parent === null 93 ? "/topic/" + post.postId 94 : "/topic/" + findParentThread(post).postId 95 } 96 > 97 {post.targetSubject.subjectName} 98 </a> 99 )} 56 100 </p> 57 <OpinionCardContentTitle>{post.title}</OpinionCardContentTitle> 58 <p>{post.content}</p> 101 <p style={{ marginBottom: "10px" }}>{post.content}</p> 59 102 <OpinionCardContentTime> 60 103 {dateConverter(
Note:
See TracChangeset
for help on using the changeset viewer.