271 lines
9.8 KiB
TypeScript
271 lines
9.8 KiB
TypeScript
"use client";
|
||
import React from "react";
|
||
import Navbar from "../../components/Navbar";
|
||
import Counter from "../../components/Counter";
|
||
import SubmitRequest from "../../components/SubmitRequest";
|
||
import { boxItems, newsItems } from "@/constants";
|
||
import Image from "next/image";
|
||
import { cn, convertDate } from "@/lib/utils";
|
||
import Link from "next/link";
|
||
import bgimg from "../../public/img/bg-slide.jpg";
|
||
import Footer from "@/components/Footer";
|
||
|
||
// Import Swiper React components
|
||
import { Swiper, SwiperSlide } from "swiper/react";
|
||
// Import Swiper styles
|
||
import "swiper/css";
|
||
import 'swiper/css/navigation';
|
||
// import required modules
|
||
import { Autoplay, Navigation } from "swiper/modules";
|
||
import { sliderItems } from "@/constants";
|
||
import { useQuery } from "@tanstack/react-query";
|
||
import { getSliders, getNews } from "@/utils/commonApi";
|
||
|
||
interface News {
|
||
id: string;
|
||
image: {
|
||
id: string;
|
||
url: string;
|
||
url2: string;
|
||
url3: string;
|
||
url4: string;
|
||
alternateText: string;
|
||
title: string;
|
||
mediaType: 0;
|
||
};
|
||
title: string;
|
||
description: string;
|
||
dateTime: string;
|
||
url: string;
|
||
content: string;
|
||
isDeleted: boolean;
|
||
}
|
||
|
||
export default function Landing() {
|
||
const { data, isLoading, refetch } = useQuery({
|
||
queryKey: ["Sliders"],
|
||
queryFn: () => getSliders(),
|
||
refetchOnWindowFocus: false,
|
||
});
|
||
|
||
const {
|
||
data: NewsData,
|
||
isLoading: NewsIsLoading,
|
||
isError: NewsIsError,
|
||
refetch: NewsRefetch,
|
||
} = useQuery({
|
||
queryKey: ["News"],
|
||
queryFn: () => getNews(),
|
||
refetchOnWindowFocus: false,
|
||
});
|
||
|
||
return (
|
||
<div className="overflow-x-hidden max-md:-mt-8">
|
||
<div className="w-screen bg-top lg:bg-center bg-no-repeat h-[13rem] sm:h-[20rem] md:h-[24rem] xl:h-[33rem]">
|
||
<Swiper
|
||
slidesPerView={1}
|
||
spaceBetween={0}
|
||
navigation={true}
|
||
autoplay={{
|
||
delay: 2500,
|
||
disableOnInteraction: false,
|
||
}}
|
||
loop={false}
|
||
pagination={{
|
||
clickable: true,
|
||
}}
|
||
modules={[Autoplay , Navigation]}
|
||
className="mySwiper w-full h-full"
|
||
>
|
||
{data?.length > 0 ? (
|
||
<>
|
||
{data.map((item: any, index: number) => {
|
||
return (
|
||
<SwiperSlide key={item.id}>
|
||
<Image
|
||
alt="bg"
|
||
src={`${process.env.NEXT_PUBLIC_BASE_URL_APP}${item?.image?.url}`}
|
||
// width={100}
|
||
// height={100}
|
||
layout="fill"
|
||
quality={100}
|
||
className=" w-full h-full object-cover max-sm:object-[70%]"
|
||
/>
|
||
</SwiperSlide>
|
||
);
|
||
})}
|
||
{data?.length == 1 && (
|
||
<SwiperSlide>
|
||
<Image
|
||
alt="bg"
|
||
src={`${process.env.NEXT_PUBLIC_BASE_URL_APP}${data[0]?.image?.url}`}
|
||
// width={20}
|
||
// height={20}
|
||
layout="fill"
|
||
quality={100}
|
||
className=" w-full h-full object-cover max-sm:object-[70%]"
|
||
/>
|
||
</SwiperSlide>
|
||
)}
|
||
</>
|
||
) : (
|
||
<>
|
||
{sliderItems.map((item) => {
|
||
return (
|
||
<SwiperSlide key={item.id}>
|
||
<Image
|
||
alt="bg"
|
||
src={bgimg}
|
||
// width={20}
|
||
// height={20}
|
||
quality={100}
|
||
className=" w-full h-full object-cover max-sm:object-[70%]"
|
||
/>
|
||
</SwiperSlide>
|
||
);
|
||
})}
|
||
</>
|
||
)}
|
||
</Swiper>
|
||
</div>
|
||
|
||
<div className="3xl:w-[60%] w-[80%] mx-auto max-md:mt-5">
|
||
<div className="flex justify-between gap-6 w-full mx-auto -mt-24 max-md:mt-0 max-sm:flex-wrap max-sm:justify-around ">
|
||
{boxItems.map((item, index) => {
|
||
return (
|
||
<Link
|
||
className="group bg-white shadow-md rounded-lg p-10 h-64 w-64 flex items-end justify-center z-10 relative
|
||
hover:bg-blue transition-all duration-700 ease-in-out text-center
|
||
hover:flex-col-reverse hover:justify-evenly hover:items-center hover:cursor-pointer
|
||
max-lg:w-52 max-lg:h-52 max-md:w-40 max-md:h-40
|
||
max-lg:p-8 max-md:p-5 max-sm:p-2 hover:max-lg:p-2
|
||
max-md:shadow-[0px_0px_8px_0px_#00000040]
|
||
"
|
||
key={index}
|
||
href={item.link}
|
||
onClick={() => {
|
||
localStorage.removeItem("Sootzani_Login_State");
|
||
if (index == 0) {
|
||
localStorage.setItem("unknown", "true");
|
||
}
|
||
}}
|
||
>
|
||
<p className="text-xs text-center font-medium text-gray hidden group-hover:flex group-hover:text-white">
|
||
{item.description}
|
||
</p>
|
||
<p className=" z-10 text-base text-black group-hover:text-white max-md:text-sm">
|
||
{item.name}
|
||
</p>
|
||
|
||
<Image
|
||
alt="icon"
|
||
src={item.icon}
|
||
width={20}
|
||
height={20}
|
||
quality={100}
|
||
key={index}
|
||
className={cn(
|
||
" w-[80%] h-[80%] absolute left-8 top-6 group-hover:hidden max-md:h-[60%] max-md:w-[60%] max-md:left-auto",
|
||
item.id == 3 && "left-2"
|
||
)}
|
||
/>
|
||
|
||
<Image
|
||
alt="icon"
|
||
src={item.icon2}
|
||
width={20}
|
||
height={20}
|
||
quality={100}
|
||
key={index}
|
||
className=" w-[45%] h-[45%] hidden group-hover:flex"
|
||
/>
|
||
</Link>
|
||
);
|
||
})}
|
||
</div>
|
||
|
||
{/* News */}
|
||
<div className=" border mt-6 mx-auto py-3 px-4 rounded-lg">
|
||
آخرین اخبار
|
||
</div>
|
||
<div className=" w-full mt-6 flex flex-row gap-8 mb-14 max-lg:flex-col max-lg:gap-4 ">
|
||
{/* Right News */}
|
||
{NewsData && (
|
||
<>
|
||
{" "}
|
||
<div
|
||
className=" w-1/2 max-lg:w-full border rounded-lg flex flex-row shadow-md hover:shadow-none transition-all
|
||
max-lg:h-[14em] max-md:h-[12em] max-sm:h-[22em] max-sm:flex-col max-sm:gap-[3px]"
|
||
>
|
||
<div className="w-1/2 h-full rounded-r-lg max-sm:h-1/2 max-md:w-1/3 max-sm:w-full">
|
||
<Image
|
||
alt="picture"
|
||
src={`${process.env.NEXT_PUBLIC_BASE_URL_APP}${NewsData[0]?.image?.url}`}
|
||
height={500}
|
||
width={500}
|
||
quality={100}
|
||
className="w-full h-full rounded-r-lg bg-cover object-cover object-center"
|
||
/>
|
||
</div>
|
||
|
||
<div className=" w-1/2 h-full flex flex-col p-8 justify-between max-lg:p-4 max-md:justify-evenly max-md:w-2/3 max-sm:h-1/2 max-sm:w-full">
|
||
<div className=" flex flex-col gap-2">
|
||
<p className="text-[10px] font-bold text-right text-white bg-blue p-1 rounded ">
|
||
اخبار
|
||
</p>
|
||
<p className="text-xs font-medium text-right text-black">
|
||
{convertDate(NewsData[0]?.dataTime)}
|
||
</p>
|
||
<p className="text-base font-medium text-right text-black line-clamp-1">
|
||
{NewsData[0]?.title}
|
||
</p>
|
||
<p className="text-sm font-normal text-justify text-[#3C3C43D9] line-clamp-5 max-md:line-clamp-2">
|
||
{NewsData[0]?.description ? NewsData[0]?.description : ""}
|
||
</p>
|
||
</div>
|
||
<Link
|
||
href="#"
|
||
className="text-[10px] font-normal text-blue text-left"
|
||
>
|
||
بیشتر بخوانید{" "}
|
||
</Link>
|
||
</div>
|
||
</div>
|
||
{/* Left News */}
|
||
<div className=" w-1/2 max-lg:w-full flex flex-col gap-[2px] max-lg:gap-4">
|
||
{NewsData.slice(1, 4).map((item: News, index: number) => {
|
||
return (
|
||
<div
|
||
className=" w-full h-1/3 flex flex-col border rounded-lg justify-between px-8 py-[10px] hover:shadow-[0px_0px_8px_0px_#00000040] transition-all
|
||
max-lg:px-4 max-lg:gap-3"
|
||
key={index}
|
||
>
|
||
<div className="flex flex-row justify-between items-center max-sm:flex-col-reverse">
|
||
<p className="text-base font-medium text-right text-black max-sm:self-start">
|
||
{item.title}
|
||
</p>
|
||
<p className="text-xs font-medium text-right text-black max-sm:self-end">
|
||
{convertDate(item.dateTime)}
|
||
</p>
|
||
</div>
|
||
<p className="text-sm font-normal text-justify text-[#3C3C43D9] max-md:line-clamp-3 md:line-clamp-2">
|
||
{item?.description}
|
||
</p>
|
||
</div>
|
||
);
|
||
})}
|
||
</div>
|
||
</>
|
||
)}
|
||
</div>
|
||
</div>
|
||
{/* Counter */}
|
||
{/* <Counter /> */}
|
||
{/*SubmitRequest */}
|
||
<SubmitRequest />
|
||
{/* Footer */}
|
||
<Footer />
|
||
</div>
|
||
);
|
||
}
|