Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
inker committed Sep 17, 2023
1 parent 429f440 commit 4317bcc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 7 additions & 6 deletions src/pages/cl/ko/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
shuffle,
} from 'lodash'

import { type FixedArray } from 'model/types'
import type Team from 'model/team/KnockoutTeam'

import usePopup from 'store/usePopup'
Expand All @@ -37,26 +38,26 @@ const createWorker = () =>

interface Props {
season: number,
pots: readonly (readonly Team[])[],
pots: FixedArray<readonly Team[], 2>,
}

interface State {
currentMatchupNum: number,
currentPotNum: number,
possiblePairings: readonly number[] | null,
pots: readonly Team[][],
pots: FixedArray<readonly Team[], 2>,
matchups: readonly [Team, Team][],
}

function getState(initialPots: readonly (readonly Team[])[]): State {
function getState(initialPots: FixedArray<readonly Team[], 2>): State {
const currentPotNum = 1
const currentMatchupNum = 0
const numMatchups = 8
return {
currentMatchupNum,
currentPotNum,
possiblePairings: null,
pots: initialPots.map(pot => shuffle(pot)),
pots: initialPots.map(pot => shuffle(pot) as readonly Team[]) as typeof initialPots,
matchups: Array.from({ length: numMatchups }, () => [] as any),
}
}
Expand Down Expand Up @@ -89,7 +90,7 @@ function CLKO({

const getPossiblePairings = useCallback(
async (
newPots: readonly (readonly Team[])[],
newPots: FixedArray<readonly Team[], 2>,
newMatchups: readonly [Team, Team][],
) => {
try {
Expand All @@ -113,7 +114,7 @@ function CLKO({
const index = possiblePairings ? possiblePairings[i] : i
const selectedTeam = currentPot[index]

const newPots = pots.slice()
const newPots = pots.slice() as typeof pots
newPots[currentPotNum] = newPots[currentPotNum].filter((_, idx) => idx !== index)

const newMatchups = matchups.slice()
Expand Down
13 changes: 7 additions & 6 deletions src/pages/el/ko/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
shuffle,
} from 'lodash'

import { type FixedArray } from 'model/types'
import type Team from 'model/team/KnockoutTeam'

import usePopup from 'store/usePopup'
Expand All @@ -38,26 +39,26 @@ const createWorker = () =>

interface Props {
season: number,
pots: readonly (readonly Team[])[],
pots: FixedArray<readonly Team[], 2>,
}

interface State {
currentMatchupNum: number,
currentPotNum: number,
possiblePairings: readonly number[] | null,
pots: readonly Team[][],
pots: FixedArray<readonly Team[], 2>,
matchups: readonly [Team, Team][],
}

function getState(initialPots: readonly (readonly Team[])[], season: number): State {
function getState(initialPots: FixedArray<readonly Team[], 2>, season: number): State {
const currentPotNum = 1
const currentMatchupNum = 0
const numMatchups = season < 2021 ? 16 : 8
return {
currentMatchupNum,
currentPotNum,
possiblePairings: null,
pots: initialPots.map(pot => shuffle(pot)),
pots: initialPots.map(pot => shuffle(pot) as readonly Team[]) as typeof initialPots,
matchups: Array.from({ length: numMatchups }, () => [] as any),
}
}
Expand Down Expand Up @@ -91,7 +92,7 @@ function ELKO({

const getPossiblePairings = useCallback(
async (
newPots: readonly (readonly Team[])[],
newPots: FixedArray<readonly Team[], 2>,
newMatchups: readonly [Team, Team][],
) => {
try {
Expand All @@ -115,7 +116,7 @@ function ELKO({
const index = possiblePairings ? possiblePairings[i] : i
const selectedTeam = currentPot[index]

const newPots = pots.slice()
const newPots = pots.slice() as typeof pots
newPots[currentPotNum] = newPots[currentPotNum].filter((_, idx) => idx !== index)

const newMatchups = matchups.slice()
Expand Down

0 comments on commit 4317bcc

Please sign in to comment.