diff --git a/src/figma-make/components/pages/daily-checklist/DailyChecklistContent.tsx b/src/figma-make/components/pages/daily-checklist/DailyChecklistContent.tsx index c7699f47..1a9b4406 100644 --- a/src/figma-make/components/pages/daily-checklist/DailyChecklistContent.tsx +++ b/src/figma-make/components/pages/daily-checklist/DailyChecklistContent.tsx @@ -2,7 +2,16 @@ import * as React from 'react'; import { useState, useEffect } from 'react'; -import { Plus, X, Save, Send, Info, FilePlus, ListChecks } from 'lucide-react'; +import { + Plus, + X, + Save, + Send, + Info, + FilePlus, + ListChecks, + Loader2, +} from 'lucide-react'; import { Card, CardContent } from '@/figma-make/components/base/card'; import { Button } from '@/figma-make/components/base/button'; import { Label } from '@/figma-make/components/base/label'; @@ -86,16 +95,11 @@ export function DailyChecklistContent() { searchParams.get('category') || '' ); - const { options: kandangOptions } = useSelect( - DailyChecklistKandangApi.basePath, - 'id', - 'name', - 'search', - { - page: '1', - limit: '100', - } - ); + const { + options: kandangOptions, + isLoadingMore: isLoadingMoreKandang, + loadMore: loadMoreKandang, + } = useSelect(DailyChecklistKandangApi.basePath, 'id', 'name'); const { data: phases } = useSWR< BaseApiResponse, @@ -168,6 +172,16 @@ export function DailyChecklistContent() { const [documents, setDocuments] = useState([]); const [deletedDocumentIds, setDeletedDocumentIds] = useState([]); + const handleKandangScroll = (e: React.UIEvent) => { + const target = e.target as HTMLDivElement; + + if (target.scrollHeight - target.scrollTop <= target.clientHeight + 10) { + if (!isLoadingMoreKandang) { + loadMoreKandang(); + } + } + }; + // Sync state to URL query params useEffect(() => { const params = new URLSearchParams(searchParams.toString()); @@ -994,7 +1008,7 @@ export function DailyChecklistContent() { > - + {kandangOptions.map((kandang) => ( ))} + + {isLoadingMoreKandang && ( +
+ +
+ )}
diff --git a/src/figma-make/components/pages/list-daily-checklist/ListDailyChecklistContent.tsx b/src/figma-make/components/pages/list-daily-checklist/ListDailyChecklistContent.tsx index f762a565..e6127cf0 100644 --- a/src/figma-make/components/pages/list-daily-checklist/ListDailyChecklistContent.tsx +++ b/src/figma-make/components/pages/list-daily-checklist/ListDailyChecklistContent.tsx @@ -1,7 +1,15 @@ 'use client'; import { useState } from 'react'; -import { Eye, CheckCircle, XCircle, Search, Trash2, Edit } from 'lucide-react'; +import { + Eye, + CheckCircle, + XCircle, + Search, + Trash2, + Edit, + Loader2, +} from 'lucide-react'; import { Card, CardContent } from '@/figma-make/components/base/card'; import { Button } from '@/figma-make/components/base/button'; import { Badge } from '@/figma-make/components/base/badge'; @@ -93,21 +101,25 @@ export function ListDailyChecklistContent() { } ); - const { options: kandangOptions } = useSelect( - DailyChecklistKandangApi.basePath, - 'id', - 'name', - 'search', - { - page: '1', - limit: '100', - } - ); + const { + options: kandangOptions, + isLoadingMore: isLoadingMoreKandang, + loadMore: loadMoreKandang, + } = useSelect(DailyChecklistKandangApi.basePath, 'id', 'name'); const checklistList = isResponseSuccess(checklistListRes) ? checklistListRes.data || [] : []; + const handleKandangScroll = (e: React.UIEvent) => { + const target = e.target as HTMLDivElement; + if (target.scrollHeight - target.scrollTop <= target.clientHeight + 10) { + if (!isLoadingMoreKandang) { + loadMoreKandang(); + } + } + }; + // Modals const [showApproveModal, setShowApproveModal] = useState(false); const [showRejectModal, setShowRejectModal] = useState(false); @@ -490,7 +502,7 @@ export function ListDailyChecklistContent() { > - + Semua Kandang {kandangOptions.map((kandang) => ( ))} + {isLoadingMoreKandang && ( +
+ +
+ )}