source: reactapp/src/Pages/Home.js@ 8dffe02

main
Last change on this file since 8dffe02 was 8dffe02, checked in by unknown <mlviktor23@…>, 2 years ago

prefinal reproducible

  • Property mode set to 100644
File size: 6.8 KB
Line 
1import React, {useEffect, useState} from 'react';
2import JSOG from "jsog";
3import {OpinionCard, OpinionCardContent, OpinionCardContentTime} from "../Components/Styled/OpinionCard.style";
4import LoadingSpinner from "../Components/Styled/LoadingSpinner.style";
5import {dateConverter} from "../Util/dateConverter";
6import {findParentThread} from "../Util/findParentThread";
7import {CurrentPageNav} from "../Components/Styled/Main.style";
8
9const Home = () => {
10 const [latestOpinions, setLatestOpinions] = useState(null);
11 const [loadedLatestOpinions, setLoadedLatestOpinions] = useState(false);
12 const [latestThreads, setLatestThreads] = useState(null);
13 const [loadedLatestThreads, setLoadedLatestThreads] = useState(false);
14
15 useEffect(() => {
16 Promise.all([fetch(`http://192.168.1.108:8080/public/latest10opinions`),
17 fetch(`http://192.168.1.108:8080/public/latest10threads`)])
18 .then(([resOpinions, resThreads]) => Promise.all([resOpinions.json(), resThreads.json()]))
19 .then(([dataOpinions, dataThreads]) => {
20 let cyclicGraph1 = dataOpinions;
21 let jsogStructure1 = JSOG.encode(cyclicGraph1);
22 cyclicGraph1 = JSOG.decode(jsogStructure1);
23 setLatestOpinions(cyclicGraph1);
24 setLoadedLatestOpinions(true);
25
26 let cyclicGraph2 = dataThreads;
27 let jsogStructure2 = JSOG.encode(cyclicGraph2);
28 cyclicGraph2 = JSOG.decode(jsogStructure2);
29 setLatestThreads(cyclicGraph2);
30 setLoadedLatestThreads(true);
31 })
32
33 }, []);
34
35 return (
36 <>
37 <CurrentPageNav>
38 &#187;{" "}
39 <a href={"/university/1"}>
40 Универзитет „Св. Кирил и Методиј“
41 </a>
42 </CurrentPageNav>
43 <div style={{display:"grid", gridTemplateColumns:"1fr 1fr", gap:"40px", marginTop:"60px"}}>
44
45 <div id="latestOpinions" style={{gridColumn:"1", paddingLeft:"20px"}}>
46 <h2 style={{fontWeight:"normal", marginBottom:"30px"}}>Последни мислења за <span style={{fontWeight:"bold"}}>професори</span></h2>
47 {loadedLatestOpinions ? latestOpinions.slice(5).map(opinion => {
48 opinion.timePosted = undefined;
49 return <OpinionCard key={opinion.postId}>
50 <OpinionCardContent>
51 <p style={{marginBottom:"10px"}}>
52 во дискусија за{" "}
53 <a href={"/professor/" + opinion.targetProfessor.professorId}>
54 {opinion.targetProfessor.professorName}
55 </a>
56 </p>
57 <p style={{ fontStyle: "italic", marginBottom: "10px" }}>
58 <a href={"/user/" + opinion.author.id}>
59 {opinion.author.username}
60 </a>{" "}
61 напишал
62 </p>
63 <p style={{ marginBottom: "10px", maxWidth: "90%" }}>
64 {opinion.content}
65 </p>
66 {new Date(opinion.timePosted).setMilliseconds(0) === new Date(opinion.timeLastEdited).setMilliseconds(0) ? (
67 <OpinionCardContentTime>
68 {dateConverter(
69 new Date(opinion.timePosted).toString().slice(4, -43)
70 )} <span style={{fontStyle:"normal",color:"blue"}}>#{opinion.postId}</span>
71 </OpinionCardContentTime>
72 ) : (
73 <OpinionCardContentTime>
74 {dateConverter(
75 new Date(opinion.timeLastEdited)
76 .toString()
77 .slice(4, -43)
78 )}{" "} <span style={{fontStyle:"normal",color:"blue"}}>#{opinion.postId}</span>{" "}
79 (едитирано од модератор)
80 </OpinionCardContentTime>
81 )}
82 </OpinionCardContent>
83 </OpinionCard>
84 }) : <LoadingSpinner/>}
85 </div>
86
87 <div id="latestThreads" style={{gridColumn:"2", paddingRight:"20px"}}>
88 <h2 style={{fontWeight:"normal", marginBottom:"30px"}}>Последни мислења за <span style={{fontWeight:"bold"}}>предмети</span></h2>
89 {loadedLatestThreads ? latestThreads.slice(5).map(thread => {
90 return <OpinionCard key={thread.postId}>
91 <OpinionCardContent>
92 <p style={{marginBottom:"10px"}}>
93 во дискусија за{" "}
94 <a href={
95 thread.parent === null
96 ? "/topic/" + thread.postId
97 : "/topic/" + findParentThread(thread).postId
98 }
99 > {thread.targetSubject.subjectName}
100 </a>
101 </p>
102 <p style={{ fontStyle: "italic", marginBottom: "10px" }}>
103 <a href={"/user/" + thread.author.id}>
104 {thread.author.username}
105 </a>{" "}
106 напишал
107 </p>
108 <p style={{ marginBottom: "10px", maxWidth: "90%" }}>
109 {thread.content}
110 </p>
111 {new Date(thread.timePosted).setMilliseconds(0) === new Date(thread.timeLastEdited).setMilliseconds(0) ? (
112 <OpinionCardContentTime>
113 {dateConverter(
114 new Date(thread.timePosted).toString().slice(4, -43)
115 )} <span style={{fontStyle:"normal",color:"blue"}}>#{thread.postId}</span>
116 </OpinionCardContentTime>
117 ) : (
118 <OpinionCardContentTime>
119 {dateConverter(
120 new Date(thread.timeLastEdited)
121 .toString()
122 .slice(4, -43)
123 )}{" "} <span style={{fontStyle:"normal",color:"blue"}}>#{thread.postId}</span>{" "}
124 (едитирано од модератор)
125 </OpinionCardContentTime>
126 )}
127 </OpinionCardContent>
128 </OpinionCard>
129 }) : null}
130 </div>
131 </div>
132 </>
133 );
134};
135
136export default Home;
Note: See TracBrowser for help on using the repository browser.