72 lines
1.9 KiB
TypeScript
72 lines
1.9 KiB
TypeScript
"use client";
|
||
import { convertFullTime } from "@/lib/utils";
|
||
import { getNewsById } from "@/utils/commonApi";
|
||
import { useQuery } from "@tanstack/react-query";
|
||
import { ArrowRight } from "lucide-react";
|
||
import Image from "next/image";
|
||
import { useRouter } from "next/navigation";
|
||
import React from "react";
|
||
|
||
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 NewsDetail({ id }: { id: any }) {
|
||
const router = useRouter();
|
||
const { data, isLoading, isError, refetch } = useQuery({
|
||
queryKey: ["News", id],
|
||
queryFn: () => getNewsById(id),
|
||
});
|
||
|
||
return (
|
||
<div className="mt-10 w-full md:w-1/2 max-md:px-3">
|
||
{data && (
|
||
<>
|
||
<div className=" text-blue gap-1 mb-2 bg-gray-100 rounded-md p-2">
|
||
<div
|
||
className=" flex items-center cursor-pointer"
|
||
onClick={() => router.push("/News")}
|
||
>
|
||
<span>
|
||
<ArrowRight />
|
||
</span>
|
||
<span>بازگشت</span>
|
||
</div>
|
||
</div>
|
||
<p className=" font-bold mb-2">{data?.title}</p>
|
||
<div className=" w-full border ">
|
||
<Image
|
||
alt="picture"
|
||
src={`${process.env.NEXT_PUBLIC_BASE_URL_APP}${data?.image?.url}`}
|
||
height={500}
|
||
width={500}
|
||
quality={100}
|
||
className="w-full h-auto bg-cover object-cover rounded-md"
|
||
/>
|
||
</div>
|
||
<div className=" text-gray-500 mt-2">
|
||
{convertFullTime(data.dateTime)}
|
||
</div>
|
||
<div className="">{data.content}</div>
|
||
</>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|