upd: diskusi
Deskripsi: - load scroll deskripsi No Issues
This commit is contained in:
@@ -18,6 +18,8 @@ export async function GET(request: Request) {
|
|||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const idDivision = searchParams.get("division");
|
const idDivision = searchParams.get("division");
|
||||||
const name = searchParams.get('search');
|
const name = searchParams.get('search');
|
||||||
|
const page = searchParams.get('page');
|
||||||
|
const dataSkip = Number(page) * 10 - 10;
|
||||||
|
|
||||||
|
|
||||||
if (idDivision != "null" && idDivision != null && idDivision != undefined) {
|
if (idDivision != "null" && idDivision != null && idDivision != undefined) {
|
||||||
@@ -33,6 +35,8 @@ export async function GET(request: Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = await prisma.divisionDisscussion.findMany({
|
const data = await prisma.divisionDisscussion.findMany({
|
||||||
|
skip: dataSkip,
|
||||||
|
take: 10,
|
||||||
where: {
|
where: {
|
||||||
isActive: true,
|
isActive: true,
|
||||||
idDivision: idDivision,
|
idDivision: idDivision,
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export async function GET(request: Request) {
|
|||||||
const divisi = searchParams.get('division');
|
const divisi = searchParams.get('division');
|
||||||
const status = searchParams.get('status');
|
const status = searchParams.get('status');
|
||||||
const page = searchParams.get('page');
|
const page = searchParams.get('page');
|
||||||
const dataSkip = Number(page) * 3 - 3;
|
const dataSkip = Number(page) * 10 - 10;
|
||||||
|
|
||||||
const cek = await prisma.division.count({
|
const cek = await prisma.division.count({
|
||||||
where: {
|
where: {
|
||||||
@@ -36,7 +36,7 @@ export async function GET(request: Request) {
|
|||||||
|
|
||||||
const data = await prisma.divisionProject.findMany({
|
const data = await prisma.divisionProject.findMany({
|
||||||
skip: dataSkip,
|
skip: dataSkip,
|
||||||
take: 3,
|
take: 10,
|
||||||
where: {
|
where: {
|
||||||
isActive: true,
|
isActive: true,
|
||||||
idDivision: String(divisi),
|
idDivision: String(divisi),
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { TEMA } from "@/module/_global";
|
import { currentScroll, TEMA } from "@/module/_global";
|
||||||
import { Avatar, Badge, Box, Divider, Flex, Grid, Group, Skeleton, Spoiler, Text, TextInput } from "@mantine/core";
|
import { Avatar, Badge, Box, Divider, Flex, Grid, Group, Skeleton, Spoiler, Text, TextInput } from "@mantine/core";
|
||||||
import { useParams, useRouter, useSearchParams } from "next/navigation";
|
import { useParams, useRouter, useSearchParams } from "next/navigation";
|
||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { GrChatOption } from "react-icons/gr";
|
import { GrChatOption } from "react-icons/gr";
|
||||||
import { HiMagnifyingGlass } from "react-icons/hi2";
|
import { HiMagnifyingGlass } from "react-icons/hi2";
|
||||||
import { funGetAllDiscussion } from "../lib/api_discussion";
|
import { funGetAllDiscussion } from "../lib/api_discussion";
|
||||||
@@ -18,15 +18,21 @@ export default function ListDiscussion({ id }: { id: string }) {
|
|||||||
const param = useParams<{ id: string }>()
|
const param = useParams<{ id: string }>()
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const tema = useHookstate(TEMA)
|
const tema = useHookstate(TEMA)
|
||||||
|
const router = useRouter()
|
||||||
|
const { value: containerRef } = useHookstate(currentScroll);
|
||||||
|
const [isPage, setPage] = useState(1)
|
||||||
|
|
||||||
const getData = async () => {
|
const getData = async (loading: boolean) => {
|
||||||
try {
|
try {
|
||||||
setLoading(true)
|
if (loading)
|
||||||
const response = await funGetAllDiscussion('?division=' + id + '&search=' + searchQuery)
|
setLoading(true)
|
||||||
if (
|
const response = await funGetAllDiscussion('?division=' + id + '&search=' + searchQuery + '&page=' + isPage)
|
||||||
response.success
|
if (response.success) {
|
||||||
) {
|
if (isPage == 1) {
|
||||||
setData(response.data)
|
setData(response.data)
|
||||||
|
} else {
|
||||||
|
setData([...isData, ...response.data])
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
toast.error(response.message)
|
toast.error(response.message)
|
||||||
}
|
}
|
||||||
@@ -39,10 +45,36 @@ export default function ListDiscussion({ id }: { id: string }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
getData()
|
setPage(1)
|
||||||
|
getData(true)
|
||||||
}, [searchQuery])
|
}, [searchQuery])
|
||||||
|
|
||||||
const router = useRouter()
|
useShallowEffect(() => {
|
||||||
|
getData(false)
|
||||||
|
}, [isPage])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleScroll = async () => {
|
||||||
|
if (containerRef && containerRef.current) {
|
||||||
|
const scrollTop = containerRef.current.scrollTop;
|
||||||
|
const containerHeight = containerRef.current.clientHeight;
|
||||||
|
const scrollHeight = containerRef.current.scrollHeight;
|
||||||
|
|
||||||
|
if (scrollTop + containerHeight >= scrollHeight) {
|
||||||
|
setPage(isPage + 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const container = containerRef?.current;
|
||||||
|
container?.addEventListener("scroll", handleScroll);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
container?.removeEventListener("scroll", handleScroll);
|
||||||
|
};
|
||||||
|
}, [containerRef, isPage]);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box p={20}>
|
<Box p={20}>
|
||||||
<TextInput
|
<TextInput
|
||||||
|
|||||||
Reference in New Issue
Block a user