Skip to content

Commit

Permalink
show all names on friends tab
Browse files Browse the repository at this point in the history
  • Loading branch information
annacai44 committed Jan 21, 2025
1 parent 4a38e30 commit 601ac88
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/components/Feed/Feed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function Feed({friends}) {
const [posts, setPosts] = useState([]);
const [search, setSearch] = useState();
const [filteredPosts, setFilteredPosts] = useState([]);
const [tabValue, setTabValue] = React.useState(0);

// useEffect runs every time the component is rendered
useEffect(() => {
Expand All @@ -54,11 +55,9 @@ function Feed({friends}) {
setFilteredPosts(posts) // retrieve all if the search bar isn't being used
}
}, [search, posts]); // must define the states that cause re-rendering

const [value, setValue] = React.useState(0);

const handleChange = (event, newValue) => {
setValue(newValue);
setTabValue(newValue);

if (newValue === 0) {
// public
Expand All @@ -72,7 +71,7 @@ function Feed({friends}) {
return (
<div>
<AppBar />
<Tabs className="friends-public-switch" value={value} onChange={handleChange} centered>
<Tabs className="friends-public-switch" value={tabValue} onChange={handleChange} centered>
<Tab label="Public" icon={<PublicIcon />} />
<Tab label="Friends" icon={<PeopleIcon />} />
</Tabs>
Expand All @@ -86,7 +85,7 @@ function Feed({friends}) {
.slice()
.sort((a, b) => b.date.seconds - a.date.seconds).map((post) =>
<div key={post.id}>
<Post post={post} friends={fake_friends} />
<Post post={post} friends={fake_friends} postAnonymously={tabValue == 1 ? false : post.anonymous ? true : false}/>
</div>)
)
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/Post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function getQuarterChipClass(quarter) {
return "";
}

function Post({ post, friends }) {
function Post({ post, friends, postAnonymously }) {
const navigate = useNavigate();
const renderUserStars = (rating) => {
const filledStars = Math.floor(rating);
Expand All @@ -64,7 +64,7 @@ function Post({ post, friends }) {

<div className="user-rating-section">
<Typography variant="body2" className="user-rating-label">
<strong>{post.anonymous ? "Anonymous" : post.username}</strong> rated this course
<strong>{postAnonymously ? "Anonymous" : post.username}</strong> rated this course
</Typography>
<div className="user-star-icons">
{renderUserStars(post.rating ?? 0)}
Expand All @@ -75,7 +75,7 @@ function Post({ post, friends }) {
{post.title}
</Typography>
<Typography variant="body2" className="post-subheader">
Posted by <strong>{post.anonymous ? "Anonymous" : post.username}</strong> on {post.date.toDate().toDateString()}
Posted by <strong>{postAnonymously ? "Anonymous" : post.username}</strong> on {post.date.toDate().toDateString()}
</Typography>
<Typography variant="body1" className="post-body">
{post.body}
Expand Down
2 changes: 1 addition & 1 deletion src/components/RatingHistory/RatingHistory.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function RatingHistory({ userName, profilePic, filteredPost }) {
.slice()
.sort((a, b) => b.date.seconds - a.date.seconds).map((post) =>
<div key={post.id}>
<Post post={post} friends={fake_friends} />
<Post post={post} friends={fake_friends} postAnonymously={false}/>
</div>)
)
}
Expand Down

0 comments on commit 601ac88

Please sign in to comment.