Skip to content

Commit

Permalink
pools: Sort teams on adding to pool
Browse files Browse the repository at this point in the history
  • Loading branch information
SibiAkkash committed Nov 7, 2023
1 parent 77a3a72 commit c867f25
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions frontend/src/components/tournament/CreatePools.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { createStore } from "solid-js/store";
const allTeamsName = "All";

/**
*
* @param {object} props
* @param {object} props.team
* @param {int} props.team.seed
Expand All @@ -28,7 +27,6 @@ const TeamInfo = props => (
);

/**
*
* @param {object} props
* @param {{seed: int, name: str}} props.team
*/
Expand Down Expand Up @@ -135,22 +133,26 @@ const CreatePools = props => {
setPools(draggableStartPool(), teams =>
teams.filter(team => team.seed !== draggable.id)
);
setPools(droppable.id, teams => [...teams, draggedTeam()]);
// its easier to look at the pools if the teams are sorted by seed
setPools(droppable.id, teams =>
[...teams, draggedTeam()].sort((a, b) => a.seed - b.seed)
);
});
}
};

const removePool = droppableId => {
batch(() => {
setPools(allTeamsName, teams => [...teams, ...pools[droppableId]]);
setPools(allTeamsName, teams =>
[...teams, ...pools[droppableId]].sort((a, b) => a.seed - b.seed)
);
// setting value undefined to delete it from the store
setPools(droppableId, undefined);
});
};

const addPool = poolName => {
console.log("creating pool", poolName);
if (Object.keys(pools).includes(poolName)) {
if (!poolName || Object.keys(pools).includes(poolName)) {
return;
}
setPools(poolName, []);
Expand Down Expand Up @@ -194,7 +196,7 @@ const CreatePools = props => {
</div>

<For each={Object.entries(pools)}>
{([poolName, teams], _) => (
{([poolName, teams]) => (
<Show when={poolName !== allTeamsName}>
<div class="row-span-1 col-span-1">
<Droppable
Expand Down

0 comments on commit c867f25

Please sign in to comment.