Sootzani/components/News.tsx

89 lines
3.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"use client";
import React, { useEffect, useState } from "react";
import { getNews } from "@/utils/commonApi";
import { useQuery } from "@tanstack/react-query";
import Image from "next/image";
import Link from "next/link";
import { convertFullTime } from "@/lib/utils";
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 News() {
const { data, isLoading, isError, refetch } = useQuery({
queryKey: ["News"],
queryFn: () => getNews(),
});
console.log(data);
return (
<div className="bg-white dark:bg-gray-900 pt-8 container">
<h2 className=" w-full font-bold mb-2">اخبار</h2>
<div className="w-full flex flex-wrap lg:flex-row gap-8 mb-14 flex-col max-lg:gap-4">
{/* {data.map((item: any, index: number) => {
return <p key={index}>News</p>;
})} */}
{data?.map((item: News) => {
return (
<div
className="w-full lg:w-[48%] border rounded-lg flex flex-row shadow-md hover:shadow-none transition-all
h-[20em] sm:h-[15em] 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}${item?.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">
{/* <p className="text-[10px] font-bold text-right text-white bg-blue p-1 rounded ">
اخبار
</p> */}
<div className=" flex flex-col gap-1">
<p className="text-xs font-medium text-right text-black">
{convertFullTime(item.dateTime)}
</p>
<p className="text-base font-medium text-right text-black line-clamp-1">
{item.title}
</p>
<p className="text-sm font-normal text-justify text-[#3C3C43D9] line-clamp-5 max-md:line-clamp-2">
{item?.description}
</p>
</div>
<Link
href={`News/${item.id}`}
className="text-[11px] font-normal text-blue text-left hover:underline"
>
بیشتر بخوانید{" "}
</Link>
</div>
</div>
);
})}
</div>
</div>
);
}