Skip to content

Commit

Permalink
update comment feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank-Gu-81 committed Jan 18, 2025
1 parent b2a466f commit 7b0c582
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
68 changes: 66 additions & 2 deletions src/components/Comment/Comment.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<AppBar />
<Container maxWidth="sm">
<h1>Comments for {post_id}</h1>
<p>Comments for {post_id}</p>
{postInfo ? (
<Post post={postInfo} friends={[]} />
) : (
<p>Loading post information...</p>
)}
</Container>

{/* add a comment section */}
<Container maxWidth="sm">
<Box className="comment-box">
<Typography variant="h6">Add a Comment</Typography>
<Stack spacing={2}>
<TextField
label="Comment"
variant="outlined"
fullWidth
multiline
rows={4}
/>
<Button variant="contained" color="primary">
Submit
</Button>
</Stack>
</Box>
</Container>
<NavigationBar />
</div>
)
}
Expand Down
1 change: 1 addition & 0 deletions src/components/Post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 7b0c582

Please sign in to comment.