upd: pengumuman
Deskripsi: - update realtime tambah pengumuman pake yg refresh page No Issues
This commit is contained in:
@@ -5,7 +5,7 @@ import { useShallowEffect } from "@mantine/hooks";
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useWibuRealtime } from "wibu-realtime";
|
import { useWibuRealtime } from "wibu-realtime";
|
||||||
import NotificationCustome from "./notification_custome";
|
import NotificationCustome from "./notification_custome";
|
||||||
import { useRouter } from "next/navigation";
|
import { usePathname, useRouter } from "next/navigation";
|
||||||
import { globalParamJumlahNotif } from "@/module/home";
|
import { globalParamJumlahNotif } from "@/module/home";
|
||||||
import ReloadButtonTop from "./reload_button_top";
|
import ReloadButtonTop from "./reload_button_top";
|
||||||
|
|
||||||
@@ -20,6 +20,8 @@ export default function WrapLayout({ children, role, theme, user }: { children:
|
|||||||
WIBU_REALTIME_TOKEN: keyWibu,
|
WIBU_REALTIME_TOKEN: keyWibu,
|
||||||
project: "sdm"
|
project: "sdm"
|
||||||
})
|
})
|
||||||
|
const path = usePathname()
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
roleLogin.set(role)
|
roleLogin.set(role)
|
||||||
@@ -29,12 +31,19 @@ export default function WrapLayout({ children, role, theme, user }: { children:
|
|||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
if (data && data.some((i: any) => i.idUserTo == user)) {
|
if (data && data.some((i: any) => i.idUserTo == user)) {
|
||||||
|
if (data.some((i: any) => i.category == path.substring(1))) {
|
||||||
|
notifLoadPage.set({
|
||||||
|
category: path.substring(1),
|
||||||
|
load: true
|
||||||
|
})
|
||||||
|
} else {
|
||||||
setTampilNotif(true)
|
setTampilNotif(true)
|
||||||
paramNotif.set(!paramNotif.get())
|
paramNotif.set(!paramNotif.get())
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setTampilNotif(false);
|
setTampilNotif(false);
|
||||||
}, 4000);
|
}, 4000);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}, [data])
|
}, [data])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +1,29 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { currentScroll, globalNotifPage, SkeletonSingle, SkeletonUser, TEMA, WARNA } from '@/module/_global';
|
import { currentScroll, globalNotifPage, ReloadButtonTop, SkeletonUser, TEMA } from '@/module/_global';
|
||||||
import { ActionIcon, Box, Center, Divider, Grid, Group, Spoiler, Stack, Text, TextInput } from '@mantine/core';
|
import { funGetUserByCookies } from '@/module/auth';
|
||||||
import React, { useEffect, useState } from 'react';
|
|
||||||
import { TfiAnnouncement } from "react-icons/tfi";
|
|
||||||
import { HiMagnifyingGlass } from 'react-icons/hi2';
|
|
||||||
import { useRouter, useSearchParams } from 'next/navigation';
|
|
||||||
import { useShallowEffect } from '@mantine/hooks';
|
|
||||||
import { IListDataAnnouncement } from '../lib/type_announcement';
|
|
||||||
import { funGetAllAnnouncement } from '../lib/api_announcement';
|
|
||||||
import toast from 'react-hot-toast';
|
|
||||||
import { useHookstate } from '@hookstate/core';
|
import { useHookstate } from '@hookstate/core';
|
||||||
|
import { ActionIcon, Box, Center, Divider, Grid, Spoiler, Stack, Text, TextInput } from '@mantine/core';
|
||||||
|
import { useShallowEffect } from '@mantine/hooks';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import toast from 'react-hot-toast';
|
||||||
|
import { HiMagnifyingGlass } from 'react-icons/hi2';
|
||||||
|
import { TfiAnnouncement } from "react-icons/tfi";
|
||||||
|
import { funGetAllAnnouncement } from '../lib/api_announcement';
|
||||||
|
import { IListDataAnnouncement } from '../lib/type_announcement';
|
||||||
|
|
||||||
|
|
||||||
export default function ListAnnouncement() {
|
export default function ListAnnouncement() {
|
||||||
const [isData, setIsData] = useState<IListDataAnnouncement[]>([])
|
const [isData, setIsData] = useState<IListDataAnnouncement[]>([])
|
||||||
|
const [user, setUser] = useState('')
|
||||||
const [searchQuery, setSearchQuery] = useState('')
|
const [searchQuery, setSearchQuery] = useState('')
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const tema = useHookstate(TEMA)
|
const tema = useHookstate(TEMA)
|
||||||
const load = useHookstate(globalNotifPage)
|
const notifLoadPage = useHookstate(globalNotifPage)
|
||||||
|
|
||||||
// ini
|
|
||||||
const { value: containerRef } = useHookstate(currentScroll);
|
const { value: containerRef } = useHookstate(currentScroll);
|
||||||
const [isPage, setPage] = useState(1)
|
const [isPage, setPage] = useState(1)
|
||||||
|
const [isRefresh, setRefresh] = useState(false)
|
||||||
|
|
||||||
|
|
||||||
const fetchData = async (loading: boolean) => {
|
const fetchData = async (loading: boolean) => {
|
||||||
@@ -48,7 +49,12 @@ export default function ListAnnouncement() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onSearch(val:string){
|
async function onUser() {
|
||||||
|
const user = await funGetUserByCookies()
|
||||||
|
setUser(String(user.id))
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSearch(val: string) {
|
||||||
setSearchQuery(val)
|
setSearchQuery(val)
|
||||||
setPage(1)
|
setPage(1)
|
||||||
}
|
}
|
||||||
@@ -63,6 +69,11 @@ export default function ListAnnouncement() {
|
|||||||
}, [isPage])
|
}, [isPage])
|
||||||
|
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
onUser()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleScroll = async () => {
|
const handleScroll = async () => {
|
||||||
@@ -84,8 +95,35 @@ export default function ListAnnouncement() {
|
|||||||
};
|
};
|
||||||
}, [containerRef, isPage]);
|
}, [containerRef, isPage]);
|
||||||
|
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
if (notifLoadPage.get().category == 'announcement' && notifLoadPage.get().load == true) {
|
||||||
|
setRefresh(true)
|
||||||
|
}
|
||||||
|
}, [notifLoadPage.get().load])
|
||||||
|
|
||||||
|
function onRefresh() {
|
||||||
|
notifLoadPage.set({
|
||||||
|
category: '',
|
||||||
|
load: false
|
||||||
|
})
|
||||||
|
setRefresh(false)
|
||||||
|
setPage(1)
|
||||||
|
setTimeout(() => {
|
||||||
|
fetchData(true)
|
||||||
|
}, 500)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box p={20}>
|
<Box p={20}>
|
||||||
|
{
|
||||||
|
isRefresh &&
|
||||||
|
<ReloadButtonTop
|
||||||
|
onReload={() => { onRefresh() }}
|
||||||
|
title='UPDATE'
|
||||||
|
/>
|
||||||
|
|
||||||
|
}
|
||||||
<TextInput
|
<TextInput
|
||||||
styles={{
|
styles={{
|
||||||
input: {
|
input: {
|
||||||
|
|||||||
Reference in New Issue
Block a user