Skip to content

Commit

Permalink
Fix array sorting (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
evroon authored Nov 26, 2023
1 parent 897aaf8 commit b50e38c
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/brackets/brackets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function getRoundsGridCols(
displaySettings: BracketDisplaySettings
) {
let rounds: React.JSX.Element[] | React.JSX.Element = stageItem.rounds
.sort((r1: any, r2: any) => (r1.name > r2.name ? 1 : 0))
.sort((r1: any, r2: any) => (r1.name > r2.name ? 1 : -1))
.map((round: RoundInterface) => (
<Round
key={round.id}
Expand Down Expand Up @@ -170,7 +170,7 @@ export default function Brackets({
swrStagesResponse.data.data.map((x: StageWithStageItems) => [x.id, x])
);
const rounds = stages_map[selectedStageId].stage_items
.sort((i1: StageItemWithRounds, i2: StageItemWithRounds) => (i1.name > i2.name ? 1 : 0))
.sort((i1: StageItemWithRounds, i2: StageItemWithRounds) => (i1.name > i2.name ? 1 : -1))
.map((stageItem: StageItemWithRounds) =>
getRoundsGridCols(
stageItem,
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/brackets/courts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ function getRoundsGridCols(
tournamentData: TournamentMinimal
) {
return activeRound.matches
.sort((m1, m2) => ((m1.court ? m1.court.name : 'y') > (m2.court ? m2.court.name : 'z') ? 1 : 0))
.sort((m1, m2) =>
(m1.court ? m1.court.name : 'y') > (m2.court ? m2.court.name : 'z') ? 1 : -1
)
.map((match) => (
<Grid.Col sm={6} lg={4} xl={4} key={match.id}>
<Match
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/brackets/round.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export default function Round({
displaySettings: BracketDisplaySettings;
}) {
const matches = round.matches
.sort((m1, m2) => ((m1.court ? m1.court.name : 'y') > (m2.court ? m2.court.name : 'z') ? 1 : 0))
.sort((m1, m2) =>
(m1.court ? m1.court.name : 'y') > (m2.court ? m2.court.name : 'z') ? 1 : -1
)
.filter(
(match: MatchInterface) =>
displaySettings.matchVisibility === 'all' ||
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/builder/builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function StageItemRow({
const stageItemsLookup = getStageItemLookup(swrStagesResponse);

const inputs = stageItem.inputs
.sort((i1, i2) => (i1.slot > i2.slot ? 1 : 0))
.sort((i1, i2) => (i1.slot > i2.slot ? 1 : -1))
.map((input, i) => {
const team = input.team_id ? teamsMap[input.team_id] : null;
const teamStageItem = input.winner_from_stage_item_id
Expand Down Expand Up @@ -141,7 +141,7 @@ function StageColumn({
}

const rows = stage.stage_items
.sort((i1: StageItemWithRounds, i2: StageItemWithRounds) => (i1.name > i2.name ? 1 : 0))
.sort((i1: StageItemWithRounds, i2: StageItemWithRounds) => (i1.name > i2.name ? 1 : -1))
.map((stageItem: StageItemWithRounds) => (
<StageItemRow
key={stageItem.id}
Expand Down Expand Up @@ -223,7 +223,7 @@ export default function Builder({
if (swrStagesResponse.error) return <RequestErrorAlert error={swrStagesResponse.error} />;

const cols = stages
.sort((s1: StageWithStageItems, s2: StageWithStageItems) => (s1.id > s2.id ? 1 : 0))
.sort((s1: StageWithStageItems, s2: StageWithStageItems) => (s1.id > s2.id ? 1 : -1))
.map((stage) => (
<StageColumn
key={stage.id}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/tables/standings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export default function StandingsTable({ swrTeamsResponse }: { swrTeamsResponse:
const maxELOScore = Math.max(...teams.map((team) => team.elo_score));

const rows = teams
.sort((p1: TeamInterface, p2: TeamInterface) => (p1.name < p2.name ? 1 : 0))
.sort((p1: TeamInterface, p2: TeamInterface) => (p1.draws > p2.draws ? 1 : 0))
.sort((p1: TeamInterface, p2: TeamInterface) => (p1.wins > p2.wins ? 1 : 0))
.sort((p1: TeamInterface, p2: TeamInterface) => (p1.name < p2.name ? 1 : -1))
.sort((p1: TeamInterface, p2: TeamInterface) => (p1.draws > p2.draws ? 1 : -1))
.sort((p1: TeamInterface, p2: TeamInterface) => (p1.wins > p2.wins ? 1 : -1))
.sort((p1: TeamInterface, p2: TeamInterface) => sortTableEntries(p1, p2, tableState))
.slice(0, 14)
.map((team, index) => (
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/tables/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const getTableState = (

export function sortTableEntries(r1: any, r2: any, tableState: TableState) {
const order = r1[tableState.sortField] > r2[tableState.sortField];
return (tableState.reversed ? order : !order) ? 1 : 0;
return (tableState.reversed ? order : !order) ? 1 : -1;
}

export function getSortIcon(sorted: boolean, reversed: boolean) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/services/lookups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function getScheduleData(
.sort((m1: MatchInterface, m2: MatchInterface) => {
assert(m1.position_in_schedule != null);
assert(m2.position_in_schedule != null);
return m1.position_in_schedule > m2.position_in_schedule ? 1 : 0 || [];
return m1.position_in_schedule > m2.position_in_schedule ? 1 : -1 || [];
}),
court,
}));
Expand Down

1 comment on commit b50e38c

@vercel
Copy link

@vercel vercel bot commented on b50e38c Nov 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.