페이징

This commit is contained in:
focp212@naver.com
2025-10-24 18:34:21 +09:00
parent ff17d01007
commit 2f13c29d1b
5 changed files with 168 additions and 12 deletions

View File

@@ -16,10 +16,12 @@ import { useVatReturnListMutation } from '../api/use-vat-return-list-mutation';
import { ListDateGroup } from './list-date-group';
import { useStore } from '@/shared/model/store';
import { EmailBottomSheet } from '@/entities/common/ui/email-bottom-sheet';
import useIntersectionObserver from '@/widgets/intersection-observer';
export const ListWrap = () => {
const userMid = useStore.getState().UserStore.mid;
const [onActionIntersect, setOnActionIntersect] = useState<boolean>(false);
const [filterOn, setFilterOn] = useState<boolean>(false);
const [sortType, setSortType] = useState<SortTypeKeys>(SortTypeKeys.LATEST);
const [listItems, setListItems] = useState<Array<VatReturnListContent>>([]);
@@ -33,8 +35,27 @@ export const ListWrap = () => {
const [emailBottomSheetOn, setEmailBottomSheetOn] = useState<boolean>(false);
const { mutateAsync: vatReturnList } = useVatReturnListMutation();
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) => {
setOnActionIntersect(false);
let params: VatReturnListParams = {
mid: mid,
startMonth: startMonth,
@@ -48,7 +69,28 @@ export const ListWrap = () => {
};
vatReturnList(params).then((rs: VatReturnListResponse) => {
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 }
});
}
});
};
@@ -152,7 +194,8 @@ export const ListWrap = () => {
></SortTypeBox>
</div>
<div className="transaction-list">
{ getListDateGroup() }
{ getListDateGroup() }
<div ref={ setTarget }></div>
</div>
<ListFilter
filterOn={ filterOn }