From 678ba0a4c2f64d0e6914186e9004e695ce9f9cb1 Mon Sep 17 00:00:00 2001 From: chaaanuwu Date: Thu, 9 Apr 2026 09:03:43 +0530 Subject: [PATCH 1/3] feat: Add Dropdown component for profile options and refactor modal state management --- client/src/components/ui/Dropdown.jsx | 19 +++++++++++++ client/src/pages/Profile.jsx | 41 ++++++++++++++++++++------- 2 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 client/src/components/ui/Dropdown.jsx diff --git a/client/src/components/ui/Dropdown.jsx b/client/src/components/ui/Dropdown.jsx new file mode 100644 index 0000000..7adf4ad --- /dev/null +++ b/client/src/components/ui/Dropdown.jsx @@ -0,0 +1,19 @@ +import { motion, AnimatePresence } from "framer-motion"; + +export default function Dropdown({ open, children }) { + return ( + + {open && ( + + {children} + + )} + + ); +} \ No newline at end of file diff --git a/client/src/pages/Profile.jsx b/client/src/pages/Profile.jsx index c7ad3b9..4053dac 100644 --- a/client/src/pages/Profile.jsx +++ b/client/src/pages/Profile.jsx @@ -1,6 +1,6 @@ import { useParams } from "react-router-dom"; import { useState, useEffect } from "react"; -import { motion } from "framer-motion"; +import { motion, AnimatePresence } from "framer-motion"; import bbBg from "../assets/bb-bg.jpg"; import defaultPfp from "../assets/default-pfp.jpg"; @@ -11,11 +11,13 @@ import Loader from "../components/ui/Loader"; import Modal from "../components/ui/Modal"; import SearchBar from "../components/ui/SearchBar"; import { getHistoryBanner } from "../api/history.api"; +import Dropdown from "../components/ui/Dropdown"; export default function Profile() { const [profileData, setProfileData] = useState(null); const [loading, setLoading] = useState(true); - const [open, setOpen] = useState(false); + const [isModalOpen, setIsModalOpen] = useState(false); + const [isDropdownOpen, setIsDropdownOpen] = useState(false); const [banners, setBanners] = useState([]); const [selectedBackdrop, setSelectedBackdrop] = useState(null); const user = useUserStore((state) => state.user); @@ -37,7 +39,7 @@ export default function Profile() { }, [userId]); const handleChangeCover = async () => { - setOpen(true); + setIsModalOpen(true); try { const bannerData = await getHistoryBanner(); const movies = bannerData.data.map(item => item.movieId); @@ -58,7 +60,7 @@ export default function Profile() { cover: selectedBackdrop } })); - setOpen(false); + setIsModalOpen(false); setSelectedBackdrop(null); } catch (err) { console.error("Failed to set profile cover", err); @@ -77,7 +79,7 @@ export default function Profile() { initial={{ scale: 1.1, opacity: 0 }} animate={{ scale: 1, opacity: 1 }} transition={{ duration: 0.8 }} - src={`${import.meta.env.VITE_TMDB_BACKDROP_BASE_URL}${profileData.user.cover}` || bbBg} + src={profileData.user.cover ? `${import.meta.env.VITE_TMDB_BACKDROP_BASE_URL}${profileData.user.cover}` : bbBg} alt="Cover" className="w-full h-full object-cover" draggable="false" @@ -150,9 +152,28 @@ export default function Profile() { )} - + {/* DROPDOWN CONTAINER */} +
+ + + +
+ + {isMyProfile && ( + + )} +
+
+
@@ -189,7 +210,7 @@ export default function Profile() { {/* Modal for Cover Selection */} - +
{/* Header */}
@@ -265,7 +286,7 @@ export default function Profile() { {selectedBackdrop && (
+ ))} +
+ ) : ( +
+

No recent searches found

+
+ )} +
+
- {/* ACTIONS */}
{user ? ( <> @@ -83,7 +154,7 @@ export default function Navbar() {
- +
- {/* Icon Container */}
- {/* Text Content */}

Confirm Logout

@@ -116,7 +185,6 @@ export default function Navbar() { Are you sure you want to logout? You'll need to sign back in to review movies.

- {/* Action Buttons */}