Skip to content

Commit

Permalink
Merge pull request #383 from Saksham2k3s/fix/logout-button-removes-us…
Browse files Browse the repository at this point in the history
…er-token-305

Solved issue 305
  • Loading branch information
hustlerZzZ authored Jun 30, 2024
2 parents ec85a5f + fe072c7 commit 8e91d20
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 35 deletions.
16 changes: 8 additions & 8 deletions server/controllers/canteenController.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ const getBreakfast = async (req, res, next) => {
res.status(500).json({ success: false, error: error.message });
}
};
catch(error){
res.status(500).json({success : false , error : error});
}
}
// catch(error){
// res.status(500).json({success : false , error : error});
// }
// }
const feedback = async (req, res) => {
const { canteenId, feedback, rating } = req.body;
const token = req.body.studentId; // This is the token
Expand Down Expand Up @@ -120,12 +120,12 @@ const canteenFeedbackRender = async (req, res) => {
}
};

const getLunch = async(req , res , next) =>{
// const getLunch = async(req , res , next) =>{

try{
const id = req.params.id;
// try{
// const id = req.params.id;

const lunchData = await Lunch.find({ canteen: id }).select("dish").select("dishId").exec();
// const lunchData = await Lunch.find({ canteen: id }).select("dish").select("dishId").exec();

const getLunch = async (req, res, next) => {
try {
Expand Down
77 changes: 60 additions & 17 deletions src/components/Navbar.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState, useContext, useEffect } from "react";
import { Link } from "react-router-dom";
import React, { useState, useContext } from "react";
import { Link, useNavigate } from "react-router-dom";

import logo from "../assets/logo2.png";
import { motion, AnimatePresence, useScroll } from "framer-motion";
import { IoClose } from "react-icons/io5";
Expand All @@ -9,9 +10,10 @@ import { jwtDecode } from "jwt-decode";
import { useAuth } from "../authContext";

const Navbar = () => {

const navigate = useNavigate();
const canteenId = localStorage.getItem("canteenId");
const { logout} = useAuth();
// const [canteenId, setCanteenId] = useState(null);

const { theme, toggleTheme } = useContext(ThemeContext);
const [isOpen, setIsOpen] = useState(false);
const { scrollYProgress } = useScroll();
Expand All @@ -35,6 +37,12 @@ const Navbar = () => {
setIsOpen(!isOpen);
};

const handleLogout = () => {
localStorage.removeItem('usertoken');
navigate('/')
}


return (
<>
<nav className="text-white p-3 shadow-lg top-0 bg-gradient-to-t from-blue-950 via-blue-950 to-gray-900 w-full fixed z-40 dark:bg-cadetblue dark:bg-none">
Expand Down Expand Up @@ -62,19 +70,21 @@ const Navbar = () => {
</div>
</div>

<div className="hidden md:flex items-center gap-5">
<button onClick={toggleTheme} className="p-2 rounded focus:outline-none text-4xl border-none outline-none">
{theme === 'dark' ? '🌞' : '🌙'}
</button>
<div>
<Link to="/">
<button
onClick={logout}
className={`py-1 px-2 w-full h-auto text-l relative z-0 rounded-lg transition-all duration-200 hover:scale-110 ${theme === 'dark' ? 'bg-white text-black' : 'bg-green-400 hover:bg-green-600 hover:shadow-green text-white'}`}
>
Log out
</button>
</Link>
<div className="hidden md:flex items-center gap-5">
<button onClick={toggleTheme} className="p-2 rounded focus:outline-none text-4xl border-none outline-none">
{theme === 'dark' ? '🌞' : '🌙'}
</button>
<div>
<Link to="/">
<button
onClick={handleLogout}
className={`py-1 px-2 rounded w-full h-auto text-l relative z-0 rounded-lg transition-all duration-200 hover:scale-110 ${theme === 'dark' ? 'bg-white text-black' : 'bg-green-400 hover:bg-green-600 hover:shadow-green text-white'}`}
>
Log out
</button>
</Link>
</div>

</div>
</div>

Expand Down Expand Up @@ -130,6 +140,39 @@ const Navbar = () => {
</nav>
</>

<AnimatePresence>
{isOpen && (
<motion.div
initial={{ opacity: 0, y: -50 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -50 }}
className="md:hidden absolute left-0 w-full flex flex-col items-center justify-center"
>
<div className="w-[100%] bg-[#152146] px-[20%] pt-2 pb-3 space-y-1 mt-1 dark:bg-teal-900">
<MobileNavItem to="/home">Home</MobileNavItem>
<MobileNavItem to="/about">About us</MobileNavItem>
<MobileNavItem to="/news">News</MobileNavItem>
<MobileNavItem to="/contact">Contact</MobileNavItem>
<MobileNavItem to="/rateus">RateUs</MobileNavItem>
{/* Conditionally render "My Canteen" button */}
{canteenId && (
<MobileNavItem to={`/section/${canteenId}`}>My Canteen</MobileNavItem>
)}
<MobileNavItem to="/">
<button
onClick={handleLogout}
className={`rounded transition duration-300 ease-in-out transform hover:scale-105 ${theme === 'dark' ? 'bg-white text-black' : 'bg-green-500 hover:bg-green-700 text-white py-1 px-2'}`}
>
Log out
</button>
</MobileNavItem>
</div>
</motion.div>
)}
</AnimatePresence>
</nav>
</>

);
};

Expand Down
10 changes: 0 additions & 10 deletions src/pages/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import Footer from "../components/Footer";
import FloatBtn from "../components/FloatBtn/FloatBtn";
import { useAuth } from "../authContext";
import { useNavigate } from "react-router-dom";
<<<<<<< Updated upstream
=======
import Reviews from "../components/Feedback";
>>>>>>> Stashed changes

function Home() {
const navigate = useNavigate();
Expand Down Expand Up @@ -140,12 +136,6 @@ function Home() {
<div className="text-center">
<CanteenList canteenData={filteredCanteenData} />
</div>
<<<<<<< Updated upstream
=======
<div className="canteenReviews">
<Reviews></Reviews>
</div>
>>>>>>> Stashed changes
<Footer />
</div>
)}
Expand Down

0 comments on commit 8e91d20

Please sign in to comment.