From 7b0c58251d18096fa7d31d3ac13267abcd347956 Mon Sep 17 00:00:00 2001 From: Frank-Gu-81 Date: Sat, 18 Jan 2025 01:12:34 -0600 Subject: [PATCH] update comment feature --- src/components/Comment/Comment.jsx | 68 +++++++++++++++++++++++++++++- src/components/Post/Post.jsx | 1 + 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/src/components/Comment/Comment.jsx b/src/components/Comment/Comment.jsx index 5a60210..84f7184 100644 --- a/src/components/Comment/Comment.jsx +++ b/src/components/Comment/Comment.jsx @@ -1,20 +1,84 @@ import { useState, useEffect } from 'react'; import { collection, getDocs } from "firebase/firestore"; import { db } from "../../utilities/firebase"; -import { Container, Box, Stack, Typography } from '@mui/material'; +import { Container, Box, Stack, Typography, Button, Textfield } from '@mui/material'; import AppBar from '../AppBar/AppBar'; import NavigationBar from '../NavigationBar/NavigationBar'; +// import TextFields from '@mui/icons-material/TextFields'; import Post from '../Post/Post'; import { useParams } from 'react-router-dom'; function Comment({ userName }) { const post_id = useParams().post_id; + const [postInfo, setPostInfo] = useState(null); + + async function getPostInfoFromDB(post_id) { + try { + const doc = await getDocs(collection(db, "posts")); + const posts = []; + doc.forEach((doc) => { + if (doc.id === post_id) { + posts.push({ id: doc.id, ...doc.data() }); + } + }); + console.log("HEREREREERE?"); + return posts[0]; + } catch (error) { + console.log("Error: ", error); + } + } + + useEffect(() => { + async function fetchPosts() { + try { + const fetchedPosts = await getPostInfoFromDB(post_id); + setPostInfo(fetchedPosts); + } + catch (error) { + console.error("Error fetching posts: ", error); + } + } + fetchPosts(); + }, [post_id]); + + useEffect(() => { + if (postInfo) { + console.log("Updated postInfo: ", postInfo); + console.log("Course name: ", postInfo.course_name); + } + }, [postInfo]); // Log whenever postInfo updates + return (
-

Comments for {post_id}

+

Comments for {post_id}

+ {postInfo ? ( + + ) : ( +

Loading post information...

+ )} +
+ + {/* add a comment section */} + + + Add a Comment + + + + + +
) } diff --git a/src/components/Post/Post.jsx b/src/components/Post/Post.jsx index cb3f85f..341ad06 100644 --- a/src/components/Post/Post.jsx +++ b/src/components/Post/Post.jsx @@ -19,6 +19,7 @@ const courseClassMap = { }; function getCourseChipClass(courseName) { + console.log("courseName: ", courseName); const upper = courseName.toUpperCase(); for (const prefix in courseClassMap) { if (upper.startsWith(prefix)) {