From 69877617f5fd62441b62c0fe3be4de7a03f3243f Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Mon, 19 May 2025 20:38:35 +0700 Subject: [PATCH] fix:little update --- components/form/login.tsx | 2 ++ components/main/detail/list-news.tsx | 5 ++-- components/main/detail/new-detail.tsx | 2 +- components/page/detail-news.tsx | 36 +++++++++++++++------------ components/page/related-news.tsx | 2 +- 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/components/form/login.tsx b/components/form/login.tsx index 606114d..d798e89 100644 --- a/components/form/login.tsx +++ b/components/form/login.tsx @@ -61,11 +61,13 @@ export default function Login() { if (!username || !password) { error("Username & Password Wajib Diisi !"); } else { + loading(); const response = await emailValidation(data); if (response?.error) { error("Username / Password Tidak Sesuai"); return false; } + close(); if (response?.data?.messages[0] === "Continue to setup email") { setFirstLogin(true); diff --git a/components/main/detail/list-news.tsx b/components/main/detail/list-news.tsx index b31870d..b580793 100644 --- a/components/main/detail/list-news.tsx +++ b/components/main/detail/list-news.tsx @@ -26,6 +26,7 @@ import { useRouter, useSearchParams, } from "next/navigation"; +import { close, loading } from "@/config/swal"; export default function ListNews() { const [article, setArticle] = useState([]); @@ -45,7 +46,7 @@ export default function ListNews() { }, [page, category]); async function getArticle() { - // loading(); + loading(); topRef.current?.scrollIntoView({ behavior: "smooth" }); const req = { @@ -63,7 +64,7 @@ export default function ListNews() { const response = await getListArticle(req); setArticle(response?.data?.data); setTotalPage(response?.data?.meta?.totalPage); - // close(); + close(); } return ( diff --git a/components/main/detail/new-detail.tsx b/components/main/detail/new-detail.tsx index a798f54..46e8986 100644 --- a/components/main/detail/new-detail.tsx +++ b/components/main/detail/new-detail.tsx @@ -30,7 +30,7 @@ export default function NewsDetailPage(props: { datas: any }) { }, []); async function getArticles() { - const req = { page: 1, search: "", limit: "50" }; + const req = { page: 1, search: "", limit: "50", isPublish: true }; const response = await getListArticle(req); setArticles(response?.data?.data); } diff --git a/components/page/detail-news.tsx b/components/page/detail-news.tsx index b9a376d..fef2e25 100644 --- a/components/page/detail-news.tsx +++ b/components/page/detail-news.tsx @@ -93,22 +93,26 @@ export default function DetailNews(props: { data: any; listArticle: any }) { }; useEffect(() => { - const index = listArticle.findIndex((item: any) => item?.id === data?.id); - if (index - 1 == -1) { - setPrevArticle(""); - } else { - const prevString = `${listArticle[index - 1]?.id}-${ - listArticle[index - 1]?.slug - }`; - setPrevArticle(prevString); - } - if (index + 1 == listArticle?.length) { - setNextArticle(""); - } else { - const nextString = `${listArticle[index + 1]?.id}-${ - listArticle[index + 1]?.slug - }`; - setNextArticle(nextString); + if (listArticle) { + const index = listArticle?.findIndex( + (item: any) => item?.id === data?.id + ); + if (index - 1 == -1) { + setPrevArticle(""); + } else { + const prevString = `${listArticle[index - 1]?.id}-${ + listArticle[index - 1]?.slug + }`; + setPrevArticle(prevString); + } + if (index + 1 == listArticle?.length) { + setNextArticle(""); + } else { + const nextString = `${listArticle[index + 1]?.id}-${ + listArticle[index + 1]?.slug + }`; + setNextArticle(nextString); + } } }, [data, listArticle]); diff --git a/components/page/related-news.tsx b/components/page/related-news.tsx index 0fc83fa..497a35b 100644 --- a/components/page/related-news.tsx +++ b/components/page/related-news.tsx @@ -17,7 +17,7 @@ export default function RelatedNews() { useEffect(() => { async function getArticle() { - const req = { page: 1, search: "", limit: "10" }; + const req = { page: 1, search: "", limit: "10", isPublish: true }; const response = await getListArticle(req); setArticle(response?.data?.data);