web-humas-fe/components/main/detail/new-detail.tsx

82 lines
2.7 KiB
TypeScript
Raw Normal View History

"use client";
import React, { useEffect, useState } from "react";
2024-11-05 06:15:40 +00:00
import DetailNews from "../../page/detail-news";
import SidebarDetail from "../../page/sidebar-detail";
import RelatedNews from "../../page/related-news";
import Comment from "./comment";
2025-05-04 07:14:12 +00:00
import { getArticleById, getListArticle } from "@/services/article";
2025-02-07 09:37:39 +00:00
import { useParams, usePathname } from "next/navigation";
import Link from "next/link";
2025-01-30 11:34:29 +00:00
import { ChevronRightIcon, UserIcon } from "@/components/icons";
import { close, loading } from "@/config/swal";
2025-05-04 07:14:12 +00:00
import { saveActivity } from "@/services/activity-log";
2025-02-07 09:37:39 +00:00
import Cookies from "js-cookie";
2025-03-10 06:03:43 +00:00
import Head from "next/head";
2025-02-07 09:37:39 +00:00
const token = Cookies.get("access_token");
const uid = Cookies.get("uie");
2024-11-05 06:15:40 +00:00
2025-03-14 07:50:34 +00:00
export default function NewsDetailPage(props: { datas: any }) {
const params = useParams();
const id: any = params?.id;
2025-02-07 09:37:39 +00:00
const pathname = usePathname();
2025-03-10 06:03:43 +00:00
const [detailArticle, setDetailArticle] = useState<any>();
2025-01-15 11:37:53 +00:00
const [articles, setArticles] = useState<any>([]);
useEffect(() => {
2025-01-15 11:37:53 +00:00
getArticles();
2025-02-07 09:37:39 +00:00
sendActivity();
}, []);
2025-01-15 11:37:53 +00:00
async function getArticles() {
2025-05-19 13:38:35 +00:00
const req = { page: 1, search: "", limit: "50", isPublish: true };
2025-01-15 11:37:53 +00:00
const response = await getListArticle(req);
setArticles(response?.data?.data);
}
2025-02-07 09:37:39 +00:00
const sendActivity = async () => {
let req: any = {
activityTypeId: 2,
2025-04-28 16:29:26 +00:00
url: "https://new-humas.polri.go.id" + pathname,
2025-02-07 09:37:39 +00:00
articleId: Number(id?.split("-")[0]),
};
if (uid) {
req.userId = Number(uid);
}
const resActivity = await saveActivity(req, token);
};
2025-03-26 08:27:09 +00:00
2024-11-05 06:15:40 +00:00
return (
2025-03-10 06:03:43 +00:00
<>
<div className="bg-white dark:bg-stone-900">
<div className="px-5 lg:px-0 lg:w-[75vw] lg:mx-auto py-8">
<div className="flex flex-row gap-4 items-end ">
<Link href="/" className=" font-semibold text-lg">
Beranda
</Link>
<ChevronRightIcon />
<p className=" text-lg">Berita</p>
</div>
<div className=" lg:flex lg:justify-around gap-4 lg:gap-16 w-full">
2025-03-14 07:50:34 +00:00
<DetailNews data={props.datas} listArticle={articles} />
2025-03-10 06:03:43 +00:00
<div className="w-auto lg:w-[25%] hidden lg:block">
<SidebarDetail />
</div>
</div>
2025-03-10 06:03:43 +00:00
<div className="w-full lg:w-[70%] h-auto my-2 md:my-5 lg:my-10 px-0 lg:px-3">
<Comment id={id?.split("-")[0]} />
</div>
2025-03-10 06:03:43 +00:00
<div className="bg-gray-50 text-black dark:bg-black dark:text-white lg:px-24 my-4 lg:my-8 pt-3 lg:pb-4 rounded-lg shadow-md h-fit ">
<RelatedNews categories={props.datas.categories} />
2025-03-10 06:03:43 +00:00
</div>
<div className="md:hidden text-black">
<SidebarDetail />
</div>
2024-11-05 06:15:40 +00:00
</div>
</div>
2025-03-10 06:03:43 +00:00
</>
2024-11-05 06:15:40 +00:00
);
}