From c0246943ecd2d7e4791a8e2db01a985d0723b4c0 Mon Sep 17 00:00:00 2001 From: lukman Date: Fri, 20 Sep 2024 17:34:11 +0800 Subject: [PATCH] style : notification --- .../announcement/ui/create_announcement.tsx | 2 +- src/module/home/ui/list_notification.tsx | 323 ++++++++++-------- 2 files changed, 184 insertions(+), 141 deletions(-) diff --git a/src/module/announcement/ui/create_announcement.tsx b/src/module/announcement/ui/create_announcement.tsx index 128f393..4e25c7c 100644 --- a/src/module/announcement/ui/create_announcement.tsx +++ b/src/module/announcement/ui/create_announcement.tsx @@ -144,7 +144,7 @@ export default function CreateAnnouncement() { - + Divisi Terpilih {(memberGroup.length === 0) ? ( Belum ada anggota diff --git a/src/module/home/ui/list_notification.tsx b/src/module/home/ui/list_notification.tsx index be7bfe5..29a4c3e 100644 --- a/src/module/home/ui/list_notification.tsx +++ b/src/module/home/ui/list_notification.tsx @@ -1,112 +1,66 @@ -"use client" -import { currentScroll, TEMA, WARNA } from '@/module/_global'; -import { useHookstate } from '@hookstate/core'; -import { ActionIcon, Box, Center, Flex, Grid, Group, Spoiler, Text } from '@mantine/core'; -import { useMediaQuery, useShallowEffect } from '@mantine/hooks'; -import { useRouter } from 'next/navigation'; -import React, { useEffect, useState } from 'react'; -import { FaBell } from 'react-icons/fa6'; -import { IListNotification } from '../lib/type_notification'; -import { funGetAllNotification, funReadNotification } from '../lib/api_notification'; -import toast from 'react-hot-toast'; - -const dataNotification = [ - { - id: 1, - title: 'Rapat Kamis Kamis Kamis Kamis Kamis Kamis Kamis Kamis ', - description: 'Dipta menambahkan berkas di document dan file. Dipta menambahkan berkas di document dan file Dipta menambahkan berkas di document dan file', - }, - { - id: 2, - title: 'Rapat Jumat', - description: 'Dipta menambahkan berkas di document dan file. Dipta menambahkan berkas di document dan file Dipta menambahkan berkas di document dan file', - }, - { - id: 3, - title: 'Rapat Senin', - description: 'Dipta menambahkan berkas di document dan file. Dipta menambahkan berkas di document dan file Dipta menambahkan berkas di document dan file', - }, - { - id: 4, - title: 'Rapat Selasa', - description: 'Dipta menambahkan berkas di document dan file. Dipta menambahkan berkas di document dan file Dipta menambahkan berkas di document dan file', - }, - { - id: 5, - title: 'Rapat Rabu', - description: 'Dipta menambahkan berkas di document dan file. Dipta menambahkan berkas di document dan file Dipta menambahkan berkas di document dan file', - }, - { - id: 5, - title: 'Rapat Rabu', - description: 'Dipta menambahkan berkas di document dan file. Dipta menambahkan berkas di document dan file Dipta menambahkan berkas di document dan file', - }, - { - id: 5, - title: 'Rapat Rabu', - description: 'Dipta menambahkan berkas di document dan file. Dipta menambahkan berkas di document dan file Dipta menambahkan berkas di document dan file', - }, - { - id: 5, - title: 'Rapat Rabu', - description: 'Dipta menambahkan berkas di document dan file. Dipta menambahkan berkas di document dan file Dipta menambahkan berkas di document dan file', - }, - { - id: 5, - title: 'Rapat Rabu', - description: 'Dipta menambahkan berkas di document dan file. Dipta menambahkan berkas di document dan file Dipta menambahkan berkas di document dan file', - }, - { - id: 5, - title: 'Rapat Rabu', - description: 'Dipta menambahkan berkas di document dan file. Dipta menambahkan berkas di document dan file Dipta menambahkan berkas di document dan file', - }, - { - id: 5, - title: 'Rapat Rabu', - description: 'Dipta menambahkan berkas di document dan file. Dipta menambahkan berkas di document dan file Dipta menambahkan berkas di document dan file', - }, -] +"use client"; +import { currentScroll, TEMA, WARNA } from "@/module/_global"; +import { useHookstate } from "@hookstate/core"; +import { + ActionIcon, + Box, + Center, + Flex, + Grid, + Group, + Skeleton, + Spoiler, + Text, +} from "@mantine/core"; +import { useMediaQuery, useShallowEffect } from "@mantine/hooks"; +import { useRouter } from "next/navigation"; +import React, { useEffect, useState } from "react"; +import { FaBell } from "react-icons/fa6"; +import { IListNotification } from "../lib/type_notification"; +import { + funGetAllNotification, + funReadNotification, +} from "../lib/api_notification"; +import toast from "react-hot-toast"; export default function ListNotification() { - const router = useRouter() - const isMobile = useMediaQuery('(max-width: 369px)') - const [isData, setData] = useState([]) - const tema = useHookstate(TEMA) - const { value: containerRef } = useHookstate(currentScroll) - const [isPage, setPage] = useState(1) - const [loading, setLoading] = useState(true) + const router = useRouter(); + const isMobile = useMediaQuery("(max-width: 369px)"); + const isMobile2 = useMediaQuery("(max-width: 575px)"); + const [isData, setData] = useState([]); + const tema = useHookstate(TEMA); + const { value: containerRef } = useHookstate(currentScroll); + const [isPage, setPage] = useState(1); + const [loading, setLoading] = useState(true); async function fetchData(loading: boolean) { try { - if (loading) - setLoading(true) - const res = await funGetAllNotification('?page=' + isPage) + if (loading) setLoading(true); + const res = await funGetAllNotification("?page=" + isPage); if (res.success) { if (isPage == 1) { - setData(res.data) + setData(res.data); } else { - setData([...isData, ...res.data]) + setData([...isData, ...res.data]); } - } else { - toast.error(res.message) + toast.error(res.message); } } catch (error) { - console.error(error) - toast.error("Gagal memuat data, coba lagi nanti") + console.error(error); + toast.error("Gagal memuat data, coba lagi nanti"); } finally { - setLoading(false) + setLoading(false); } } useShallowEffect(() => { - fetchData(true) - }, []) + fetchData(true); + }, []); useShallowEffect(() => { - fetchData(false) - }, [isPage]) + fetchData(false); + }, [isPage]); useEffect(() => { const handleScroll = async () => { @@ -116,9 +70,8 @@ export default function ListNotification() { const scrollHeight = containerRef.current.scrollHeight; if (scrollTop + containerHeight >= scrollHeight) { - setPage(isPage + 1) + setPage(isPage + 1); } - } }; @@ -129,67 +82,157 @@ export default function ListNotification() { }; }, [containerRef, isPage]); - - - async function onReadNotif(category: string, idContent: string, idData: string) { + async function onReadNotif( + category: string, + idContent: string, + idData: string + ) { try { - const response = await funReadNotification({ id: idData }) + const response = await funReadNotification({ id: idData }); if (response.success) { - router.push(`/${category}/${idContent}`) + router.push(`/${category}/${idContent}`); } else { - toast.error(response.message) + toast.error(response.message); } } catch (error) { - console.error(error) - toast.error("Gagal memuat data, coba lagi nanti") + console.error(error); + toast.error("Gagal memuat data, coba lagi nanti"); } } - - return ( - { - isData.length == 0 ? - - Tidak ada notifikasi - - : - isData.map((v, i) => { - return ( - - { - onReadNotif(v.category, v.idContent, v.id) - }} - > - - - - - ( + + + + )) + ) : ( + + {isData.length == 0 ? ( + + + Tidak ada Notifikasi + + + ) : ( + isData.map((v, i) => { + return ( + + + { + onReadNotif(v.category, v.idContent, v.id); }} > - {v.title} - - - - {v.desc} - + + {/*
*/} + + + + {/*
*/} +
+ + + + + {v.title} + + + + + {v.createdAt} + + + + + + + + + {v.desc} + + +
-
- ) - }) - } - { } + ); + }) + )} +
+ )} + + {}
); } -