From 8f46be4bf835883c42de4a2e17a02091cbc509c9 Mon Sep 17 00:00:00 2001 From: amel Date: Wed, 9 Oct 2024 16:07:02 +0800 Subject: [PATCH 1/2] upd: notifikasi Deskripsi: - tambah jumlah notifikasi dg variable global No Issues --- src/module/_global/components/wrap_layout.tsx | 5 +++-- src/module/home/index.ts | 4 +++- src/module/home/lib/val_home.ts | 3 +++ src/module/home/ui/header_home.tsx | 14 +++++++++++++- 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 src/module/home/lib/val_home.ts diff --git a/src/module/_global/components/wrap_layout.tsx b/src/module/_global/components/wrap_layout.tsx index 816c315..d0cfdb7 100644 --- a/src/module/_global/components/wrap_layout.tsx +++ b/src/module/_global/components/wrap_layout.tsx @@ -6,6 +6,7 @@ import { useEffect, useState } from "react"; import { useWibuRealtime } from "wibu-realtime"; import NotificationCustome from "./notification_custome"; import { useRouter } from "next/navigation"; +import { globalParamJumlahNotif } from "@/module/home"; export default function WrapLayout({ children, role, theme, user }: { children: React.ReactNode, role: any, theme: any, user: any }) { const router = useRouter() @@ -13,6 +14,7 @@ export default function WrapLayout({ children, role, theme, user }: { children: const tema = useHookstate(TEMA) const notifLoadPage = useHookstate(globalNotifPage) const [tampilNotif, setTampilNotif] = useState(false) + const paramNotif = useHookstate(globalParamJumlahNotif) const [data, setData] = useWibuRealtime({ WIBU_REALTIME_TOKEN: keyWibu, project: "sdm" @@ -27,6 +29,7 @@ export default function WrapLayout({ children, role, theme, user }: { children: useShallowEffect(() => { if (data && data.some((i: any) => i.idUserTo == user)) { setTampilNotif(true) + paramNotif.set(!paramNotif.get()) setTimeout(() => { setTampilNotif(false); }, 4000); @@ -40,7 +43,6 @@ export default function WrapLayout({ children, role, theme, user }: { children: return ( <> - {/* {JSON.stringify(data)} */} { tampilNotif && { '' }} /> } - {children} ); diff --git a/src/module/home/index.ts b/src/module/home/index.ts index ebd8e75..ea9c7e8 100644 --- a/src/module/home/index.ts +++ b/src/module/home/index.ts @@ -1,4 +1,5 @@ import { funGetHome } from "./lib/api_home"; +import { globalParamJumlahNotif } from "./lib/val_home"; import ViewDetailFeature from "./ui/view_detail_feature"; import ViewHome from "./ui/view_home"; import ViewNotification from "./ui/view_notification"; @@ -8,4 +9,5 @@ export { ViewHome } export { ViewDetailFeature } export { ViewSearch } export { ViewNotification } -export { funGetHome } \ No newline at end of file +export { funGetHome } +export { globalParamJumlahNotif } \ No newline at end of file diff --git a/src/module/home/lib/val_home.ts b/src/module/home/lib/val_home.ts new file mode 100644 index 0000000..8bb1e91 --- /dev/null +++ b/src/module/home/lib/val_home.ts @@ -0,0 +1,3 @@ +import { hookstate } from "@hookstate/core"; + +export const globalParamJumlahNotif = hookstate(false) diff --git a/src/module/home/ui/header_home.tsx b/src/module/home/ui/header_home.tsx index d0fadaa..3ccd63a 100644 --- a/src/module/home/ui/header_home.tsx +++ b/src/module/home/ui/header_home.tsx @@ -2,22 +2,26 @@ import { LayoutNavbarHome, TEMA } from "@/module/_global"; import { useHookstate } from "@hookstate/core"; import { ActionIcon, Box, Group, Indicator, Text } from "@mantine/core"; +import { useShallowEffect } from "@mantine/hooks"; import { useRouter } from "next/navigation"; import { useState } from "react"; import toast from "react-hot-toast"; import { HiMagnifyingGlass, HiOutlineBell, HiOutlineUser } from "react-icons/hi2"; import { funGetHome } from "../lib/api_home"; -import { useShallowEffect } from "@mantine/hooks"; +import { globalParamJumlahNotif } from "../lib/val_home"; export default function HeaderHome() { const router = useRouter() const tema = useHookstate(TEMA) const [isDesa, setDesa] = useState("") const [isNotif, setNotif] = useState(0) + const paramNotif = useHookstate(globalParamJumlahNotif) + const [loading, setLoading] = useState(true) const fetchData = async () => { try { + setLoading(true) const response = await funGetHome('?cat=header') if (response.success) { setDesa(response.data.village) @@ -28,6 +32,8 @@ export default function HeaderHome() { } catch (error) { toast.error("Gagal mendapatkan data, coba lagi nanti"); console.error(error); + } finally { + setLoading(false) } }; @@ -36,6 +42,12 @@ export default function HeaderHome() { fetchData(); }, []); + useShallowEffect(() => { + if (!loading) { + setNotif(isNotif + 1) + } + }, [paramNotif.get()]) + return ( From f9ed35813f8a93cd5252fde41226edb75355e9f1 Mon Sep 17 00:00:00 2001 From: amel Date: Wed, 9 Oct 2024 17:34:04 +0800 Subject: [PATCH 2/2] upd: Deskripsi: - button load pada layout No Issues --- src/module/_global/components/wrap_layout.tsx | 10 ++++++++++ src/module/home/ui/view_home.tsx | 8 -------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/module/_global/components/wrap_layout.tsx b/src/module/_global/components/wrap_layout.tsx index d0cfdb7..efead1c 100644 --- a/src/module/_global/components/wrap_layout.tsx +++ b/src/module/_global/components/wrap_layout.tsx @@ -7,6 +7,7 @@ import { useWibuRealtime } from "wibu-realtime"; import NotificationCustome from "./notification_custome"; import { useRouter } from "next/navigation"; import { globalParamJumlahNotif } from "@/module/home"; +import ReloadButtonTop from "./reload_button_top"; export default function WrapLayout({ children, role, theme, user }: { children: React.ReactNode, role: any, theme: any, user: any }) { const router = useRouter() @@ -52,6 +53,15 @@ export default function WrapLayout({ children, role, theme, user }: { children: onClose={() => { '' }} /> } + + {/* { + '' + } + } + title='UPDATE' + /> */} {children} ); diff --git a/src/module/home/ui/view_home.tsx b/src/module/home/ui/view_home.tsx index a91b619..3879290 100644 --- a/src/module/home/ui/view_home.tsx +++ b/src/module/home/ui/view_home.tsx @@ -18,14 +18,6 @@ export default function ViewHome() { return ( <> - {/* { - '' - } - } - title='UPDATE' - /> */}