66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
"use client";
|
|
import { convertFullTime } from "@/lib/utils";
|
|
import { getSingleNews } from "@/utils/CitizenNews";
|
|
import { useQuery } from "@tanstack/react-query";
|
|
import { useParams } from "next/navigation";
|
|
import React, { useEffect, useState } from "react";
|
|
|
|
interface NewsDetails {
|
|
id: string;
|
|
title: string;
|
|
description: string;
|
|
url: string;
|
|
imageFile: {
|
|
id: string;
|
|
url: string;
|
|
url2: string;
|
|
url3: string;
|
|
url4: string;
|
|
alternateText: string;
|
|
title: string;
|
|
mediaType: 0;
|
|
};
|
|
created: string;
|
|
isDeleted: boolean;
|
|
}
|
|
|
|
interface NewsProps {
|
|
id: number;
|
|
}
|
|
|
|
const NewsDetails: React.FC<NewsProps> = ({ id }) => {
|
|
// const NewsDetails: React.FC<NewsProps> = () => {
|
|
// const id = Number(useParams());
|
|
// const { id } = useParams();
|
|
|
|
const [details, setDetails] = useState<any | null>(null);
|
|
const { data, isLoading, isError, isSuccess, refetch } = useQuery({
|
|
queryKey: ["NewsDetails", id],
|
|
queryFn: () => getSingleNews(id),
|
|
});
|
|
|
|
useEffect(() => {
|
|
if (data) {
|
|
console.log(data);
|
|
console.log(data.data);
|
|
console.log(data.data[0]);
|
|
setDetails(data.data);
|
|
}
|
|
}, [data]);
|
|
|
|
return (
|
|
<div className=" w-full">
|
|
<div className=" flex justify-between items-center w-full">
|
|
<h1 className=" text-xl text-blue">{details?.title}</h1>
|
|
<p className=" text-gray-600">{convertFullTime(details?.created)}</p>
|
|
</div>
|
|
<div
|
|
className="w-full mt-2 news-description"
|
|
dangerouslySetInnerHTML={{ __html: details?.description }}
|
|
></div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default NewsDetails;
|