diff --git a/src/app/api/forum/route.ts b/src/app/api/forum/route.ts index 9188747e..6c53c6d2 100644 --- a/src/app/api/forum/route.ts +++ b/src/app/api/forum/route.ts @@ -9,9 +9,10 @@ export async function GET(request: Request) { const { searchParams } = new URL(request.url); const page = searchParams.get("page"); const search = searchParams.get("search"); - const takeData = 4 + const takeData = 5; const skipData = Number(page) * takeData - takeData; + if (!page) { fixData = await prisma.forum_Posting.findMany({ orderBy: { diff --git a/src/app_modules/forum/component/button/button_update_beranda.tsx b/src/app_modules/forum/component/button/button_update_beranda.tsx new file mode 100644 index 00000000..2ce88e04 --- /dev/null +++ b/src/app_modules/forum/component/button/button_update_beranda.tsx @@ -0,0 +1,63 @@ +import { AccentColor } from "@/app_modules/_global/color"; +import { clientLogger } from "@/util/clientLogger"; +import { Center, Button } from "@mantine/core"; +import { useState } from "react"; +import { apiGetAllForum } from "../api_fetch_forum"; + +export function ButtonUpdateBeranda({ + countNewPost, + onSetData, + onSetIsNewPost, + onSetCountNewPosting, +}: { + countNewPost: number; + onSetData: (val: any) => void; + onSetIsNewPost: (val: any) => void; + onSetCountNewPosting: (val: any) => void; +}) { + const [isLoading, setIsLoading] = useState(false); + + const handleLoadData = async (isSearch: string) => { + try { + setIsLoading(true); + + const response = await apiGetAllForum({ + page: `1`, + search: isSearch, + }); + + if (response) { + onSetData(response.data); + onSetIsNewPost(false); + setIsLoading(false); + onSetCountNewPosting(0); + } + } catch (error) { + setIsLoading(false); + clientLogger.error("Error get data forum", error); + } finally { + setIsLoading(false); + } + }; + + return ( + <> +
+ +
+ + ); +} diff --git a/src/app_modules/forum/component/card_loader.tsx b/src/app_modules/forum/component/card_loader.tsx deleted file mode 100644 index e3660996..00000000 --- a/src/app_modules/forum/component/card_loader.tsx +++ /dev/null @@ -1,25 +0,0 @@ -"use client"; - -import { Overlay, Center, Loader } from "@mantine/core"; - -export default function ComponentForum_CardLoadingOverlay({ - size, - variant, -}: { - size?: number; - variant?: any; -}) { - return ( - <> - -
- -
-
- - ); -} diff --git a/src/app_modules/forum/component/loading_drawer.tsx b/src/app_modules/forum/component/loading_drawer.tsx deleted file mode 100644 index 3a1a53ac..00000000 --- a/src/app_modules/forum/component/loading_drawer.tsx +++ /dev/null @@ -1,22 +0,0 @@ -"use client"; - -import { Center, Group, LoadingOverlay, Skeleton } from "@mantine/core"; - -export default function ComponentForum_LoadingDrawer() { - const customLoad = ( -
- - {Array(3) - .fill(0) - .map((e, i) => ( - - ))} - -
- ); - return ( - <> - {customLoad} - - ); -} diff --git a/src/app_modules/forum/component/main_component/card_more_button.tsx b/src/app_modules/forum/component/main_component/card_more_button.tsx index a248c564..bda87f56 100644 --- a/src/app_modules/forum/component/main_component/card_more_button.tsx +++ b/src/app_modules/forum/component/main_component/card_more_button.tsx @@ -37,6 +37,7 @@ import { AccentColor, MainColor, } from "@/app_modules/_global/color/color_pallet"; +import { clientLogger } from "@/util/clientLogger"; export default function ComponentForum_BerandaMoreButton({ authorId, @@ -255,11 +256,11 @@ function ButtonDelete({ const [loading, setLoading] = useState(false); async function onDelete() { - setOpenDel(false); - await forum_funDeletePostingById(postingId as any).then(async (res) => { - if (res.status === 200) { - ComponentGlobal_NotifikasiBerhasil(`Postingan Terhapus`, 2000); - setLoading(true); + try { + setLoading(true); + const deleteData = await forum_funDeletePostingById(postingId as any); + if (deleteData.status === 200) { + setOpenDel(false); const cloneData = _.clone(allData); const hapusData = cloneData.filter((e) => e.id !== postingId); @@ -272,10 +273,16 @@ function ButtonDelete({ data: hapusData, }) ); + + ComponentGlobal_NotifikasiBerhasil(`Postingan Terhapus`, 2000); } else { - ComponentGlobal_NotifikasiGagal(res.message); + setLoading(false); + ComponentGlobal_NotifikasiGagal(deleteData.message); } - }); + } catch (error) { + setLoading(false); + clientLogger.error("Error get data forum", error); + } } return ( <> @@ -324,120 +331,132 @@ function ButtonStatus({ const [loading, setLoading] = useState(false); async function onTutupForum() { - setOpenStatus(false); - - const upateStatusClose = await forum_funEditStatusPostingById( - postingId as any, - 2 - ); - if (upateStatusClose.status === 200) { - ComponentGlobal_NotifikasiBerhasil(`Forum Ditutup`, 2000); + try { setLoading(true); - - const cloneData = _.clone(allData); - const loadData = cloneData.map( - (e) => ( - e.id === postingId, - { - ...e, - ForumMaster_StatusPosting: { - id: e.id === postingId ? 2 : e.ForumMaster_StatusPosting.id, - status: - e.id === postingId - ? "Close" - : e.ForumMaster_StatusPosting.status, - }, - } - ) - ); - onLoadData(loadData); - - // - mqtt_client.publish( - "Forum_ganti_status", - JSON.stringify({ - id: postingId, - data: loadData, - }) + const upateStatusClose = await forum_funEditStatusPostingById( + postingId as any, + 2 ); - const findData = cloneData.find((val) => val.id === postingId); - const updateDetail = { - ...findData, - ForumMaster_StatusPosting: { - id: 2, - status: "Close", - }, - }; + if (upateStatusClose.status === 200) { + setOpenStatus(false); + ComponentGlobal_NotifikasiBerhasil(`Forum Ditutup`, 2000); - mqtt_client.publish( - "Forum_detail_ganti_status", - JSON.stringify({ - id: postingId, - data: updateDetail.ForumMaster_StatusPosting, - }) - ); - } else { - ComponentGlobal_NotifikasiGagal(upateStatusClose.message); + const cloneData = _.clone(allData); + const loadData = cloneData.map( + (e) => ( + e.id === postingId, + { + ...e, + ForumMaster_StatusPosting: { + id: e.id === postingId ? 2 : e.ForumMaster_StatusPosting.id, + status: + e.id === postingId + ? "Close" + : e.ForumMaster_StatusPosting.status, + }, + } + ) + ); + onLoadData(loadData); + + // + mqtt_client.publish( + "Forum_ganti_status", + JSON.stringify({ + id: postingId, + data: loadData, + }) + ); + + const findData = cloneData.find((val) => val.id === postingId); + const updateDetail = { + ...findData, + ForumMaster_StatusPosting: { + id: 2, + status: "Close", + }, + }; + + mqtt_client.publish( + "Forum_detail_ganti_status", + JSON.stringify({ + id: postingId, + data: updateDetail.ForumMaster_StatusPosting, + }) + ); + } else { + setLoading(false); + ComponentGlobal_NotifikasiGagal(upateStatusClose.message); + } + } catch (error) { + setLoading(false); + clientLogger.error("Error get data forum", error); } } async function onBukaForum() { - setOpenStatus(false); - - const updateStatusOpen = await forum_funEditStatusPostingById( - postingId as any, - 1 - ); - if (updateStatusOpen.status === 200) { - ComponentGlobal_NotifikasiBerhasil(`Forum Dibuka`, 2000); + try { setLoading(true); - - const cloneData = _.clone(allData); - const loadData = cloneData.map( - (e) => ( - e.id === postingId, - { - ...e, - ForumMaster_StatusPosting: { - id: e.id === postingId ? 1 : e.ForumMaster_StatusPosting.id, - status: - e.id === postingId - ? "Open" - : e.ForumMaster_StatusPosting.status, - }, - } - ) + const updateStatusOpen = await forum_funEditStatusPostingById( + postingId as any, + 1 ); - mqtt_client.publish( - "Forum_ganti_status", - JSON.stringify({ - id: postingId, - data: loadData, - }) - ); + if (updateStatusOpen.status === 200) { + setOpenStatus(false); + ComponentGlobal_NotifikasiBerhasil(`Forum Dibuka`, 2000); - onLoadData(loadData); + const cloneData = _.clone(allData); + const loadData = cloneData.map( + (e) => ( + e.id === postingId, + { + ...e, + ForumMaster_StatusPosting: { + id: e.id === postingId ? 1 : e.ForumMaster_StatusPosting.id, + status: + e.id === postingId + ? "Open" + : e.ForumMaster_StatusPosting.status, + }, + } + ) + ); - const findData = cloneData.find((val) => val.id === postingId); - const updateDetail = { - ...findData, - ForumMaster_StatusPosting: { - id: 1, - status: "Open", - }, - }; + mqtt_client.publish( + "Forum_ganti_status", + JSON.stringify({ + id: postingId, + data: loadData, + }) + ); - mqtt_client.publish( - "Forum_detail_ganti_status", - JSON.stringify({ - id: postingId, - data: updateDetail.ForumMaster_StatusPosting, - }) - ); - } else { - ComponentGlobal_NotifikasiGagal(updateStatusOpen.message); + onLoadData(loadData); + + const findData = cloneData.find((val) => val.id === postingId); + const updateDetail = { + ...findData, + ForumMaster_StatusPosting: { + id: 1, + status: "Open", + }, + }; + + mqtt_client.publish( + "Forum_detail_ganti_status", + JSON.stringify({ + id: postingId, + data: updateDetail.ForumMaster_StatusPosting, + }) + ); + } else { + setLoading(false); + ComponentGlobal_NotifikasiGagal(updateStatusOpen.message); + } + } catch (error) { + setLoading(false); + clientLogger.error("Error get data forum", error); } } @@ -461,7 +480,7 @@ function ButtonStatus({ {statusId === 1 ? ( - - - ); -}