upd: project
Deskripsi: - update scroll page No Issues
This commit is contained in:
@@ -22,6 +22,8 @@ export async function GET(request: Request) {
|
|||||||
const name = searchParams.get('search');
|
const name = searchParams.get('search');
|
||||||
const status = searchParams.get('status');
|
const status = searchParams.get('status');
|
||||||
const idGroup = searchParams.get("group");
|
const idGroup = searchParams.get("group");
|
||||||
|
const page = searchParams.get('page');
|
||||||
|
const dataSkip = Number(page) * 10 - 10;
|
||||||
const villageId = user.idVillage
|
const villageId = user.idVillage
|
||||||
const userId = user.id
|
const userId = user.id
|
||||||
|
|
||||||
@@ -73,6 +75,8 @@ export async function GET(request: Request) {
|
|||||||
|
|
||||||
|
|
||||||
const data = await prisma.project.findMany({
|
const data = await prisma.project.findMany({
|
||||||
|
skip: dataSkip,
|
||||||
|
take: 10,
|
||||||
where: kondisi,
|
where: kondisi,
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
@@ -95,6 +99,11 @@ export async function GET(request: Request) {
|
|||||||
member: v.ProjectMember.length
|
member: v.ProjectMember.length
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
||||||
|
const totalData = await prisma.project.count({
|
||||||
|
where: kondisi
|
||||||
|
})
|
||||||
|
|
||||||
const filter = await prisma.group.findUnique({
|
const filter = await prisma.group.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: grup
|
id: grup
|
||||||
@@ -106,7 +115,7 @@ export async function GET(request: Request) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan kegiatan", data: omitData, filter }, { status: 200 });
|
return NextResponse.json({ success: true, message: "Berhasil mendapatkan kegiatan", data: omitData, filter, total: totalData }, { status: 200 });
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { globalRole, TEMA, WARNA } from '@/module/_global';
|
import { currentScroll, globalRole, TEMA, WARNA } from '@/module/_global';
|
||||||
import { ActionIcon, Avatar, Badge, Box, Card, Center, Divider, Flex, Grid, Group, Skeleton, Text, TextInput, Title } from '@mantine/core';
|
import { ActionIcon, Avatar, Badge, Box, Card, Center, Divider, Flex, Grid, Group, Skeleton, Text, TextInput, Title } from '@mantine/core';
|
||||||
import { useRouter, useSearchParams } from 'next/navigation';
|
import { useRouter, useSearchParams } from 'next/navigation';
|
||||||
import React, { useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { HiMagnifyingGlass, HiMiniPresentationChartBar, HiOutlineListBullet, HiSquares2X2 } from 'react-icons/hi2';
|
import { HiMagnifyingGlass, HiMiniPresentationChartBar, HiOutlineListBullet, HiSquares2X2 } from 'react-icons/hi2';
|
||||||
import { MdAccountCircle } from 'react-icons/md';
|
import { MdAccountCircle } from 'react-icons/md';
|
||||||
import { RiCircleFill } from 'react-icons/ri';
|
import { RiCircleFill } from 'react-icons/ri';
|
||||||
@@ -25,14 +25,29 @@ export default function ListProject() {
|
|||||||
const roleLogin = useHookstate(globalRole)
|
const roleLogin = useHookstate(globalRole)
|
||||||
const [nameGroup, setNameGroup] = useState('')
|
const [nameGroup, setNameGroup] = useState('')
|
||||||
const tema = useHookstate(TEMA)
|
const tema = useHookstate(TEMA)
|
||||||
|
const { value: containerRef } = useHookstate(currentScroll)
|
||||||
|
const [isPage, setPage] = useState(1)
|
||||||
|
const [totalData, setTotalData] = useState(0)
|
||||||
|
const isMobile = useMediaQuery('(max-width: 369px)');
|
||||||
|
const paddingLift = useMediaQuery('(max-width: 505px)')
|
||||||
|
|
||||||
const fetchData = async () => {
|
const handleList = () => {
|
||||||
|
setIsList(!isList)
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchData = async (loading: boolean) => {
|
||||||
try {
|
try {
|
||||||
setLoading(true)
|
if (loading)
|
||||||
const response = await funGetAllProject('?status=' + status + '&search=' + searchQuery + '&group=' + group)
|
setLoading(true)
|
||||||
|
const response = await funGetAllProject('?status=' + status + '&search=' + searchQuery + '&group=' + group + '&page=' + isPage)
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
setData(response?.data)
|
|
||||||
setNameGroup(response.filter.name)
|
setNameGroup(response.filter.name)
|
||||||
|
setTotalData(response.total)
|
||||||
|
if (isPage == 1) {
|
||||||
|
setData(response.data)
|
||||||
|
} else {
|
||||||
|
setData([...isData, ...response.data])
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
toast.error(response.message);
|
toast.error(response.message);
|
||||||
}
|
}
|
||||||
@@ -47,15 +62,35 @@ export default function ListProject() {
|
|||||||
|
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
fetchData();
|
setPage(1)
|
||||||
|
fetchData(true);
|
||||||
}, [status, searchQuery]);
|
}, [status, searchQuery]);
|
||||||
|
|
||||||
const handleList = () => {
|
|
||||||
setIsList(!isList)
|
|
||||||
}
|
|
||||||
const isMobile = useMediaQuery('(max-width: 369px)');
|
|
||||||
|
|
||||||
const paddingLift = useMediaQuery('(max-width: 505px)')
|
useShallowEffect(() => {
|
||||||
|
fetchData(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 + 1 >= scrollHeight) {
|
||||||
|
setPage(isPage + 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const container = containerRef?.current;
|
||||||
|
container?.addEventListener("scroll", handleScroll);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
container?.removeEventListener("scroll", handleScroll);
|
||||||
|
};
|
||||||
|
}, [containerRef, isPage]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box mt={20}>
|
<Box mt={20}>
|
||||||
@@ -97,7 +132,7 @@ export default function ListProject() {
|
|||||||
<Box bg={tema.get().bgTotalKegiatan} p={10} style={{ borderRadius: 10 }}>
|
<Box bg={tema.get().bgTotalKegiatan} p={10} style={{ borderRadius: 10 }}>
|
||||||
<Text fw={'bold'} c={tema.get().utama}>Total Kegiatan</Text>
|
<Text fw={'bold'} c={tema.get().utama}>Total Kegiatan</Text>
|
||||||
<Flex justify={'center'} align={'center'} h={'100%'}>
|
<Flex justify={'center'} align={'center'} h={'100%'}>
|
||||||
<Text fz={40} fw={'bold'} c={tema.get().utama}>{isData.length}</Text>
|
<Text fz={40} fw={'bold'} c={tema.get().utama}>{totalData}</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
</Box>
|
</Box>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user