From 92bba180ef903880ed17307960dc23d77c830939 Mon Sep 17 00:00:00 2001 From: Sabda Yagra Date: Tue, 24 Jun 2025 11:25:39 +0700 Subject: [PATCH] fixing --- .../admin/settings/banner/component/table.tsx | 44 +++++++++--- .../settings/popup/component/popup-table.tsx | 25 ++++--- .../admin/settings/popup/component/table.tsx | 67 ++++++++++++++++--- .../polda/[polda_name]/audio/filter/page.tsx | 7 +- .../[polda_name]/document/filter/page.tsx | 5 +- .../polda/[polda_name]/image/filter/page.tsx | 5 +- .../polda/[polda_name]/video/filter/page.tsx | 5 +- .../[satker_name]/audio/filter/page.tsx | 7 +- .../[satker_name]/document/filter/page.tsx | 5 +- .../[satker_name]/image/filter/page.tsx | 7 +- .../[satker_name]/video/filter/page.tsx | 5 +- app/[locale]/(public)/audio/filter/page.tsx | 5 +- .../(public)/document/filter/page.tsx | 5 +- app/[locale]/(public)/image/filter/page.tsx | 9 +-- app/[locale]/(public)/video/filter/page.tsx | 7 +- service/landing/landing.ts | 2 +- 16 files changed, 150 insertions(+), 60 deletions(-) diff --git a/app/[locale]/(protected)/admin/settings/banner/component/table.tsx b/app/[locale]/(protected)/admin/settings/banner/component/table.tsx index 44d98ec7..a98ab776 100644 --- a/app/[locale]/(protected)/admin/settings/banner/component/table.tsx +++ b/app/[locale]/(protected)/admin/settings/banner/component/table.tsx @@ -94,9 +94,7 @@ const ContentListBanner = () => { const [selectedItems, setSelectedItems] = React.useState([]); const [page, setPage] = React.useState(1); const [totalPage, setTotalPage] = React.useState(1); - - let typingTimer: any; - const doneTypingInterval = 1500; + const [searchQuery, setSearchQuery] = React.useState(""); const handleKeyUp = () => { clearTimeout(typingTimer); @@ -108,6 +106,21 @@ const ContentListBanner = () => { typingTimer = setTimeout(doneTyping, doneTypingInterval); }; + let typingTimer: NodeJS.Timeout; + const doneTypingInterval = 1500; + + const handleTyping = () => { + clearTimeout(typingTimer); + typingTimer = setTimeout(() => { + setPage(1); + fetchData(); + }, doneTypingInterval); + }; + + React.useEffect(() => { + fetchData(); + }, [categoryFilter, statusFilter]); + async function doneTyping() { fetchData(); } @@ -133,10 +146,11 @@ const ContentListBanner = () => { const res = await listDataMedia( page - 1, showData, - "", + searchQuery, categoryFilter?.sort().join(","), statusFilter?.sort().join(",") ); + const data = res?.data?.data; const contentData = data?.content; contentData.forEach((item: any, index: number) => { @@ -224,10 +238,19 @@ const ContentListBanner = () => { { + setSearchQuery(e.target.value); + handleTyping(); + }} className="max-w-[300px]" + onKeyDown={(e) => { + if (e.key === "Enter") { + fetchData(); + } + }} /> + {/*
@@ -393,9 +416,12 @@ const ContentListBanner = () => { alt={item.title} className="w-full h-48 object-cover" /> -
-

{item.title}

-
+ +

{item.title}

+
))} diff --git a/app/[locale]/(protected)/admin/settings/popup/component/popup-table.tsx b/app/[locale]/(protected)/admin/settings/popup/component/popup-table.tsx index 76b609ea..aaab2881 100644 --- a/app/[locale]/(protected)/admin/settings/popup/component/popup-table.tsx +++ b/app/[locale]/(protected)/admin/settings/popup/component/popup-table.tsx @@ -98,16 +98,21 @@ const PopUpListTable = () => { loading(); let temp: any; - const response = await listDataPopUp( - page - 1, - showData, - "", - categoryFilter?.sort().join(","), - statusFilter?.sort().join(",") - ); - const data = response?.data?.data?.content; - console.log("banner", data); - setGetData(data); + // const response = await listDataPopUp( + // page - 1, + // showData, + // "", + // categoryFilter?.sort().join(","), + // statusFilter?.sort().join(",") + // ); + // const data = response?.data?.data?.content; + // console.log("banner", data); + // setGetData(data); + + const response = await listBanner(); + const data = response?.data?.data?.content; + console.log("banner", data); + setGetData(data); close(); } diff --git a/app/[locale]/(protected)/admin/settings/popup/component/table.tsx b/app/[locale]/(protected)/admin/settings/popup/component/table.tsx index 5361510a..b8697f7c 100644 --- a/app/[locale]/(protected)/admin/settings/popup/component/table.tsx +++ b/app/[locale]/(protected)/admin/settings/popup/component/table.tsx @@ -94,9 +94,10 @@ const ContentListPopUp = () => { const [selectedItems, setSelectedItems] = React.useState([]); const [page, setPage] = React.useState(1); const [totalPage, setTotalPage] = React.useState(1); + const [searchQuery, setSearchQuery] = React.useState(""); - let typingTimer: any; - const doneTypingInterval = 1500; + let typingTimer: NodeJS.Timeout; + const doneTypingInterval = 2000; const handleKeyUp = () => { clearTimeout(typingTimer); @@ -105,9 +106,16 @@ const ContentListPopUp = () => { const handleKeyDown = () => { clearTimeout(typingTimer); - typingTimer = setTimeout(doneTyping, doneTypingInterval); + typingTimer = setTimeout(() => { + setPage(1); + fetchData(); + }, doneTypingInterval); }; + React.useEffect(() => { + fetchData(); + }, [categoryFilter, statusFilter]); + async function doneTyping() { fetchData(); } @@ -127,13 +135,40 @@ const ContentListPopUp = () => { }); }, [page, showData]); + // async function fetchData() { + // try { + // loading(); + // const res = await listDataPopUp( + // page - 1, + // showData, + // "", + // categoryFilter?.sort().join(","), + // statusFilter?.sort().join(",") + // ); + // const data = res?.data?.data; + // const contentData = data?.content; + // contentData.forEach((item: any, index: number) => { + // item.no = (page - 1) * Number(showData) + index + 1; + // }); + + // console.log("contentData : ", data); + + // setData(contentData); + // setTotalData(data?.totalElements); + // setTotalPage(data?.totalPages); + // close(); + // } catch (error) { + // console.error("Error fetching tasks:", error); + // } + // } + async function fetchData() { try { loading(); - const res = await listDataPopUp( + const res = await listDataMedia( page - 1, showData, - "", + searchQuery, // <-- gunakan nilai pencarian categoryFilter?.sort().join(","), statusFilter?.sort().join(",") ); @@ -224,10 +259,19 @@ const ContentListPopUp = () => { { + setSearchQuery(e.target.value); + handleKeyDown(); + }} + onKeyDown={(e) => { + if (e.key === "Enter") { + fetchData(); + } + }} className="max-w-[300px]" /> + {/*
@@ -393,9 +437,12 @@ const ContentListPopUp = () => { alt={item.title} className="w-full h-48 object-cover" /> -
-

{item.title}

-
+ +

{item.title}

+
))} diff --git a/app/[locale]/(public)/(polda)/polda/[polda_name]/audio/filter/page.tsx b/app/[locale]/(public)/(polda)/polda/[polda_name]/audio/filter/page.tsx index 8fb5e685..4298d417 100644 --- a/app/[locale]/(public)/(polda)/polda/[polda_name]/audio/filter/page.tsx +++ b/app/[locale]/(public)/(polda)/polda/[polda_name]/audio/filter/page.tsx @@ -120,7 +120,7 @@ const FilterPage = () => { return () => clearTimeout(timer); }, []); - + React.useEffect(() => { const pageFromUrl = searchParams?.get("page"); if (pageFromUrl) { @@ -323,10 +323,11 @@ const FilterPage = () => { let filter = [...categoryFilter]; if (e) { - filter = [...categoryFilter, String(id)]; + filter = [...filter, String(id)]; } else { - filter.splice(categoryFilter.indexOf(id), 1); + filter = filter.filter((item) => item !== String(id)); } + console.log("checkbox filter", filter); setCategoryFilter(filter); router.push(`?category=${filter.join("&")}`); diff --git a/app/[locale]/(public)/(polda)/polda/[polda_name]/document/filter/page.tsx b/app/[locale]/(public)/(polda)/polda/[polda_name]/document/filter/page.tsx index 117bb8e8..3b484445 100644 --- a/app/[locale]/(public)/(polda)/polda/[polda_name]/document/filter/page.tsx +++ b/app/[locale]/(public)/(polda)/polda/[polda_name]/document/filter/page.tsx @@ -320,10 +320,11 @@ const FilterPage = () => { let filter = [...categoryFilter]; if (e) { - filter = [...categoryFilter, String(id)]; + filter = [...filter, String(id)]; } else { - filter.splice(categoryFilter.indexOf(id), 1); + filter = filter.filter((item) => item !== String(id)); } + console.log("checkbox filter", filter); setCategoryFilter(filter); router.push(`?category=${filter.join("&")}`); diff --git a/app/[locale]/(public)/(polda)/polda/[polda_name]/image/filter/page.tsx b/app/[locale]/(public)/(polda)/polda/[polda_name]/image/filter/page.tsx index 83dc2ed7..363729e2 100644 --- a/app/[locale]/(public)/(polda)/polda/[polda_name]/image/filter/page.tsx +++ b/app/[locale]/(public)/(polda)/polda/[polda_name]/image/filter/page.tsx @@ -320,10 +320,11 @@ const FilterPage = () => { let filter = [...categoryFilter]; if (e) { - filter = [...categoryFilter, String(id)]; + filter = [...filter, String(id)]; } else { - filter.splice(categoryFilter.indexOf(id), 1); + filter = filter.filter((item) => item !== String(id)); } + console.log("checkbox filter", filter); setCategoryFilter(filter); router.push(`?category=${filter.join("&")}`); diff --git a/app/[locale]/(public)/(polda)/polda/[polda_name]/video/filter/page.tsx b/app/[locale]/(public)/(polda)/polda/[polda_name]/video/filter/page.tsx index 2ec4e371..39151aea 100644 --- a/app/[locale]/(public)/(polda)/polda/[polda_name]/video/filter/page.tsx +++ b/app/[locale]/(public)/(polda)/polda/[polda_name]/video/filter/page.tsx @@ -314,10 +314,11 @@ const FilterPage = () => { let filter = [...categoryFilter]; if (e) { - filter = [...categoryFilter, String(id)]; + filter = [...filter, String(id)]; } else { - filter.splice(categoryFilter.indexOf(id), 1); + filter = filter.filter((item) => item !== String(id)); } + console.log("checkbox filter", filter); setCategoryFilter(filter); router.push(`?category=${filter.join("&")}`); diff --git a/app/[locale]/(public)/(satker)/satker/[satker_name]/audio/filter/page.tsx b/app/[locale]/(public)/(satker)/satker/[satker_name]/audio/filter/page.tsx index 4368385b..9b47ede1 100644 --- a/app/[locale]/(public)/(satker)/satker/[satker_name]/audio/filter/page.tsx +++ b/app/[locale]/(public)/(satker)/satker/[satker_name]/audio/filter/page.tsx @@ -319,14 +319,15 @@ const FilterPage = () => { } } - const handleCategoryFilter = (e: boolean, id: string) => { + const handleCategoryFilter = (e: boolean, id: string) => { let filter = [...categoryFilter]; if (e) { - filter = [...categoryFilter, String(id)]; + filter = [...filter, String(id)]; } else { - filter.splice(categoryFilter.indexOf(id), 1); + filter = filter.filter((item) => item !== String(id)); } + console.log("checkbox filter", filter); setCategoryFilter(filter); router.push(`?category=${filter.join("&")}`); diff --git a/app/[locale]/(public)/(satker)/satker/[satker_name]/document/filter/page.tsx b/app/[locale]/(public)/(satker)/satker/[satker_name]/document/filter/page.tsx index 8924843b..33e44a2a 100644 --- a/app/[locale]/(public)/(satker)/satker/[satker_name]/document/filter/page.tsx +++ b/app/[locale]/(public)/(satker)/satker/[satker_name]/document/filter/page.tsx @@ -311,10 +311,11 @@ const FilterPage = () => { let filter = [...categoryFilter]; if (e) { - filter = [...categoryFilter, String(id)]; + filter = [...filter, String(id)]; } else { - filter.splice(categoryFilter.indexOf(id), 1); + filter = filter.filter((item) => item !== String(id)); } + console.log("checkbox filter", filter); setCategoryFilter(filter); router.push(`?category=${filter.join("&")}`); diff --git a/app/[locale]/(public)/(satker)/satker/[satker_name]/image/filter/page.tsx b/app/[locale]/(public)/(satker)/satker/[satker_name]/image/filter/page.tsx index 10f42551..cd1e520c 100644 --- a/app/[locale]/(public)/(satker)/satker/[satker_name]/image/filter/page.tsx +++ b/app/[locale]/(public)/(satker)/satker/[satker_name]/image/filter/page.tsx @@ -303,14 +303,15 @@ const FilterPage = () => { } } - const handleCategoryFilter = (e: boolean, id: string) => { + const handleCategoryFilter = (e: boolean, id: string) => { let filter = [...categoryFilter]; if (e) { - filter = [...categoryFilter, String(id)]; + filter = [...filter, String(id)]; } else { - filter.splice(categoryFilter.indexOf(id), 1); + filter = filter.filter((item) => item !== String(id)); } + console.log("checkbox filter", filter); setCategoryFilter(filter); router.push(`?category=${filter.join("&")}`); diff --git a/app/[locale]/(public)/(satker)/satker/[satker_name]/video/filter/page.tsx b/app/[locale]/(public)/(satker)/satker/[satker_name]/video/filter/page.tsx index 457eca01..b027a590 100644 --- a/app/[locale]/(public)/(satker)/satker/[satker_name]/video/filter/page.tsx +++ b/app/[locale]/(public)/(satker)/satker/[satker_name]/video/filter/page.tsx @@ -303,10 +303,11 @@ const FilterPage = () => { let filter = [...categoryFilter]; if (e) { - filter = [...categoryFilter, String(id)]; + filter = [...filter, String(id)]; } else { - filter.splice(categoryFilter.indexOf(id), 1); + filter = filter.filter((item) => item !== String(id)); } + console.log("checkbox filter", filter); setCategoryFilter(filter); router.push(`?category=${filter.join("&")}`); diff --git a/app/[locale]/(public)/audio/filter/page.tsx b/app/[locale]/(public)/audio/filter/page.tsx index 072933cf..6d46df2b 100644 --- a/app/[locale]/(public)/audio/filter/page.tsx +++ b/app/[locale]/(public)/audio/filter/page.tsx @@ -325,10 +325,11 @@ const FilterPage = () => { let filter = [...categoryFilter]; if (e) { - filter = [...categoryFilter, String(id)]; + filter = [...filter, String(id)]; } else { - filter.splice(categoryFilter.indexOf(id), 1); + filter = filter.filter((item) => item !== String(id)); } + console.log("checkbox filter", filter); setCategoryFilter(filter); router.push(`?category=${filter.join("&")}`); diff --git a/app/[locale]/(public)/document/filter/page.tsx b/app/[locale]/(public)/document/filter/page.tsx index e1c994c8..697da859 100644 --- a/app/[locale]/(public)/document/filter/page.tsx +++ b/app/[locale]/(public)/document/filter/page.tsx @@ -326,10 +326,11 @@ const FilterPage = () => { let filter = [...categoryFilter]; if (e) { - filter = [...categoryFilter, String(id)]; + filter = [...filter, String(id)]; } else { - filter.splice(categoryFilter.indexOf(id), 1); + filter = filter.filter((item) => item !== String(id)); } + console.log("checkbox filter", filter); setCategoryFilter(filter); router.push(`?category=${filter.join("&")}`); diff --git a/app/[locale]/(public)/image/filter/page.tsx b/app/[locale]/(public)/image/filter/page.tsx index a3b8ede5..04003030 100644 --- a/app/[locale]/(public)/image/filter/page.tsx +++ b/app/[locale]/(public)/image/filter/page.tsx @@ -102,7 +102,7 @@ const FilterPage = () => { const [isFilterOpen, setIsFilterOpen] = useState(true); const poldaName = params?.polda_name; const satkerName = params?.satker_name; - const [categoryPage, setCategoryPage] = useState(1); + const [categoryPage, setCategoryPage] = useState(1); const [categoryTotalPages, setCategoryTotalPages] = useState(1); // const [startDate, endDate] = dateRange; @@ -217,7 +217,7 @@ const FilterPage = () => { "", isInt, pageNumber - ); + ); const content = response?.data?.data?.content || []; const total = response?.data?.data?.totalPages || 1; @@ -329,10 +329,11 @@ const FilterPage = () => { let filter = [...categoryFilter]; if (e) { - filter = [...categoryFilter, String(id)]; + filter = [...filter, String(id)]; } else { - filter.splice(categoryFilter.indexOf(id), 1); + filter = filter.filter((item) => item !== String(id)); } + console.log("checkbox filter", filter); setCategoryFilter(filter); router.push(`?category=${filter.join("&")}`); diff --git a/app/[locale]/(public)/video/filter/page.tsx b/app/[locale]/(public)/video/filter/page.tsx index 675c6814..424ea2c8 100644 --- a/app/[locale]/(public)/video/filter/page.tsx +++ b/app/[locale]/(public)/video/filter/page.tsx @@ -319,15 +319,16 @@ const FilterPage = () => { let filter = [...categoryFilter]; if (e) { - filter = [...categoryFilter, String(id)]; + filter = [...filter, String(id)]; } else { - filter.splice(categoryFilter.indexOf(id), 1); + filter = filter.filter((item) => item !== String(id)); } + console.log("checkbox filter", filter); setCategoryFilter(filter); router.push(`?category=${filter.join("&")}`); }; - + const handleFormatFilter = (e: boolean, id: string) => { let filter = [...formatFilter]; diff --git a/service/landing/landing.ts b/service/landing/landing.ts index 399a4fe1..f79b7454 100644 --- a/service/landing/landing.ts +++ b/service/landing/landing.ts @@ -63,7 +63,7 @@ export async function getPublicCategoryData( page: number = 1 ) { return await httpGetInterceptor( - `media/categories/list/publish?enablePage=1&size=12&page=${ + `media/categories/list/publish?enablePage=1&size=12&sort=desc&sortBy=createdAt&page=${ page - 1 }&group=${group}&type=${type}&isInt=${isInt}` );