페이징

This commit is contained in:
focp212@naver.com
2025-10-24 17:40:40 +09:00
parent 8e27c42a2d
commit ff17d01007

View File

@@ -29,6 +29,7 @@ import {
useSetFooterMode
} from '@/widgets/sub-layout/use-sub-layout';
import { EmailBottomSheet } from '@/entities/common/ui/email-bottom-sheet';
import useIntersectionObserver from '@/widgets/intersection-observer';
export const AllTransactionListPage = () => {
const { navigate } = useNavigate();
@@ -36,6 +37,7 @@ export const AllTransactionListPage = () => {
const [serviceCodeOptions, setServiceCodeOptions] = useState<Array<Record<string, any>>>();
const [onActionIntersect, setOnActionIntersect] = useState<boolean>(false);
const [sortType, setSortType] = useState<SortTypeKeys>(SortTypeKeys.LATEST);
const [listItems, setListItems] = useState<Array<ListItemProps>>([]);
const [filterOn, setFilterOn] = useState<boolean>(false);
@@ -73,8 +75,26 @@ export const AllTransactionListPage = () => {
const { mutateAsync: allTransactionList } = useAllTransactionListMutation();
const { mutateAsync: allTransactionListSummary } = useAllTransactionListSummaryMutation();
const { mutateAsync: downloadExcel } = useDownloadExcelMutation();
const onIntersect: IntersectionObserverCallback = (entries: Array<IntersectionObserverEntry>) => {
entries.forEach((entry: IntersectionObserverEntry) => {
if(entry.isIntersecting){
console.log('Element is now intersecting with the root. [' + onActionIntersect + ']');
if(onActionIntersect && !!pageParam.cursor){
callList('page');
}
}
else{
console.log('Element is no longer intersecting with the root.');
}
});
};
const callList = () => {
const { setTarget } = useIntersectionObserver({
threshold: 1,
onIntersect
});
const callList = (type?: string) => {
let listSummaryParams: AllTransactionListSummaryParams = {
moid: moid,
tid: tid,
@@ -101,10 +121,33 @@ export const AllTransactionListPage = () => {
}
}
};
if(type !== 'page' && listParams.page){
listParams.page.cursor = null;
}
allTransactionList(listParams).then((rs: AllTransactionListResponse) => {
console.log(rs.content)
setListItems(rs.content);
if(type === 'page'){
setListItems([
...listItems,
...rs.content
]);
}
else{
setListItems(rs.content);
}
if(rs.hasNext){
setPageParam({
...pageParam,
...{ cursor: rs.nextCursor }
});
setOnActionIntersect(true);
}
else{
setPageParam({
...pageParam,
...{ cursor: null }
});
}
});
allTransactionListSummary(listSummaryParams).then((rs: AllTransactionListSummaryResponse) => {
setTotalAmount(rs.totalAmount);
@@ -241,6 +284,7 @@ export const AllTransactionListPage = () => {
listItems={ listItems }
transactionCategory={ TransactionCategory.AllTransaction }
></AllTransactionList>
<div ref={ setTarget }></div>
</div>
</div>
</main>