Skip to content

Commit

Permalink
temp fix for rating history
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank-Gu-81 committed Jan 22, 2025
1 parent a6bc768 commit 3c8c8e8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function App() {
: <Navigate to="/" />}
/>
<Route path="/my-friends" element={isAuthenticated ? <MyFriends user={user} friends={friends} /> : <Navigate to="/" />} />
<Route path="/rating-history" element={isAuthenticated ? <RatingHistory userName={user} profilePic={profilePic} filteredPost={filteredPost}/> : <Navigate to="/" />} />
<Route path="/rating-history" element={isAuthenticated ? <RatingHistory userName={user} profilePic={profilePic}/> : <Navigate to="/" />} />
<Route path="/comment/:post_id" element={isAuthenticated ? <Comment userName={user} profilePic={profilePic} /> : <Navigate to="/" />} />
<Route path="*" element={<Navigate to="/" />} />
</Routes>
Expand Down
1 change: 1 addition & 0 deletions src/components/RatingHistory/RatingHistory.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
}

.rating-history-page {
padding-top: 3em;
padding-bottom: 3em;
margin-top: 2px;
margin-bottom: auto;
Expand Down
43 changes: 41 additions & 2 deletions src/components/RatingHistory/RatingHistory.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<AppBar />
Expand Down Expand Up @@ -38,7 +77,7 @@ function RatingHistory({ userName, profilePic, filteredPost }) {
<NavigationBar />
</Container>
</div>
)
);

}

Expand Down

0 comments on commit 3c8c8e8

Please sign in to comment.