From 3c8c8e85b61cd12248e6e8f29675fc915600d010 Mon Sep 17 00:00:00 2001 From: Frank-Gu-81 Date: Tue, 21 Jan 2025 22:22:58 -0600 Subject: [PATCH] temp fix for rating history --- src/App.jsx | 2 +- .../RatingHistory/RatingHistory.css | 1 + .../RatingHistory/RatingHistory.jsx | 43 ++++++++++++++++++- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 954aeb8..1ae24fe 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -113,7 +113,7 @@ function App() { : } /> : } /> - : } /> + : } /> : } /> } /> diff --git a/src/components/RatingHistory/RatingHistory.css b/src/components/RatingHistory/RatingHistory.css index 2b37fbd..1bb1012 100644 --- a/src/components/RatingHistory/RatingHistory.css +++ b/src/components/RatingHistory/RatingHistory.css @@ -5,6 +5,7 @@ } .rating-history-page { + padding-top: 3em; padding-bottom: 3em; margin-top: 2px; margin-bottom: auto; diff --git a/src/components/RatingHistory/RatingHistory.jsx b/src/components/RatingHistory/RatingHistory.jsx index c86a0f5..6add36f 100644 --- a/src/components/RatingHistory/RatingHistory.jsx +++ b/src/components/RatingHistory/RatingHistory.jsx @@ -1,16 +1,55 @@ import Post from '../Post/Post'; +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 './RatingHistory.css'; import Avatar from '@mui/material/Avatar'; +import { useState, useEffect } from 'react'; -function RatingHistory({ userName, profilePic, filteredPost }) { +function RatingHistory({ userName, profilePic }) { + const [filteredPost, setFilteredPost] = useState([]); const fake_friends = ["Alice", "Bob", "Charlie", "David"]; // Add userName as a dependency to prevent it from running infinitely + async function getPostsFromDB() { + try { + const querySnapshot = await getDocs(collection(db, "posts")); + const posts = []; + querySnapshot.forEach((doc) => { + if (doc.data().username === userName?.displayName){ + posts.push({ id: doc.id, ...doc.data() }); + } + }); + return posts; + } catch (error) { + console.log("Error: ", error); + } + + } + + useEffect(() => { + async function fetchPosts() { + try { + const fetchedPosts = await getPostsFromDB(); + setFilteredPost(fetchedPosts); + // console.log("Filtered posts: ", fetchedPosts); + } catch (error) { + console.error("Error fetching posts: ", error); + } + } + fetchPosts(); + }, [userName]); // Add userName as a dependency to prevent it from running infinitely + + // print out the posts + useEffect(() => { + console.log(filteredPost); + } + , [filteredPost]); + return (
@@ -38,7 +77,7 @@ function RatingHistory({ userName, profilePic, filteredPost }) {
- ) + ); }