Ignore:
Timestamp:
01/20/23 22:57:18 (18 months ago)
Author:
viktor <viktor@…>
Branches:
main
Children:
8dffe02
Parents:
4abf55a
Message:

prefinal

File:
1 edited

Legend:

Unmodified
Added
Removed
  • reactapp/src/Pages/Subject.js

    r4abf55a r9bf1f8d  
    3333  let params = useParams();
    3434  let navigate = useNavigate();
    35 
    3635  const { auth, setAuth } = useContext(AuthApi);
     36
    3737  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);
    3941  const [fetchError, setFetchError] = useState(false);
     42
    4043  var totalTopics = 0;
    4144  var topics = [];
     
    4750
    4851  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  }, []);
    6670
    6771  const handleAddTopicButtonClick = () => {
     
    8488    if (!topicTitle.length < 1 && !topicContent.length < 1) {
    8589      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`,
    8791        {
    8892          method: "post",
     
    109113  };
    110114
    111   return loaded ? (
     115  return loadedSubject ? (
    112116    <>
    113117      <CurrentPageNav>
     
    151155          }}
    152156        >
    153           {subject.threads.map((thread) => {
     157          {threads.map((thread) => {
    154158            if (thread.parent === null) {
    155159              totalTopics++;
     
    210214            <EntityUl key={topic.postId}>
    211215              <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>
    213217                <EntityParam right="30px">
    214218                  <span style={{ fontWeight: "normal" }}>
Note: See TracChangeset for help on using the changeset viewer.