Use paginate and add index numbers

This commit is contained in:
Marco van Dijk 2022-04-22 11:36:19 +02:00
parent dc18713749
commit 9f7a50d576
3 changed files with 105 additions and 81 deletions

View File

@ -1,13 +1,43 @@
import React from "react"; import React, { useState, useEffect } from 'react';
import ScrollContainer from "react-indiana-drag-scroll"; import ScrollContainer from "react-indiana-drag-scroll";
import Address from "./OrchAddressViewer"; import Address from "./OrchAddressViewer";
import { Pagination } from "@mantine/core";
const itemsPerPage = 10;
const OrchDelegatorViewer = (obj) => { const OrchDelegatorViewer = (obj) => {
const [activePage, setPage] = useState(1);
let delegators = obj.delegators; let delegators = obj.delegators;
let sortedList = [];
if (delegators && delegators.length) { if (delegators && delegators.length) {
let tmpCopy = [...delegators];
while (tmpCopy.length) {
let ticketIdx2 = tmpCopy.length - 1;
let largestIdx = 0;
let largestValue = 0;
// Find current O with most ticket wins in Eth
while (ticketIdx2 >= 0) {
const currentOrch = tmpCopy[ticketIdx2];
let thisVal = currentOrch.bondedAmount;
if (thisVal > largestValue) {
largestIdx = ticketIdx2;
largestValue = thisVal;
}
ticketIdx2 -= 1;
}
// Push current biggest list
sortedList.push(tmpCopy[largestIdx]);
// Remove from list
tmpCopy.splice(largestIdx, 1);
}
const totalPages = (delegators.length + (itemsPerPage - (delegators.length % itemsPerPage))) / itemsPerPage;
return ( return (
<div className="row"> <div className="row">
<div className="strokeSmollLeft fullMargin"> <div className="strokeSmollLeft fullMargin" style={{ paddingBottom: 0, marginBottom: 0 }}>
<div className="row"> <div className="row">
<h3>{delegators.length} Current Delegators</h3> <h3>{delegators.length} Current Delegators</h3>
</div> </div>
@ -15,22 +45,36 @@ const OrchDelegatorViewer = (obj) => {
<ScrollContainer className="overflow-container" hideScrollbars={false} style={{}}> <ScrollContainer className="overflow-container" hideScrollbars={false} style={{}}>
<div className="overflow-content" style={{ cursor: 'grab', maxHeight: '300px' }}> <div className="overflow-content" style={{ cursor: 'grab', maxHeight: '300px' }}>
{ {
delegators.map((delObj, idx) => { sortedList.map((delObj, idx) => {
const tmp = idx - ((activePage - 1) * itemsPerPage);
if (tmp >= 0 && tmp < itemsPerPage) {
return ( return (
<div className="flexContainer forceWrap" key={"delegator" + idx}> <div className="flexContainer forceWrap" key={"delegator" + idx}>
<div className="rowAlignLeft">
<div className="strokeSmollLeft" style={{ marginLeft: '0.2em', whiteSpace: 'nowrap' }} >
<h3>{idx}</h3>
</div>
<div className="rowAlignLeft"> <div className="rowAlignLeft">
<Address address={delObj.id} seed={"delegator" + idx + delObj.id} /> <Address address={delObj.id} seed={"delegator" + idx + delObj.id} />
</div> </div>
</div>
<div className="rowAlignRight"> <div className="rowAlignRight">
<p className="darkText">{parseFloat(delObj.bondedAmount).toFixed(2)} LPT since round {delObj.startRound}</p> <p className="darkText">{parseFloat(delObj.bondedAmount).toFixed(2)} LPT since round {delObj.startRound}</p>
</div> </div>
</div> </div>
) )
}
return null;
}) })
} }
</div> </div>
</ScrollContainer> </ScrollContainer>
</div> </div>
<div className="row" style={{ marginTop: '1em', marginBottom: '1em' }}>
{totalPages > 1 ?
<Pagination page={activePage} onChange={setPage} total={totalPages} siblings={1} initialPage={1} />
: null}
</div>
</div> </div>
</div> </div>
) )

View File

@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { VictoryPie } from 'victory'; import { VictoryPie } from 'victory';
import Winner from '../components/WinnerStat'; import Winner from '../components/WinnerStat';

View File

@ -1,6 +1,7 @@
import React, { useState, useRef } from "react"; import React, { useState, useRef } from "react";
import EventButton from "./eventButton"; import EventButton from "./eventButton";
import ScrollContainer from 'react-indiana-drag-scroll'; import ScrollContainer from 'react-indiana-drag-scroll';
import { Pagination } from "@mantine/core";
import Filter from './filterComponent'; import Filter from './filterComponent';
const thresholdStaking = 0.001; const thresholdStaking = 0.001;
@ -18,8 +19,10 @@ const ticketTransferColour = "rgba(88, 91, 42, 0.3)";
const greyColour = "rgba(122, 128, 127, 0.4)"; const greyColour = "rgba(122, 128, 127, 0.4)";
const defaultIncrementMaxShown = 50; const defaultIncrementMaxShown = 50;
const itemsPerPage = 10;
const EventViewer = (obj) => { const EventViewer = (obj) => {
const [activePage, setPage] = useState(1);
const listInnerRef = useRef(); const listInnerRef = useRef();
const [filterActivated, setFilterActivated] = useState(true); const [filterActivated, setFilterActivated] = useState(true);
const [rewardActivated, setRewardActivated] = useState(true); const [rewardActivated, setRewardActivated] = useState(true);
@ -55,18 +58,6 @@ const EventViewer = (obj) => {
let unbondActivatedColour; let unbondActivatedColour;
unbondActivatedColour = unbondActivated ? unbondColour : greyColour; unbondActivatedColour = unbondActivated ? unbondColour : greyColour;
const updateOnScroll = () => {
if (unfiltered == 0) {
return;
}
if (listInnerRef.current) {
const { scrollTop, scrollHeight, clientHeight } = listInnerRef.current.container.current;
if (scrollTop + clientHeight === scrollHeight) {
obj.setMaxAmount(obj.maxAmount + defaultIncrementMaxShown);
}
}
}
let eventList = []; let eventList = [];
let thisEvent = {}; let thisEvent = {};
let updateEventsIdx = obj.updateEvents.length - 1; let updateEventsIdx = obj.updateEvents.length - 1;
@ -428,8 +419,6 @@ const EventViewer = (obj) => {
console.log("bork"); console.log("bork");
} }
if (unfiltered < obj.maxAmount) {
unfiltered++; unfiltered++;
if (prevBlock === thisEvent.blockNumber) { if (prevBlock === thisEvent.blockNumber) {
eventList.push(<EventButton eventList.push(<EventButton
@ -452,34 +441,6 @@ const EventViewer = (obj) => {
/>); />);
} }
} }
else {
hidden++;
}
}
let showMoreButton;
if (hidden == 0) {
showMoreButton =
<div className="row">
<div className="strokeSmollLeft" style={{ width: '100%' }}>
<p className="row buttonPadding" style={{ borderRadius: "1.2em", backgroundColor: greyColour, maxWidth: '600px' }}>
Reached end of results
</p>
</div>
</div>
} else {
showMoreButton =
<div className="row">
<div className="strokeSmollLeft" style={{ width: '100%' }}>
<button className="row nonHomeButton buttonPadding" style={{ borderRadius: "1.2em", backgroundColor: greyColour, maxWidth: '600px' }}
onClick={() => {
obj.setMaxAmount(obj.maxAmount + defaultIncrementMaxShown);
}}>
<h3>🔄 Show More</h3>
</button>
</div>
</div>
}
let filterBit; let filterBit;
if (obj.showFilter) { if (obj.showFilter) {
@ -499,14 +460,30 @@ const EventViewer = (obj) => {
<div className="row" style={{ width: '100%', height: '100%' }}> <div className="row" style={{ width: '100%', height: '100%' }}>
<div className="stroke roundedOpaque onlyVerticalScroll" style={{ width: '40vw', minWidth: '400px', height: 'calc( 100vh - 50px - 2em)', marginTop: '2em' }}> <div className="stroke roundedOpaque onlyVerticalScroll" style={{ width: '40vw', minWidth: '400px', height: 'calc( 100vh - 50px - 2em)', marginTop: '2em' }}>
<div className="content-wrapper" style={{ width: '100%' }}> <div className="content-wrapper" style={{ width: '100%' }}>
<ScrollContainer activationDistance={1} className="overflow-container" <ScrollContainer activationDistance={1} className="overflow-container" hideScrollbars={false} style={{ width: '100%' }}>
hideScrollbars={false} onEndScroll={updateOnScroll} ref={listInnerRef}> <div className="overflow-content" style={{ cursor: 'grab', padding: 0 }}>
<div className="overflow-content" style={{ cursor: 'grab', paddingTop: 0 }}>
<div className={obj.forceVertical ? "flexContainer forceWrap" : "flexContainer"} > <div className={obj.forceVertical ? "flexContainer forceWrap" : "flexContainer"} >
<div className="verticalDivider" /> <div className="verticalDivider" />
{eventList} {
<div className="verticalDivider" /> eventList.map((delObj, idx) => {
{showMoreButton} const tmp = idx - ((activePage - 1) * itemsPerPage);
if (tmp >= 0 && tmp < itemsPerPage) {
return (
<div className="flexContainer forceWrap" style={{ marginLeft: '0.2em', marginRight: '0.2em', width: '100%' }} key={"ticket-" + idx}>
<div className="rowAlignLeft">
<div className="strokeSmollLeft showNeverOnMobile" style={{ marginLeft: '0.2em', marginRight: '0.2em', whiteSpace: 'nowrap' }} >
<h3>{idx}</h3>
</div>
<div className="row">
{delObj}
</div>
</div>
</div>
)
}
return null;
})
}
<div className="verticalDivider" /> <div className="verticalDivider" />
</div> </div>
</div> </div>
@ -555,6 +532,9 @@ const EventViewer = (obj) => {
</button> </button>
</div> </div>
</div> </div>
<div className="row" style={{ marginTop: '1em', marginBottom: '1em', justifyContent: 'space-evenly', display: "flex" }}>
<Pagination page={activePage} onChange={setPage} total={(limitShown + (itemsPerPage - (limitShown % itemsPerPage))) / itemsPerPage} siblings={3} initialPage={1} />
</div>
</div> </div>
</div> </div>
</div> </div>