From 57856b4222b790b3bfaff6b4ed129a99818ab88b Mon Sep 17 00:00:00 2001 From: Nidboj132 <28981031+Nidboj132@users.noreply.github.com> Date: Fri, 22 Sep 2023 15:58:48 +0200 Subject: added leaderboard (#53) Former-commit-id: cca018d7af153dbeab6689f48293ee58a8c871fe --- frontend/src/components/pages/summary.js | 104 ++++++++++++++++++++++++++++--- 1 file changed, 95 insertions(+), 9 deletions(-) (limited to 'frontend/src/components/pages/summary.js') diff --git a/frontend/src/components/pages/summary.js b/frontend/src/components/pages/summary.js index 276389f..deb5fd2 100644 --- a/frontend/src/components/pages/summary.js +++ b/frontend/src/components/pages/summary.js @@ -7,6 +7,8 @@ import "./summary.css"; import img4 from "../../imgs/4.png" import img5 from "../../imgs/5.png" import img6 from "../../imgs/6.png" +import img12 from "../../imgs/12.png" +import img13 from "../../imgs/13.png" import Modview from "./summary_modview.js" export default function Summary(prop) { @@ -28,7 +30,15 @@ const fakedata={} //for debug // eslint-disable-next-line }, []); - + const [pageNumber, setPageNumber] = React.useState(1); + const [lbData, setLbData] = React.useState(null); + React.useEffect(() => { + fetch(`https://lp.ardapektezol.com/api/v1/maps/${location.pathname.split('/')[2]}/leaderboards?page=${pageNumber}`) + .then(r => r.json()) + .then(d => setLbData(d)) + console.log(lbData) + // eslint-disable-next-line + }, [pageNumber]); @@ -40,6 +50,11 @@ function NavClick() { const btn = document.querySelectorAll("#section2 button.nav-button"); btn.forEach((e) => {e.style.backgroundColor = "#2b2e46"}); btn[navState].style.backgroundColor = "#202232"; + + document.querySelectorAll("section").forEach((e,i)=>i>=2?e.style.display="none":"") + if(navState === 0){document.querySelectorAll(".summary1").forEach((e) => {e.style.display = "grid"});} + if(navState === 1){document.querySelectorAll(".summary2").forEach((e) => {e.style.display = "block"});} + if(navState === 2){document.querySelectorAll(".summary3").forEach((e) => {e.style.display = "block"});} }} @@ -108,7 +123,6 @@ function graph(state) {
)) case 2: // graph - let i = 1 let g = 0 let h = 0 return graph_numbers.map((e,j)=>( @@ -123,11 +137,11 @@ function graph(state) { =h ? "1px dashed white" : "0" }} > - {g==h && graph_score.includes(graph_max-j) ? + {g===h && graph_score.includes(graph_max-j) ? - -
+
@@ -279,7 +315,7 @@ return (
-
+
Difficulty {data.summary.routes.sort((a,b)=>a.category.id - b.category.id)[selectedRun].rating === 0 ? (Very easy):null} @@ -301,7 +337,7 @@ return (
-
+
{data.summary.routes.sort((a,b)=>a.category.id - b.category.id)[selectedRun].showcase!=="" ? @@ -312,9 +348,59 @@ return ( {data.summary.routes.sort((a,b)=>a.category.id - b.category.id)[selectedRun].description} -
+ +
+ + {lbData===null?( +
+

Map is not available for competitive boards.

+
+ ):lbData.data.records.length===0?( +
+

No records found.

+
+ ):( +
+
+ Place + Runner + Portals + Time + Date +
+
+ + + {lbData.data.pagination.current_page}/{lbData.data.pagination.total_pages} + +
+
+
+
+
+ {lbData.data.records.map((r, index) => ( + + {r.placement} + +   {r.user.user_name} + {r.score_count} + + {r.score_time} + { TimeAgo(new Date(r.record_date.replace("T"," ").replace("Z",""))) } + + + + + + ))} + {console.log(lbData.data.records.length)} +
+ )} + ) -- cgit v1.2.3