페이징
This commit is contained in:
@@ -29,12 +29,14 @@ 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 BillingListPage = () => {
|
||||
const { navigate } = useNavigate();
|
||||
const userMid = useStore.getState().UserStore.mid;
|
||||
const userInfo = useStore((state) => state.UserStore.userInfo);
|
||||
|
||||
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);
|
||||
@@ -62,8 +64,27 @@ export const BillingListPage = () => {
|
||||
|
||||
const { mutateAsync: billingList } = useBillingListMutation();
|
||||
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) => {
|
||||
setOnActionIntersect(false);
|
||||
let listParams: BillingListParams = {
|
||||
mid: mid,
|
||||
searchType: searchType,
|
||||
@@ -80,9 +101,33 @@ export const BillingListPage = () => {
|
||||
...{ sortType: sortType }
|
||||
}
|
||||
};
|
||||
if(type !== 'page' && listParams.page){
|
||||
listParams.page.cursor = null;
|
||||
}
|
||||
|
||||
billingList(listParams).then((rs: BillingListResponse) => {
|
||||
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 }
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -167,7 +212,8 @@ export const BillingListPage = () => {
|
||||
<BillingList
|
||||
listItems={ listItems }
|
||||
transactionCategory={ TransactionCategory.Billing }
|
||||
></BillingList>
|
||||
></BillingList>
|
||||
<div ref={ setTarget }></div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
Reference in New Issue
Block a user