From b2a466f06402331e62c3ba74928b974504bbb62a Mon Sep 17 00:00:00 2001 From: Frank-Gu-81 Date: Fri, 17 Jan 2025 21:43:28 -0600 Subject: [PATCH] comment page template added --- src/App.jsx | 2 + src/components/Comment/Comment.jsx | 22 +++++++ src/components/Post/Post.jsx | 98 ++++++++++++++++-------------- 3 files changed, 76 insertions(+), 46 deletions(-) create mode 100644 src/components/Comment/Comment.jsx diff --git a/src/App.jsx b/src/App.jsx index 73e0eda..caf304f 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -13,6 +13,7 @@ import Account from './components/Account/Account'; import { Container } from '@mui/material'; import SearchPage from './components/SearchPage/SearchPage'; import RatingHistory from './components/RatingHistory/RatingHistory'; +import Comment from './components/Comment/Comment'; const App = () => { // react hook to keep track of the user's authentication status @@ -37,6 +38,7 @@ const App = () => { : } /> : } /> : } /> + : } /> diff --git a/src/components/Comment/Comment.jsx b/src/components/Comment/Comment.jsx new file mode 100644 index 0000000..5a60210 --- /dev/null +++ b/src/components/Comment/Comment.jsx @@ -0,0 +1,22 @@ +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 AppBar from '../AppBar/AppBar'; +import NavigationBar from '../NavigationBar/NavigationBar'; +import Post from '../Post/Post'; +import { useParams } from 'react-router-dom'; + +function Comment({ userName }) { + const post_id = useParams().post_id; + return ( +
+ + +

Comments for {post_id}

+
+
+ ) +} + +export default Comment \ No newline at end of file diff --git a/src/components/Post/Post.jsx b/src/components/Post/Post.jsx index 5ca72f7..cb3f85f 100644 --- a/src/components/Post/Post.jsx +++ b/src/components/Post/Post.jsx @@ -9,6 +9,8 @@ import { import StarIcon from '@mui/icons-material/Star'; import StarBorderIcon from '@mui/icons-material/StarBorder'; import "./Post.css"; +import CardActionArea from '@mui/material/CardActionArea'; +import { useNavigate } from "react-router-dom"; const courseClassMap = { CS: "chip-course-cs", @@ -36,6 +38,7 @@ function getQuarterChipClass(quarter) { } function Post({ post, friends }) { + const navigate = useNavigate(); const renderUserStars = (rating) => { const filledStars = Math.floor(rating); const starsArray = []; @@ -49,62 +52,65 @@ function Post({ post, friends }) { }; return ( - - -
- - - -
+ // Q: how to make the card clickable and navigate to comment page? + navigate(`/comment/${post.id}`)}> + + +
+ + + +
-
- - {post.username} rated this course - -
- {renderUserStars(post.rating ?? 0)} +
+ + {post.username} rated this course + +
+ {renderUserStars(post.rating ?? 0)} +
-
- - {post.title} - - - Posted by {post.username} on {post.date.toDate().toDateString()} - - - {post.body} - + + {post.title} + + + Posted by {post.username} on {post.date.toDate().toDateString()} + + + {post.body} + -
+
-
-
- - Friends who enrolled - -
- {Object.values(friends).map((friend) => ( - - {friend[0]} - - ))} +
+
+ + Friends who enrolled + +
+ {Object.values(friends).map((friend) => ( + + {friend[0]} + + ))} +
-
-
- - {(post.publicRatingCount ?? 1100).toLocaleString()} ratings - -
- -
- {post.publicRating ?? 3.5} +
+ + {(post.publicRatingCount ?? 1100).toLocaleString()} ratings + +
+ +
+ {post.publicRating ?? 3.5} +
-
- + + ); }