From 668d8170fa2230524deab65507bd8299ac6522c3 Mon Sep 17 00:00:00 2001 From: Marco van Dijk Date: Fri, 22 Apr 2022 13:33:58 +0200 Subject: [PATCH] Add pages to stats --- src/components/WinnerMonth.js | 139 ++++++++++++++++++++++------------ 1 file changed, 92 insertions(+), 47 deletions(-) diff --git a/src/components/WinnerMonth.js b/src/components/WinnerMonth.js index 0747d69..e367bee 100644 --- a/src/components/WinnerMonth.js +++ b/src/components/WinnerMonth.js @@ -6,6 +6,7 @@ import { getOrchestratorScores } from "../actions/livepeer"; import Ticket from "../components/TicketViewer"; +import { Pagination } from "@mantine/core"; const claimColour = "rgba(25, 158, 29, 0.4)"; const stakeColour = "rgba(25, 158, 147, 0.4)"; @@ -18,9 +19,16 @@ const activationColour = "rgba(154, 158, 25, 0.4)"; const ticketTransferColour = "rgba(88, 91, 42, 0.3)"; const greyColour = "rgba(122, 128, 127, 0.4)"; +const itemsPerPage = 6; + const WinnerMonth = (obj) => { const livepeer = useSelector((state) => state.livepeerstate); const [thisScores, setThisScores] = useState(null); + const [activePage, setPage] = useState(1); + const [activeGraph, setGraph] = useState(1); + + let totalGraphs = 0; + useEffect(() => { const setScore = async () => { @@ -119,6 +127,8 @@ const WinnerMonth = (obj) => { }); } + totalGraphs++; + stakeObj =

Stake Distribution

{ }); } + totalGraphs++; + earningsObj =

Earnings Distribution

{ }); } + totalGraphs++; + broadcasterObj =

Broadcaster Payments

{ } } + const totalPages = (sortedList.length + (itemsPerPage - (sortedList.length % itemsPerPage))) / itemsPerPage; + let renderStake = false; + let renderEarnings = false; + let renderBread = false; + let graphIndex = 1; + if (activeGraph == graphIndex && totalGraphs && stakeObj) { + renderStake = true; + } + graphIndex++; + if (activeGraph == graphIndex && totalGraphs && earningsObj) { + renderEarnings = true; + } + graphIndex++; + if (activeGraph == graphIndex && totalGraphs && broadcasterObj) { + renderBread = true; + } + return (
{obj.data.reactivationCount ? @@ -405,7 +436,7 @@ const WinnerMonth = (obj) => {
: null @@ -415,7 +446,7 @@ const WinnerMonth = (obj) => {
: null} @@ -424,7 +455,7 @@ const WinnerMonth = (obj) => {
: null @@ -434,7 +465,7 @@ const WinnerMonth = (obj) => {
: null @@ -444,7 +475,7 @@ const WinnerMonth = (obj) => {
: null @@ -454,7 +485,7 @@ const WinnerMonth = (obj) => {
: null @@ -464,7 +495,7 @@ const WinnerMonth = (obj) => {
: null @@ -474,7 +505,7 @@ const WinnerMonth = (obj) => {
: null @@ -484,7 +515,7 @@ const WinnerMonth = (obj) => {
: null @@ -504,59 +535,73 @@ const WinnerMonth = (obj) => {
: null }
- {stakeObj} - {earningsObj} - {broadcasterObj} + {renderStake ? stakeObj : null} + {renderEarnings ? earningsObj : null} + {renderBread ? broadcasterObj : null} +
+ {totalGraphs > 1 ? + + : null} +
{ sortedList.map(function (orch, i) { - let thisCommission = null; - let thisStake = null; - let thisEarnings = null; + const tmp = i - ((activePage - 1) * itemsPerPage); + if (tmp >= 0 && tmp < itemsPerPage) { + let thisCommission = null; + let thisStake = null; + let thisEarnings = null; - for (const obj of ticketList) { - if (obj.address == orch.address) { - thisEarnings = obj; + for (const obj of ticketList) { + if (obj.address == orch.address) { + thisEarnings = obj; + } } - } - for (const obj of commissionList) { - if (obj.address == orch.address) { - thisCommission = obj; + for (const obj of commissionList) { + if (obj.address == orch.address) { + thisCommission = obj; + } } - } - for (const obj of stakeList) { - if (obj.address == orch.address) { - thisStake = obj; + for (const obj of stakeList) { + if (obj.address == orch.address) { + thisStake = obj; + } } + let thisScore = null; + if (thisScores && thisScores.scores) { + thisScore = thisScores.scores[orch.address]; + } + return ( +
+ +
+
+ ) } - let thisScore = null; - if (thisScores && thisScores.scores) { - thisScore = thisScores.scores[orch.address]; - } - return ( -
- -
-
- ) + return null; }) } +
+ {totalPages > 1 ? + + : null} +