-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathSelectSeason.tsx
More file actions
96 lines (83 loc) · 2.39 KB
/
Copy pathSelectSeason.tsx
File metadata and controls
96 lines (83 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import {
useCallback,
memo,
} from 'react'
import {
range,
} from 'lodash'
import type Tournament from 'model/Tournament'
import type Stage from 'model/Stage'
import Select from 'ui/SelectWithHiddenLabel'
import currentSeasonByTournament from '../currentSeasonByTournament'
import seasonAsString from './seasonAsString'
const minSeasons = {
cl: 2002,
el: 2009,
ecl: 2021,
wc: 2018,
}
interface Props {
tournament: Tournament,
stage: Stage,
season: number,
onChange: (tournament: Tournament, stage: Stage, season?: number) => void,
}
const SelectSeason = ({
tournament,
stage,
season,
onChange,
}: Props) => {
const onSeasonChange = useCallback((e: React.ChangeEvent<HTMLSelectElement>) => {
const newSeason = +e.target.value
onChange(tournament, stage, newSeason)
}, [tournament, stage, onChange])
const onTournamentChange = useCallback((e: React.ChangeEvent<HTMLSelectElement>) => {
const newTournament = e.target.value as Tournament
onChange(newTournament, stage, currentSeasonByTournament(newTournament, stage))
}, [stage, onChange])
const onStageChange = useCallback((e: React.ChangeEvent<HTMLSelectElement>) => {
const newStage = e.target.value as Stage
onChange(tournament, newStage, currentSeasonByTournament(tournament, newStage))
}, [tournament, onChange])
const minSeason = minSeasons[tournament]
return (
<div>
<Select
label="tournament"
onChange={onTournamentChange}
value={tournament}
>
<option value="cl">Champions League</option>
<option value="el">Europa League</option>
<option value="ecl">Europa Conference League</option>
<option value="wc">World Cup</option>
</Select>
<Select
label="stage"
onChange={onStageChange}
value={stage}
>
<option value="gs">Group Stage</option>
{tournament !== 'wc' && (
<option value="ko">Knockout Stage</option>
)}
</Select>
<Select
label="season"
onChange={onSeasonChange}
value={season}
>
{range(currentSeasonByTournament(tournament, stage), minSeason - 1, tournament === 'wc' ? -4 : -1).map(i => (
<option
key={i}
value={i}
>
{seasonAsString(tournament, i)}
</option>
))}
</Select>
</div>
)
}
export default memo(SelectSeason)