turkmentv_front/components/MobileMenu.tsx

237 lines
9.1 KiB
TypeScript
Raw Normal View History

2025-02-16 09:20:28 +00:00
"use client";
import Image from "next/image";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { useContext, useEffect, useRef, useState } from "react";
import GlobalContext from "@/context/GlobalContext";
import close from "@/public/close-white.svg";
2024-08-19 12:44:56 +00:00
const MobileMenu = () => {
2025-02-16 09:20:28 +00:00
const path = usePathname() ?? "/";
2024-08-19 12:44:56 +00:00
const { burgerOpen, setBurgerOpen } = useContext(GlobalContext).burgerContext;
const onClickCloseBurgerHandler = () => {
setBurgerOpen(false);
};
const [dropDownOpened, setDropDownOpened] = useState(false);
const dropdownRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const handleOutsideClick = (event: MouseEvent) => {
2025-02-16 09:20:28 +00:00
if (
dropdownRef.current &&
!dropdownRef.current.contains(event.target as Node)
) {
2024-08-19 12:44:56 +00:00
setDropDownOpened(false);
}
};
// Attach the event listener to the document
2025-02-16 09:20:28 +00:00
document.addEventListener("click", handleOutsideClick);
2024-08-19 12:44:56 +00:00
// Cleanup the event listener when the component unmounts
return () => {
2025-02-16 09:20:28 +00:00
document.removeEventListener("click", handleOutsideClick);
2024-08-19 12:44:56 +00:00
};
}, []);
return (
<>
{burgerOpen && (
<div className="absolute top-0 left-0 w-full h-fit bg-[#131369] z-50 py-1">
<div className="container">
<div className="w-full h-screen flex flex-col gap-10">
<div className="flex items-center justify-between">
2025-02-16 09:20:28 +00:00
<Link href={"/"} className="logo">
2024-08-19 12:44:56 +00:00
<Image
priority
2025-02-16 09:20:28 +00:00
src={"/logo.png"}
2024-08-19 12:44:56 +00:00
alt="logo"
unoptimized
unselectable="off"
width={60}
height={60}
className="w-[60px] h-[60px] object-contain"
/>
</Link>
<div
className="relative w-[24px] h-[24px] cursor-pointer "
2025-02-16 09:20:28 +00:00
onClick={() => setBurgerOpen(false)}
>
2024-08-19 12:44:56 +00:00
<Image src={close} fill alt="menu" />
</div>
</div>
<ul className="flex flex-col gap-10 items-start justify-center p-6">
2024-10-24 07:48:07 +00:00
{/* <li>
2024-08-19 12:44:56 +00:00
<Link
className="block text-3xl text-white transition-all font-roboto font-bold dark:text-white"
onClick={() => onClickCloseBurgerHandler()}
href={'/news'}
style={path.includes('news') ? { color: '#FFAB48' } : {}}>
Habarlar
</Link>
2024-10-24 07:48:07 +00:00
</li> */}
2024-08-19 12:44:56 +00:00
<li>
<Link
2025-02-16 09:20:28 +00:00
href={"/treasury"}
2024-08-19 12:44:56 +00:00
onClick={() => onClickCloseBurgerHandler()}
className="block text-3xl text-white transition-all font-roboto font-bold dark:text-white"
style={
2025-02-16 09:20:28 +00:00
path.includes("treasury") || path.includes("video/")
? { color: "#FFAB48" }
2024-08-19 12:44:56 +00:00
: {}
2025-02-16 09:20:28 +00:00
}
>
2024-08-19 12:44:56 +00:00
Hazyna
</Link>
</li>
<li>
<Link
2025-02-16 09:20:28 +00:00
href={"/live"}
2024-08-19 12:44:56 +00:00
onClick={() => onClickCloseBurgerHandler()}
className="block text-3xl text-white transition-all font-roboto font-bold dark:text-white"
2025-02-16 09:20:28 +00:00
style={path.includes("live") ? { color: "#FFAB48" } : {}}
>
2024-08-19 12:44:56 +00:00
Göni Ýaýlym
</Link>
</li>
<li>
<Link
2025-02-16 09:20:28 +00:00
href={"/advert"}
2024-08-19 12:44:56 +00:00
onClick={() => onClickCloseBurgerHandler()}
className="block text-3xl text-white transition-all font-roboto font-bold dark:text-white"
2025-02-16 09:20:28 +00:00
style={path.includes("advert") ? { color: "#FFAB48" } : {}}
>
2024-08-19 12:44:56 +00:00
Mahabat
</Link>
</li>
<li>
<Link
2025-02-16 09:20:28 +00:00
href={"/contact_us"}
2024-08-19 12:44:56 +00:00
onClick={() => onClickCloseBurgerHandler()}
2025-02-16 09:20:28 +00:00
style={
path.includes("contact_us") ? { color: "#FFAB48" } : {}
}
className="font-roboto font-bold text-white text-3xl dark:text-white transition-all"
>
2024-08-19 12:44:56 +00:00
Habarlaşmak üçin
</Link>
</li>
<li>
<div
ref={dropdownRef}
className="flex flex-col cursor-pointer relative"
2025-02-16 09:20:28 +00:00
onClick={() => setDropDownOpened(!dropDownOpened)}
>
2024-08-19 12:44:56 +00:00
<div className="flex items-center gap-[8px]">
<span className="block text-3xl text-white transition-all font-roboto font-bold">
Interaktiw
</span>
<svg
xmlns="http://www.w3.org/2000/svg"
width="40"
height="40"
viewBox="0 0 24 24"
fill="none"
className={`${
2025-02-16 09:20:28 +00:00
dropDownOpened ? "" : "rotate-180"
} transition-all ease-in duration-150`}
>
2024-08-19 12:44:56 +00:00
<path
d="M7.41 15.41L12 10.83L16.59 15.41L18 14L12 8L6 14L7.41 15.41Z"
fill="#fff"
/>
</svg>
</div>
<div
className={` flex flex-col gap-4 rounded-[8px] transition-all duration-150 ${
dropDownOpened
2025-02-16 09:20:28 +00:00
? "h-fit opacity-100 pointer-events-auto py-[16px] px-[24px]"
: " h-0 opacity-0 pointer-events-none"
}`}
>
2024-08-19 12:44:56 +00:00
<Link
2025-02-16 09:20:28 +00:00
href={"/quiz"}
2024-08-19 12:44:56 +00:00
className="block text-2xl text-white transition-all font-roboto font-bold "
2025-02-16 09:20:28 +00:00
style={
path.includes("quiz") ? { color: "#FFAB48" } : {}
}
2024-08-19 12:44:56 +00:00
onClick={() => {
setDropDownOpened(false);
onClickCloseBurgerHandler();
2025-02-16 09:20:28 +00:00
}}
>
2024-08-19 12:44:56 +00:00
Bäsleşik
</Link>
<Link
2025-02-16 09:20:28 +00:00
href={"/vote"}
2024-08-19 12:44:56 +00:00
className="block text-2xl text-white transition-all font-roboto font-bold "
2025-02-16 09:20:28 +00:00
style={
path.includes("vote") ? { color: "#FFAB48" } : {}
}
2024-08-19 12:44:56 +00:00
onClick={() => {
setDropDownOpened(false);
onClickCloseBurgerHandler();
2025-02-16 09:20:28 +00:00
}}
>
2024-08-19 12:44:56 +00:00
Ses bermek
</Link>
<Link
2025-02-16 09:20:28 +00:00
href={"https://shop.turkmentv.gov.tm/"}
2024-08-19 12:44:56 +00:00
className="block text-2xl text-white transition-all font-roboto font-bold"
onClick={() => {
setDropDownOpened(false);
onClickCloseBurgerHandler();
2025-02-16 09:20:28 +00:00
}}
>
2024-08-19 12:44:56 +00:00
TV market
</Link>
2024-10-17 11:03:18 +00:00
<Link
2025-02-16 09:20:28 +00:00
href={"/prizes/auth"}
2024-10-14 13:41:39 +00:00
className="block text-2xl text-white transition-all font-roboto font-bold"
2025-02-16 09:20:28 +00:00
style={
path.includes("prizes") ? { color: "#FFAB48" } : {}
}
2024-10-14 13:41:39 +00:00
onClick={() => {
setDropDownOpened(false);
onClickCloseBurgerHandler();
2025-02-16 09:20:28 +00:00
}}
>
2024-10-14 13:41:39 +00:00
Sowgatlar
2024-10-17 11:03:18 +00:00
</Link>
2025-01-10 13:17:37 +00:00
<Link
2025-02-16 09:20:28 +00:00
href={"/b"}
2025-01-10 13:17:37 +00:00
className="block text-2xl text-white transition-all font-roboto font-bold"
2025-02-16 09:20:28 +00:00
style={path.includes("b") ? { color: "#FFAB48" } : {}}
2025-01-10 13:17:37 +00:00
onClick={() => {
setDropDownOpened(false);
onClickCloseBurgerHandler();
2025-02-16 09:20:28 +00:00
}}
>
2025-01-10 13:17:37 +00:00
Bije
</Link>
2024-08-19 12:44:56 +00:00
</div>
</div>
</li>
<li>
<Link
target="_blank"
2025-02-16 09:20:28 +00:00
href={"https://turkmentv.gov.tm/mahabat/admin/user/login"}
2024-08-19 12:44:56 +00:00
onClick={() => onClickCloseBurgerHandler()}
2025-02-16 09:20:28 +00:00
className="font-roboto font-bold text-white text-3xl dark:text-white transition-all p-2 bg-red-500 rounded-lg "
>
2024-08-19 12:44:56 +00:00
Ýaýlym tertibi
</Link>
</li>
</ul>
</div>
</div>
</div>
)}
</>
);
};
export default MobileMenu;