From 4bc28b4bd95bc37d904690c827c58d8eb2c358ca Mon Sep 17 00:00:00 2001 From: Ayushmaanagarwal1121 Date: Sun, 30 Jun 2024 12:32:23 +0530 Subject: [PATCH 1/2] Added BEM Naming convention --- src/App.css | 18 +++++++++--------- src/components/Feedback.jsx | 8 ++++---- src/index.css | 2 +- src/pages/MenuPage.jsx | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/App.css b/src/App.css index 95be599..9da17f6 100644 --- a/src/App.css +++ b/src/App.css @@ -40,18 +40,18 @@ li:hover span { } } -.nav-item{ +.Nav__item{ font-size: 52px !important; <<<<<<< Updated upstream ======= } -.star-rating { +.StarRating { display: flex; flex-direction: row; } -.star { +.StarRating__star { font-size: 2rem; color: #d3d3d3; background: none; @@ -60,30 +60,30 @@ li:hover span { transition: color 0.2s; } -.star.on { +.StarRating__star--on { color: #ffc107; } -.star.off { +.StarRating__star--off { color: #d3d3d3; } -.reviews-container{ +.Reviews__container{ display: flex; flex-direction: row; justify-content: space-around; } -.review-card{ +.Reviews__card { width: calc(90vw/3); border: 1px solid green; background-color: white; background-color: aquamarine; } -.stdfeedback{ +.Feedback__standard{ background-color: white; padding: 2% 3%; } -.stdname{ +.Feedback__name{ margin: 2% 3%; } diff --git a/src/components/Feedback.jsx b/src/components/Feedback.jsx index 0d3121c..6a6571b 100644 --- a/src/components/Feedback.jsx +++ b/src/components/Feedback.jsx @@ -30,11 +30,11 @@ const Reviews = () => { }; return ( -
+
{reviews.map(review => ( -
-

{review.studentName}

-
+
+

{review.studentName}

+

Rating: {renderStars(review.rating)}

{review.comment}

Canteen: {review.canteenName}

diff --git a/src/index.css b/src/index.css index 587bb9d..bcf3e36 100644 --- a/src/index.css +++ b/src/index.css @@ -23,7 +23,7 @@ code { display: none; } -.nav-item{ +.Nav__item{ font-size: 12px !important; font-weight: bolder !important; } diff --git a/src/pages/MenuPage.jsx b/src/pages/MenuPage.jsx index 57fc33b..9042538 100644 --- a/src/pages/MenuPage.jsx +++ b/src/pages/MenuPage.jsx @@ -11,12 +11,12 @@ const StarRating = ({ rating, onRatingChange }) => { const [hoverRating, setHoverRating] = useState(0); return ( -
+
{[1, 2, 3, 4, 5].map((star) => (
-
- -
- - - -
- +
+ +
+ + +
@@ -140,39 +141,6 @@ const Navbar = () => { - - {isOpen && ( - -
- Home - About us - News - Contact - RateUs - {/* Conditionally render "My Canteen" button */} - {canteenId && ( - My Canteen - )} - - - -
-
- )} -
- - - ); }; diff --git a/src/pages/MenuPage.jsx b/src/pages/MenuPage.jsx index 57fc33b..352f09b 100644 --- a/src/pages/MenuPage.jsx +++ b/src/pages/MenuPage.jsx @@ -5,37 +5,16 @@ import { toast } from "react-hot-toast"; import Navbar from "../components/Navbar"; import Loader from "../components/Loader/Loader"; import Footer from "../components/Footer"; +import FoodCard from "../components/FoodCard"; import { ThemeContext } from '../themeContext'; -const StarRating = ({ rating, onRatingChange }) => { - const [hoverRating, setHoverRating] = useState(0); - - return ( -
- {[1, 2, 3, 4, 5].map((star) => ( - - ))} -
- ); -}; - function MenuPage() { const { _id } = useParams(); - const [breakfast, setBreakfast] = useState(); - const [lunch, setLunch] = useState(); - const [dinner, setDinner] = useState(); - const [selectedDish, setSelectedDish] = useState(null); + const [breakfast, setBreakfast] = useState([]); + const [lunch, setLunch] = useState([]); + const [dinner, setDinner] = useState([]); + const [selectedCategory, setSelectedCategory] = useState('breakfast'); const [feedback, setFeedback] = useState(""); - const [rating, setRating] = useState(0); const [loading, setLoading] = useState(false); const [searchTerm, setSearchTerm] = useState(""); const [searchResults, setSearchResults] = useState([]); @@ -54,7 +33,7 @@ function MenuPage() { } ); const res = await getBreakfast.json(); - setBreakfast(res); + setBreakfast(res.data); } catch (error) { console.error(error); } finally { @@ -75,7 +54,7 @@ function MenuPage() { } ); const res = await getLunch.json(); - setLunch(res); + setLunch(res.data); } catch (error) { console.error(error); } finally { @@ -96,7 +75,7 @@ function MenuPage() { } ); const res = await getDinner.json(); - setDinner(res); + setDinner(res.data); } catch (error) { console.error(error); } finally { @@ -152,9 +131,9 @@ function MenuPage() { } }; - const handleFeedbackSubmit = async () => { - if (feedback.trim() === '' && rating === 0) { - toast.error("Please provide your feedback and rating before submitting."); + function handleFeedbackSubmit() { + if (feedback.trim() === '') { + toast.error("Please provide your feedback before submitting."); } else { setFeedback(''); toast.success('Feedback Submitted!'); @@ -178,29 +157,10 @@ function MenuPage() { } if (items.length === 0) { return

No {selectedCategory.charAt(0).toUpperCase() + selectedCategory.slice(1)} Available Now

; - try { - const response = await axios.post( - `${process.env.REACT_APP_BASE_URL}/feedback`, - { - canteenId: _id, - feedback: feedback, - rating: rating, - studentId: localStorage.getItem('token') - }, - { - headers: { - "Content-Type": "application/json", - }, - } - ); - setFeedback(''); - setRating(0); - toast.success('Feedback Submitted!'); - } catch (error) { - console.error("Error submitting feedback: ", error); - toast.error("Failed to submit feedback. Please try again."); - } } + return items.map((dish) => ( + handleDishClick(dish.dishId)} /> + )); }; const renderSearchResults = () => { @@ -213,7 +173,7 @@ function MenuPage() { }; return ( -
+
@@ -252,112 +212,22 @@ function MenuPage() { )} )} -
-

Today's Menu

- { - loading ? ( - - ) : ( - <> -
- {breakfast && ( -
-
- Breakfast Icon - Breakfast -
-
-
    - {breakfast.data.map((dish) => ( -
  • handleDishClick(dish.dishId)} - className={`cursor-pointer hover:bg-gradient-to-r from-green-300 to-green-500 transition-transform duration-300 ease-in-out transform hover:-translate-y-1 px-5 py-2 ${theme === 'dark' ? 'text-white' : 'text-red-600'} hover:text-black mt-2 `} - > - • {dish.dish} -
  • - ))} -
-
-
- )} - {lunch && ( -
-
- Lunch Icon - Lunch -
-
-
    - {lunch.data.map((dish) => ( -
  • handleDishClick(dish.dishId)} - className={`hover:bg-gradient-to-r from-green-300 to-green-500 transition-transform duration-300 ease-in-out transform hover:-translate-y-1 px-5 py-2 ${theme === 'dark' ? 'text-white' : 'text-green-600'} hover:text-black mt-2 `} - > - • {dish.dish} -
  • - ))} -
-
-
- )} - {dinner && ( -
-
- Dinner Icon - Dinner -
-
-
    - {dinner.data.map((dish) => ( -
  • handleDishClick(dish.dishId)} - className={`hover:bg-gradient-to-r from-yellow-300 to-yellow-500 transition-transform duration-300 ease-in-out transform hover:-translate-y-1 px-5 py-2 ${theme === 'dark' ? 'text-white' : 'text-yellow-600'} hover:text-black mt-2 `} - > - • {dish.dish} -
  • - ))} -
-
-
- )} -
-
-

Meal Feedback

- -
- -
- -
- - ) - }
+
+

Meal Feedback

+ + +
);