Changeset 9bf1f8d for reactapp/src/Pages/Subject.js
- Timestamp:
- 01/20/23 22:57:18 (18 months ago)
- Branches:
- main
- Children:
- 8dffe02
- Parents:
- 4abf55a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
reactapp/src/Pages/Subject.js
r4abf55a r9bf1f8d 33 33 let params = useParams(); 34 34 let navigate = useNavigate(); 35 36 35 const { auth, setAuth } = useContext(AuthApi); 36 37 37 const [subject, setSubject] = useState(null); 38 const [loaded, setLoaded] = useState(false); 38 const [loadedSubject, setLoadedSubject] = useState(false); 39 const [threads, setThreads] = useState(null); 40 const [loadedThreads, setLoadedThreads] = useState(false); 39 41 const [fetchError, setFetchError] = useState(false); 42 40 43 var totalTopics = 0; 41 44 var topics = []; … … 47 50 48 51 useEffect(() => { 49 const url = `http://192.168.0.29:8080/public/subject/${params.subjectId}`; 50 51 const fetchData = async () => { 52 try { 53 const response = await fetch(url); 54 let cyclicGraph = await response.json(); 55 let jsogStructure = JSOG.encode(cyclicGraph); 56 cyclicGraph = JSOG.decode(jsogStructure); 57 setSubject(cyclicGraph); 58 setLoaded(true); 59 } catch (error) { 60 setFetchError(true); 61 } 62 }; 63 64 fetchData(); 65 }, [params.subjectId]); 52 Promise.all([fetch(`http://192.168.1.254:8080/public/subject/${params.subjectId}`), 53 fetch(`http://192.168.1.254:8080/public/subject/${params.subjectId}/threads`)]) 54 .then(([resSubject, resThreads]) => Promise.all([resSubject.json(), resThreads.json()])) 55 .then(([dataSubject, dataThreads]) => { 56 let cyclicGraph1 = dataSubject; 57 let jsogStructure1 = JSOG.encode(cyclicGraph1); 58 cyclicGraph1 = JSOG.decode(jsogStructure1); 59 setSubject(cyclicGraph1); 60 setLoadedSubject(true); 61 62 let cyclicGraph2 = dataThreads; 63 let jsogStructure2 = JSOG.encode(cyclicGraph2); 64 cyclicGraph2 = JSOG.decode(jsogStructure2); 65 setThreads(cyclicGraph2); 66 setLoadedThreads(true); 67 }) 68 69 }, []); 66 70 67 71 const handleAddTopicButtonClick = () => { … … 84 88 if (!topicTitle.length < 1 && !topicContent.length < 1) { 85 89 const response = await axios( 86 `http://192.168. 0.29:8080/secure/subject/${params.subjectId}/addThread`,90 `http://192.168.1.254:8080/secure/subject/${params.subjectId}/addThread`, 87 91 { 88 92 method: "post", … … 109 113 }; 110 114 111 return loaded ? (115 return loadedSubject ? ( 112 116 <> 113 117 <CurrentPageNav> … … 151 155 }} 152 156 > 153 { subject.threads.map((thread) => {157 {threads.map((thread) => { 154 158 if (thread.parent === null) { 155 159 totalTopics++; … … 210 214 <EntityUl key={topic.postId}> 211 215 <EntityLi bgcolor="cornsilk"> 212 <a href={"/topic/" + topic.postId}>{topic.title }</a>216 <a href={"/topic/" + topic.postId}>{topic.title.length >= 99 ? topic.title.slice(0,98) + "..." : topic.title}</a> 213 217 <EntityParam right="30px"> 214 218 <span style={{ fontWeight: "normal" }}>
Note:
See TracChangeset
for help on using the changeset viewer.