import React, { useEffect, useState, useContext } from "react"; import { OpinionCard, OpinionCardContent, OpinionCardContentTime, } from "../Components/Styled/OpinionCard.style"; import { UserDetailsCard, UserDetailsCardContent, } from "../Components/Styled/UserDetails.style"; import { dateConverter } from "../Util/dateConverter"; import axios from "../api/axios"; import JSOG from "jsog"; import AuthApi from "../api/AuthApi"; function UserDashboard() { const { auth, setAuth } = useContext(AuthApi); const [user, setUser] = useState(null); const [loadedUser, setLoadedUser] = useState(false); const [fetchError, setFetchError] = useState(false); useEffect(() => { const url = `http://192.168.0.17:8080/secure/currentUser`; const fetchUser = async () => { try { const response = await axios.get(url, { withCredentials: true }); var cyclicGraph = await response.data; var jsogStructure = JSOG.encode(cyclicGraph); cyclicGraph = JSOG.decode(jsogStructure); setUser(cyclicGraph); setLoadedUser(true); } catch (error) { setFetchError(true); } }; if (auth) fetchUser(); }, []); // useEffect(() => { // const timer = setTimeout(() => { // if (user === null) window.location.reload(false); <---- :-) // }, 3000); // return () => clearTimeout(timer); // }, []); function findParentThread(post) { if (post.parent === null) return post; return findParentThread(post.parent); } return loadedUser ? ( <>

Кориснички податоци:

{user.fullName && ( Име: {user.fullName}{" "} )} Корисничко име: {user.username}{" "} E-mail: {user.email} Карма: {user.karma} {user.authoredPosts.length > 0 ? (

Ваши мислења:

) : (

Немате објавени мислења

)} {user.authoredPosts.map((post) => { return (

во дискусија за{" "} {post.targetProfessor !== undefined ? ( {post.targetProfessor.professorName} ) : ( {post.targetSubject.subjectName} )}

{post.content}

{dateConverter( new Date(post.timePosted).toString().slice(4, -43) )}
); })} ) : ( <>се вчитува... ); } export default UserDashboard;