Skip to content

Commit

Permalink
Merge pull request #12 from 392-f24/fix-category-select
Browse files Browse the repository at this point in the history
fix category select
  • Loading branch information
markantfort23 authored Nov 8, 2024
2 parents 4826943 + 41fe4ab commit e1ab1dd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/pages/CafePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const CafePage = () => {
const [cafe, setCafe] = useState(null);
const [replyMessages, setReplyMessages] = useState({});
const [newReview, setNewReview] = useState('');
const [selectedCategory, setSelectedCategory] = useState('Ambience');
const [selectedCategory, setSelectedCategory] = useState(''); // Default to empty string

useEffect(() => {
if (user && user.email) {
Expand Down Expand Up @@ -51,7 +51,7 @@ const CafePage = () => {
const [posts, postError] = findCafePosts(cafe?.placeId);

const handleReviewSubmit = async () => {
if (newReview.trim() && user) {
if (newReview.trim() && selectedCategory && user) {
const review = {
content: newReview,
category: selectedCategory,
Expand All @@ -65,8 +65,10 @@ const CafePage = () => {
console.error('Error adding review:', error);
} else {
setNewReview('');
setSelectedCategory('Ambience');
setSelectedCategory(''); // Reset to default placeholder
}
} else {
alert("Please write a review and select a category.");
}
};

Expand Down Expand Up @@ -126,11 +128,14 @@ const CafePage = () => {
onChange={(e) => setSelectedCategory(e.target.value)}
className="category-dropdown"
>
<option value="" disabled>Select a category</option>
<option value="Ambience">Ambience</option>
<option value="Seating Availability">Seating Availability</option>
<option value="Outlet Availability">Outlet Availability</option>
<option value="Noise Level">Noise Level</option>
<option value="Food and Drink">Food and Drink</option>
<option value="Question">Question</option>
<option value="Suggestion">Suggestion</option>
</select>
<button onClick={handleReviewSubmit} className="submit-review-btn">Submit Review</button>
</div>
Expand Down Expand Up @@ -170,6 +175,7 @@ const CafePage = () => {
value={replyMessages[postKey] || ''}
onChange={(e) => handleReplyChange(e, postKey)}
placeholder="Write your reply..."
className="reply-textarea"
/>
<button
onClick={() => handleAddReply(postKey)}
Expand Down

0 comments on commit e1ab1dd

Please sign in to comment.