upd: notifikasi

Deskripsi:
- tambah jumlah notifikasi dg variable global

No Issues
This commit is contained in:
amel
2024-10-09 16:07:02 +08:00
parent 7a110a9c0c
commit 8f46be4bf8
4 changed files with 22 additions and 4 deletions

View File

@@ -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 }
export { funGetHome }
export { globalParamJumlahNotif }

View File

@@ -0,0 +1,3 @@
import { hookstate } from "@hookstate/core";
export const globalParamJumlahNotif = hookstate<boolean>(false)

View File

@@ -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 (
<LayoutNavbarHome>