Skip to content

Commit

Permalink
fix tab transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
haunv3 committed Sep 25, 2023
1 parent 4beb87b commit b3544e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 55 deletions.
20 changes: 12 additions & 8 deletions src/components/Dashboard/TransactionsCard/TransactionsCard.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, {useState, useEffect, useRef} from "react";
import {NavLink} from "react-router-dom";
import {useTheme} from "@material-ui/core/styles";
import React, { useState, useEffect, useRef } from "react";
import { NavLink } from "react-router-dom";
import { useTheme } from "@material-ui/core/styles";
import useMediaQuery from "@material-ui/core/useMediaQuery";
import {useGet} from "restful-react";
import { useGet } from "restful-react";
import cn from "classnames/bind";
import consts from "src/constants/consts";
import {arraysEqual, calculateBefore, mergeArrays} from "src/helpers/helper";
import {_} from "src/lib/scripts";
import { arraysEqual, calculateBefore, mergeArrays } from "src/helpers/helper";
import { _ } from "src/lib/scripts";
import Pagination from "src/components/common/Pagination";
import NoResult from "src/components/common/NoResult";
import TransactionTable from "src/components/Dashboard/TransactionTable";
Expand Down Expand Up @@ -53,7 +53,7 @@ const TransactionsCard = props => {
path += "&before=" + calculateBefore(totalItemsRef.current, consts.REQUEST.LIMIT, pageId);
}

const {data, loading, error, refetch} = useGet({
const { data, loading, error, refetch } = useGet({
path: path,
resolve: data => {
if (!firstLoadCompleted) {
Expand Down Expand Up @@ -131,7 +131,11 @@ const TransactionsCard = props => {
}
}
}
paginationSection = totalPagesRef.current ? <Pagination pages={totalPagesRef.current} page={pageId} onChange={(e, page) => onPageChange(page)} /> : <></>;
paginationSection = totalPagesRef.current ? (
<Pagination isCustomPaging={true} pages={totalPagesRef.current} page={pageId} onChange={(e, page) => onPageChange(page)} />
) : (
<></>
);

return (
<div className={cx("transactions-card")}>
Expand Down
59 changes: 12 additions & 47 deletions src/containers/TxList/TxList.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const TxList = () => {
const prevDataRef = useRef([]);

let timerIdRef = useRef(null);
let timerTxsRef = useRef(null);

let titleSection;
let tableSection;
Expand All @@ -56,12 +55,6 @@ const TxList = () => {
}
};

const cleanUpTxs = () => {
if (timerTxsRef) {
clearInterval(timerTxsRef.current);
}
};

const onPageChange = page => {
cleanUp();
setFirstLoadCompleted(false);
Expand Down Expand Up @@ -188,61 +181,33 @@ const TxList = () => {
setLoading(true);
if (pending) {
await queryListPending();
return;
}
let before = null,
type = "";
if (data?.paging?.total && !isInterval) {
before = prevOldPage.current < pageId ? data.paging.before : data.paging.after;
type = prevOldPage.current < pageId ? "next" : "previous";
} else {
let before = null,
type = "";
if (data?.paging?.total && !isInterval) {
before = prevOldPage.current < pageId ? data.paging.before : data.paging.after;
type = prevOldPage.current < pageId ? "next" : "previous";
}
await queryList({ before, type });
}
await queryList({ before, type });
} finally {
setTimeout(() => {
setLoading(false);
}, 800);
setLoading(false);
}
};

useEffect(() => {
getListTxs();
}, []);

useEffect(() => {
getListTxs();
if (pageId == 1) {
timerIdRef.current = null;
timerTxsRef.current = setInterval(() => {
if (pageId == 1 || pending) {
timerIdRef.current = setInterval(() => {
getListTxs(true);
}, consts.REQUEST.TIMEOUT);
} else {
cleanUpTxs();
}
return () => {
cleanUpTxs();
};
}, [pageId]);

useEffect(() => {
if (!pending) {
getListTxs(true);
cleanUp();
timerIdRef.current = null;
timerTxsRef.current = setInterval(() => {
getListTxs(true);
}, consts.REQUEST.TIMEOUT);
return;
}
setTableData([]);
clearInterval(timerTxsRef.current);
timerTxsRef.current = null;
timerIdRef.current = setInterval(() => {
getListTxs();
}, consts.REQUEST.TIMEOUT);
return () => {
cleanUp();
};
}, [pending]);
}, [pageId, pending]);

paginationSection = totalPagesRef.current ? (
!pending && <Pagination disabled={loading} isCustomPaging pages={totalPagesRef.current} page={pageId} onChange={(e, page) => onPageChange(page)} />
Expand Down

0 comments on commit b3544e4

Please sign in to comment.