페이징
This commit is contained in:
@@ -29,6 +29,7 @@ import {
|
|||||||
useSetFooterMode
|
useSetFooterMode
|
||||||
} from '@/widgets/sub-layout/use-sub-layout';
|
} from '@/widgets/sub-layout/use-sub-layout';
|
||||||
import { EmailBottomSheet } from '@/entities/common/ui/email-bottom-sheet';
|
import { EmailBottomSheet } from '@/entities/common/ui/email-bottom-sheet';
|
||||||
|
import useIntersectionObserver from '@/widgets/intersection-observer';
|
||||||
|
|
||||||
export const AllTransactionListPage = () => {
|
export const AllTransactionListPage = () => {
|
||||||
const { navigate } = useNavigate();
|
const { navigate } = useNavigate();
|
||||||
@@ -36,6 +37,7 @@ export const AllTransactionListPage = () => {
|
|||||||
|
|
||||||
const [serviceCodeOptions, setServiceCodeOptions] = useState<Array<Record<string, any>>>();
|
const [serviceCodeOptions, setServiceCodeOptions] = useState<Array<Record<string, any>>>();
|
||||||
|
|
||||||
|
const [onActionIntersect, setOnActionIntersect] = useState<boolean>(false);
|
||||||
const [sortType, setSortType] = useState<SortTypeKeys>(SortTypeKeys.LATEST);
|
const [sortType, setSortType] = useState<SortTypeKeys>(SortTypeKeys.LATEST);
|
||||||
const [listItems, setListItems] = useState<Array<ListItemProps>>([]);
|
const [listItems, setListItems] = useState<Array<ListItemProps>>([]);
|
||||||
const [filterOn, setFilterOn] = useState<boolean>(false);
|
const [filterOn, setFilterOn] = useState<boolean>(false);
|
||||||
@@ -73,8 +75,26 @@ export const AllTransactionListPage = () => {
|
|||||||
const { mutateAsync: allTransactionList } = useAllTransactionListMutation();
|
const { mutateAsync: allTransactionList } = useAllTransactionListMutation();
|
||||||
const { mutateAsync: allTransactionListSummary } = useAllTransactionListSummaryMutation();
|
const { mutateAsync: allTransactionListSummary } = useAllTransactionListSummaryMutation();
|
||||||
const { mutateAsync: downloadExcel } = useDownloadExcelMutation();
|
const { mutateAsync: downloadExcel } = useDownloadExcelMutation();
|
||||||
|
const onIntersect: IntersectionObserverCallback = (entries: Array<IntersectionObserverEntry>) => {
|
||||||
const callList = () => {
|
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 { setTarget } = useIntersectionObserver({
|
||||||
|
threshold: 1,
|
||||||
|
onIntersect
|
||||||
|
});
|
||||||
|
|
||||||
|
const callList = (type?: string) => {
|
||||||
let listSummaryParams: AllTransactionListSummaryParams = {
|
let listSummaryParams: AllTransactionListSummaryParams = {
|
||||||
moid: moid,
|
moid: moid,
|
||||||
tid: tid,
|
tid: tid,
|
||||||
@@ -101,10 +121,33 @@ export const AllTransactionListPage = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if(type !== 'page' && listParams.page){
|
||||||
|
listParams.page.cursor = null;
|
||||||
|
}
|
||||||
|
|
||||||
allTransactionList(listParams).then((rs: AllTransactionListResponse) => {
|
allTransactionList(listParams).then((rs: AllTransactionListResponse) => {
|
||||||
console.log(rs.content)
|
if(type === 'page'){
|
||||||
setListItems(rs.content);
|
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) => {
|
allTransactionListSummary(listSummaryParams).then((rs: AllTransactionListSummaryResponse) => {
|
||||||
setTotalAmount(rs.totalAmount);
|
setTotalAmount(rs.totalAmount);
|
||||||
@@ -240,7 +283,8 @@ export const AllTransactionListPage = () => {
|
|||||||
<AllTransactionList
|
<AllTransactionList
|
||||||
listItems={ listItems }
|
listItems={ listItems }
|
||||||
transactionCategory={ TransactionCategory.AllTransaction }
|
transactionCategory={ TransactionCategory.AllTransaction }
|
||||||
></AllTransactionList>
|
></AllTransactionList>
|
||||||
|
<div ref={ setTarget }></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
Reference in New Issue
Block a user