upd: realtime

Deskripsi;
- realtime halaman diskusi

No Issues
This commit is contained in:
amel
2024-10-02 10:58:30 +08:00
parent 354f3cbd85
commit 0c525e8bae
2 changed files with 26 additions and 18 deletions

View File

@@ -25,6 +25,7 @@ export default function WrapLayout({ children, role, theme, user }: { children:
}, [role, theme])
useShallowEffect(() => {
console.log(data)
if (data && data.some((i: any) => i.idUserTo == user)) {
setTampilNotif(true)
setTimeout(() => {

View File

@@ -1,14 +1,15 @@
'use client'
import { TEMA } from "@/module/_global";
import { keyWibu, TEMA } from "@/module/_global";
import LayoutModal from "@/module/_global/layout/layout_modal";
import { Avatar, Box, Button, Center, Grid, Group, rem, Text, Textarea } from "@mantine/core";
import { useState } from "react";
import toast from "react-hot-toast";
import { funCreateDiscussion, funGetDiscussionById } from "../lib/api_discussion";
import { useParams, useRouter } from "next/navigation";
import { useShallowEffect } from "@mantine/hooks";
import { funGetProfileByCookies } from "@/module/user/profile/lib/api_profile";
import { useHookstate } from "@hookstate/core";
import { Avatar, Box, Button, Grid, rem, Textarea } from "@mantine/core";
import { useShallowEffect } from "@mantine/hooks";
import { useParams, useRouter } from "next/navigation";
import { useState } from "react";
import toast from "react-hot-toast";
import { useWibuRealtime } from "wibu-realtime";
import { funCreateDiscussion } from "../lib/api_discussion";
export default function FormCreateDiscussion({ id }: { id: string }) {
const [isValModal, setValModal] = useState(false)
@@ -25,22 +26,27 @@ export default function FormCreateDiscussion({ id }: { id: string }) {
desc: "",
idDivision: id
})
const [data, setDataRealtime] = useWibuRealtime({
WIBU_REALTIME_TOKEN: keyWibu,
project: "sdm"
})
async function getData() {
try {
setLoading(true)
const res = await funGetProfileByCookies()
setIMG(`https://wibu-storage.wibudev.com/api/files/${res.data.img}`)
setLoading(false)
setLoading(true)
const res = await funGetProfileByCookies()
setIMG(`https://wibu-storage.wibudev.com/api/files/${res.data.img}`)
setLoading(false)
} catch (error) {
console.error(error);
console.error(error);
} finally {
setLoading(false)
setLoading(false)
}
}
useShallowEffect(() => {
}
useShallowEffect(() => {
getData()
}, [])
}, [])
async function createDiscussion(val: boolean) {
try {
@@ -51,6 +57,7 @@ export default function FormCreateDiscussion({ id }: { id: string }) {
})
if (response.success) {
setDataRealtime(response.notif)
toast.success(response.message)
router.push(`/division/${param.id}/discussion/`)
setValModal(false)
@@ -70,7 +77,7 @@ export default function FormCreateDiscussion({ id }: { id: string }) {
return (
<Box >
<Box p={20} >
<Grid pt={10}>
<Grid pt={10}>
<Grid.Col span={2}>
<Avatar src={img} alt="it's me" size="lg" />
</Grid.Col>