Skip to content

Commit

Permalink
Wizualiztor demo
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislawMalinski committed May 28, 2024
1 parent 7187570 commit 9a0e27e
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/elements/Ladder/Ladder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
import { useEffect, useState } from "react"
import { Bracket } from 'react-brackets';
import { Bracket, RoundProps, Seed, SeedItem, SeedTeam, RenderSeedProps } from 'react-brackets';

const CustomSeed = ({seed, breakpoint, roundIndex, seedIndex}) => {
const getColor = (winner, team) => {
if (winner === -1) return 'gray';
if (winner === team.name) return 'green';
return 'red';
}
console.log("seed");
console.log(seed);
return (
<Seed mobileBreakpoint={breakpoint} style={{ fontSize: 12 }}>
<SeedItem>
<div>
<SeedTeam style={{ color: getColor(seed.winner, seed.teams[0]) }}>{seed.teams[0]?.name || '...'}</SeedTeam>
<SeedTeam style={{ color: getColor(seed.winner, seed.teams[1]) }}>{seed.teams[1]?.name || '...'}</SeedTeam>
</div>
</SeedItem>
</Seed>
);
};

const buildRounds = function (json) {
console.log("before")
Expand All @@ -15,7 +35,7 @@ const buildRounds = function (json) {
temp.push({
id: i,
date: new Date().toDateString(),
teams: [{ name: 'Its a me' }, { name: 'Mario ' + i }],
teams: [{}, {}],
});
};
temp = temp.concat(result);
Expand All @@ -24,7 +44,7 @@ const buildRounds = function (json) {
temp.push({
id: i + maxPosition + 1,
date: new Date().toDateString(),
teams: [{ name: 'Its a me' }, { name: 'Luigi ' + i }],
teams: [{}, {}],
});
}

Expand All @@ -43,7 +63,6 @@ const buildRounds = function (json) {
let cursor = -1;
for (let i = result.length - 1; i >= 0 ; i--) {
if (Number.isInteger(Math.log2(i + 2))) {

temp.push([]);
cursor++;
}
Expand Down Expand Up @@ -129,6 +148,9 @@ export default function Ladder({status}){
}, [status]);

return (<>
<Bracket rounds={rounds} rtl={false} mobileBreakpoint={100} />
<Bracket rounds={rounds}
rtl={false}
mobileBreakpoint={100}
renderSeedComponent={CustomSeed}/>
</>)
}

0 comments on commit 9a0e27e

Please sign in to comment.