fix: diskusi

deskripsi:
-pencarian
- loading pada update status dan hapus diskusi

No Issues
This commit is contained in:
amel
2024-11-04 16:02:45 +08:00
parent 5758d19267
commit 9f8cf53dd8
4 changed files with 62 additions and 33 deletions

View File

@@ -1,16 +1,17 @@
'use client'
import { currentScroll, TEMA } from "@/module/_global";
import { currentScroll, globalNotifPage, ReloadButtonTop, TEMA } from "@/module/_global";
import { useHookstate } from "@hookstate/core";
import { Avatar, Badge, Box, Divider, Flex, Grid, Group, Skeleton, Spoiler, Text, TextInput } from "@mantine/core";
import { useParams, useRouter, useSearchParams } from "next/navigation";
import { useShallowEffect } from "@mantine/hooks";
import _ from "lodash";
import { useParams, useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import toast from "react-hot-toast";
import { GrChatOption } from "react-icons/gr";
import { HiMagnifyingGlass } from "react-icons/hi2";
import { funGetAllDiscussion } from "../lib/api_discussion";
import { useShallowEffect } from "@mantine/hooks";
import { IDataDiscussion } from "../lib/type_discussion";
import toast from "react-hot-toast";
import _ from "lodash";
import { useHookstate } from "@hookstate/core";
export default function ListDiscussion({ id }: { id: string }) {
const [isData, setData] = useState<IDataDiscussion[]>([])
@@ -21,11 +22,12 @@ export default function ListDiscussion({ id }: { id: string }) {
const router = useRouter()
const { value: containerRef } = useHookstate(currentScroll);
const [isPage, setPage] = useState(1)
const notifLoadPage = useHookstate(globalNotifPage)
const [isRefresh, setRefresh] = useState(false)
const getData = async (loading: boolean) => {
try {
if (loading)
setLoading(true)
setLoading(loading)
const response = await funGetAllDiscussion('?division=' + id + '&search=' + searchQuery + '&page=' + isPage)
if (response.success) {
if (isPage == 1) {
@@ -36,7 +38,6 @@ export default function ListDiscussion({ id }: { id: string }) {
} else {
toast.error(response.message)
}
setLoading(false)
} catch (error) {
console.error(error)
} finally {
@@ -75,8 +76,37 @@ export default function ListDiscussion({ id }: { id: string }) {
}, [containerRef, isPage]);
useShallowEffect(() => {
console.log(notifLoadPage.get())
if (notifLoadPage.get().category == 'division/' + param.id + '/discussion' && notifLoadPage.get().load == true) {
setRefresh(true)
}
}, [notifLoadPage.get().load])
function onRefresh() {
notifLoadPage.set({
category: '',
load: false
})
setRefresh(false)
setPage(1)
setTimeout(() => {
getData(false)
}, 500)
}
return (
<Box p={20}>
{
isRefresh &&
<ReloadButtonTop
onReload={() => { onRefresh() }}
title='UPDATE'
/>
}
<TextInput
styles={{
input: {