From 156914ab1c07da1d628c9f1b1249833ff3cb934b Mon Sep 17 00:00:00 2001 From: Anna Cai Date: Tue, 21 Jan 2025 13:13:02 -0600 Subject: [PATCH] allow anonymous posts --- src/components/Post/Post.jsx | 4 +-- src/components/Submission/Submission.css | 11 +++++++- src/components/Submission/Submission.jsx | 33 +++++++++++++++++++----- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/components/Post/Post.jsx b/src/components/Post/Post.jsx index cb3f85f..333233c 100644 --- a/src/components/Post/Post.jsx +++ b/src/components/Post/Post.jsx @@ -64,7 +64,7 @@ function Post({ post, friends }) {
- {post.username} rated this course + {post.anonymous ? "Anonymous" : post.username} rated this course
{renderUserStars(post.rating ?? 0)} @@ -75,7 +75,7 @@ function Post({ post, friends }) { {post.title} - Posted by {post.username} on {post.date.toDate().toDateString()} + Posted by {post.anonymous ? "Anonymous" : post.username} on {post.date.toDate().toDateString()} {post.body} diff --git a/src/components/Submission/Submission.css b/src/components/Submission/Submission.css index 1c4ccab..5e6c59d 100644 --- a/src/components/Submission/Submission.css +++ b/src/components/Submission/Submission.css @@ -1,7 +1,7 @@ .submission-content { height: calc(100vh - 56px - 64px); margin-top: 6rem; - margin-bottom: 6rem; + margin-bottom: 10rem; } #rating { @@ -12,4 +12,13 @@ display: flex; flex-direction: column; align-items: center; +} + +.anonymous-button { + background-color: purple; +} + +.anonymous-buttons { + display: flex !important; + justify-content: center; } \ No newline at end of file diff --git a/src/components/Submission/Submission.jsx b/src/components/Submission/Submission.jsx index e83cedd..22543d6 100644 --- a/src/components/Submission/Submission.jsx +++ b/src/components/Submission/Submission.jsx @@ -1,13 +1,9 @@ import React from 'react'; -import { Stack, Button, Alert, Container, TextField, Rating, Typography } from '@mui/material'; +import { Stack, Button, Alert, Container, TextField, Rating, Typography, Tab, Tabs, InputLabel, MenuItem, FormControl, Select } from '@mui/material'; import NavigationBar from '../NavigationBar/NavigationBar'; import AppBar from '../AppBar/AppBar'; import "./Submission.css"; import { useNavigate } from "react-router-dom"; -import InputLabel from '@mui/material/InputLabel'; -import MenuItem from '@mui/material/MenuItem'; -import FormControl from '@mui/material/FormControl'; -import Select from '@mui/material/Select'; // Firebase // Source: How to add/set documents. https://firebase.google.com/docs/firestore/manage-data/add-data @@ -27,6 +23,8 @@ function Submission({ userName }) { const [rating, setRating] = React.useState(0); const [professor, setProfessor] = React.useState(""); const [fillInFields, setFillInFields] = React.useState(false); + const [selectedButton, setSelectedButton] = React.useState(""); // Default to "Show Name" + async function handleSubmit() { try { @@ -39,10 +37,11 @@ function Submission({ userName }) { rating: rating, professor: professor, username: userName.displayName, - date: new Date() + date: new Date(), + anonymous: selectedButton === 'anonymous' ? true : false }; - if (!title || !course || !body || !professor || !rating) { + if (!title || !course || !body || !professor || !rating || !selectedButton ) { setFillInFields(true); } else { await addDoc(collectionRef, post); @@ -55,6 +54,12 @@ function Submission({ userName }) { } } + const handleButtonClick = (buttonType) => { + setSelectedButton(buttonType); + // Save the data or handle side effects here + console.log(`Selected: ${buttonType}`); + }; + return (
@@ -106,6 +111,20 @@ function Submission({ userName }) { Course Rating setRating(newValue)} />
+
+ + +
{(fillInFields) ? Fill in all the fields before submitting. : null}