Skip to content

Commit

Permalink
comment page template added
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank-Gu-81 committed Jan 18, 2025
1 parent 7523730 commit b2a466f
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 46 deletions.
2 changes: 2 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,6 +38,7 @@ const App = () => {
<Route path="/search" element={user ? <SearchPage /> : <Navigate to="/" />} />
<Route path="/account" element={user ? <Account userName={user} userEmail={userEmail} profilePic={profilePic} /> : <Navigate to="/" />} />
<Route path="/rating-history" element={user ? <RatingHistory userName={user} profilePic={profilePic} /> : <Navigate to="/" />} />
<Route path="/comment/:post_id" element={user ? <Comment userName={user} /> : <Navigate to="/" />} />
</Routes>
</Router>
</Container>
Expand Down
22 changes: 22 additions & 0 deletions src/components/Comment/Comment.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<AppBar />
<Container maxWidth="sm">
<h1>Comments for {post_id}</h1>
</Container>
</div>
)
}

export default Comment
98 changes: 52 additions & 46 deletions src/components/Post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -36,6 +38,7 @@ function getQuarterChipClass(quarter) {
}

function Post({ post, friends }) {
const navigate = useNavigate();
const renderUserStars = (rating) => {
const filledStars = Math.floor(rating);
const starsArray = [];
Expand All @@ -49,62 +52,65 @@ function Post({ post, friends }) {
};

return (
<Card className="post-card">
<CardContent>
<div className="chip-box">
<Chip label={post.course_name} className={getCourseChipClass(post.course_name)} />
<Chip label={post.quarter} className={getQuarterChipClass(post.quarter)} />
<Chip label={post.professor} className="chip-third" />
</div>
// Q: how to make the card clickable and navigate to comment page?
<Card className="post-card" onClick={() => navigate(`/comment/${post.id}`)}>
<CardActionArea>
<CardContent>
<div className="chip-box">
<Chip label={post.course_name} className={getCourseChipClass(post.course_name)} />
<Chip label={post.quarter} className={getQuarterChipClass(post.quarter)} />
<Chip label={post.professor} className="chip-third" />
</div>

<div className="user-rating-section">
<Typography variant="body2" className="user-rating-label">
<strong>{post.username}</strong> rated this course
</Typography>
<div className="user-star-icons">
{renderUserStars(post.rating ?? 0)}
<div className="user-rating-section">
<Typography variant="body2" className="user-rating-label">
<strong>{post.username}</strong> rated this course
</Typography>
<div className="user-star-icons">
{renderUserStars(post.rating ?? 0)}
</div>
</div>
</div>

<Typography variant="h5" component="div" className="post-title">
{post.title}
</Typography>
<Typography variant="body2" className="post-subheader">
Posted by <strong>{post.username}</strong> on {post.date.toDate().toDateString()}
</Typography>
<Typography variant="body1" className="post-body">
{post.body}
</Typography>
<Typography variant="h5" component="div" className="post-title">
{post.title}
</Typography>
<Typography variant="body2" className="post-subheader">
Posted by <strong>{post.username}</strong> on {post.date.toDate().toDateString()}
</Typography>
<Typography variant="body1" className="post-body">
{post.body}
</Typography>

<hr className="divider" />
<hr className="divider" />

<div className="bottom-row">
<div className="friends-section">
<Typography variant="body2" className="friends-text">
Friends who enrolled
</Typography>
<div className="friends-avatar">
{Object.values(friends).map((friend) => (
<Avatar key={friend} aria-label="recipe">
{friend[0]}
</Avatar>
))}
<div className="bottom-row">
<div className="friends-section">
<Typography variant="body2" className="friends-text">
Friends who enrolled
</Typography>
<div className="friends-avatar">
{Object.values(friends).map((friend) => (
<Avatar key={friend} aria-label="recipe">
{friend[0]}
</Avatar>
))}
</div>
</div>
</div>

<div className="public-rating-container">
<Typography variant="body2" className="public-rating-label">
{(post.publicRatingCount ?? 1100).toLocaleString()} ratings
</Typography>
<div className="big-star-wrapper">
<StarIcon className="big-star-icon" />
<div className="big-star-text">
{post.publicRating ?? 3.5}
<div className="public-rating-container">
<Typography variant="body2" className="public-rating-label">
{(post.publicRatingCount ?? 1100).toLocaleString()} ratings
</Typography>
<div className="big-star-wrapper">
<StarIcon className="big-star-icon" />
<div className="big-star-text">
{post.publicRating ?? 3.5}
</div>
</div>
</div>
</div>
</div>
</CardContent>
</CardContent>
</CardActionArea>
</Card>
);
}
Expand Down

0 comments on commit b2a466f

Please sign in to comment.