Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix category select #12

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading