Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | 274x 15x 15x 15x 15x 274x 5x 5x | import { CampaignType } from "@common/Campaigns/hooks/useReportMenuActions";
import NiceModal from "@ebay/nice-modal-react";
import { ROWS_PER_PAGE } from "@hooks/common/usePagination";
import { TRANSACTION_INFO_MODAL } from "modals/modal_names";
import { useState } from "react";
export const useIterator = ({ dataLen }: { dataLen: number }) => {
const [selectedRowIdx, setSelectedRowIdx] = useState<any>(-1);
const onChangeSelectedRowItem = (
newIdx: number | string,
currentPage = 1,
isOldList = false,
) => {
setSelectedRowIdx((current: number) => {
if (typeof newIdx === "number") {
return newIdx;
} else {
const a = {
next: 1,
prev: -1,
};
const idx = current + a[newIdx as "next" | "prev"];
if (isOldList) {
if (newIdx === "prev") {
if (currentPage > 1) {
if (current === 0) {
return ROWS_PER_PAGE - 1;
}
} else {
/*
If the current page is 1:
- if is selected the first item of the list and prev is pressed, do nothing
*/
if (current === 0) {
return 0;
}
}
}
if (idx >= ROWS_PER_PAGE) {
return 0;
}
if (newIdx === "next") {
//if there is not more data just do nothing
if (idx > dataLen) {
return current;
}
}
}
return idx;
}
});
};
const onIterator =
(setPage: any, currentPage: number) => (newIdx: number | string) => {
setPage((current: number) => {
/*
If the current page is greater than 1:
- if is selected the first item of the list and prev is pressed, go to previous page and return the index of the last item on the new page
*/
if (current > 1 && selectedRowIdx === 0 && newIdx === "prev") {
return current - 1;
}
if (selectedRowIdx + 1 >= ROWS_PER_PAGE && newIdx === "next") {
return current + 1;
}
return current;
});
onChangeSelectedRowItem(newIdx, currentPage, true);
};
return {
setSelectedRowIdx,
onIterator,
onChangeSelectedRowItem,
selectedRowIdx,
};
};
export const useOnOpenSidePanel = ({
isLoading,
setPageDispatcher,
page,
DMenu,
compaignType,
secondaryAction,
}: {
isLoading: boolean;
setPageDispatcher: any;
page: number;
DMenu: any;
compaignType?: CampaignType;
secondaryAction?: (rowData: any) => void;
}) => {
const onOpenSidePanel = ({
rowData,
setSelectedRow,
isFirst,
isLast,
}: {
rowData: any;
setSelectedRow: any;
isFirst?: boolean;
isLast?: boolean;
}) => {
if (rowData) {
NiceModal.show(TRANSACTION_INFO_MODAL, {
data: rowData,
DMenu: DMenu,
setSelectedRow: setSelectedRow(setPageDispatcher, page),
isFirst,
isLast,
compaignType,
});
secondaryAction && secondaryAction(rowData);
}
};
return {
onOpenSidePanel,
};
};
|