import React, {useEffect, useState} from 'react'; import JSOG from "jsog"; import {OpinionCard, OpinionCardContent, OpinionCardContentTime} from "../Components/Styled/OpinionCard.style"; import LoadingSpinner from "../Components/Styled/LoadingSpinner.style"; import {dateConverter} from "../Util/dateConverter"; import {findParentThread} from "../Util/findParentThread"; import {CurrentPageNav} from "../Components/Styled/Main.style"; const Home = () => { const [latestOpinions, setLatestOpinions] = useState(null); const [loadedLatestOpinions, setLoadedLatestOpinions] = useState(false); const [latestThreads, setLatestThreads] = useState(null); const [loadedLatestThreads, setLoadedLatestThreads] = useState(false); useEffect(() => { Promise.all([fetch(`http://192.168.1.108:8080/public/latest10opinions`), fetch(`http://192.168.1.108:8080/public/latest10threads`)]) .then(([resOpinions, resThreads]) => Promise.all([resOpinions.json(), resThreads.json()])) .then(([dataOpinions, dataThreads]) => { let cyclicGraph1 = dataOpinions; let jsogStructure1 = JSOG.encode(cyclicGraph1); cyclicGraph1 = JSOG.decode(jsogStructure1); setLatestOpinions(cyclicGraph1); setLoadedLatestOpinions(true); let cyclicGraph2 = dataThreads; let jsogStructure2 = JSOG.encode(cyclicGraph2); cyclicGraph2 = JSOG.decode(jsogStructure2); setLatestThreads(cyclicGraph2); setLoadedLatestThreads(true); }) }, []); return ( <> »{" "} Универзитет „Св. Кирил и Методиј“

Последни мислења за професори

{loadedLatestOpinions ? latestOpinions.slice(5).map(opinion => { opinion.timePosted = undefined; return

во дискусија за{" "} {opinion.targetProfessor.professorName}

{opinion.author.username} {" "} напишал

{opinion.content}

{new Date(opinion.timePosted).setMilliseconds(0) === new Date(opinion.timeLastEdited).setMilliseconds(0) ? ( {dateConverter( new Date(opinion.timePosted).toString().slice(4, -43) )} #{opinion.postId} ) : ( {dateConverter( new Date(opinion.timeLastEdited) .toString() .slice(4, -43) )}{" "} #{opinion.postId}{" "} (едитирано од модератор) )}
}) : }

Последни мислења за предмети

{loadedLatestThreads ? latestThreads.slice(5).map(thread => { return

во дискусија за{" "} {thread.targetSubject.subjectName}

{thread.author.username} {" "} напишал

{thread.content}

{new Date(thread.timePosted).setMilliseconds(0) === new Date(thread.timeLastEdited).setMilliseconds(0) ? ( {dateConverter( new Date(thread.timePosted).toString().slice(4, -43) )} #{thread.postId} ) : ( {dateConverter( new Date(thread.timeLastEdited) .toString() .slice(4, -43) )}{" "} #{thread.postId}{" "} (едитирано од модератор) )}
}) : null}
); }; export default Home;