@@ -26,7 +26,7 @@ async function getCurrentKHLTeams(): Promise<TeamInfo> {
2626}
2727
2828async function getFiveVFiveSeasons ( ) : Promise < Array < { name : string ; id : number } > > {
29- return (
29+ const ans = (
3030 ( await get ( `https://snokinghockeyleague.com/api/season/all/0?v=1021270` ) ) as {
3131 seasons : [
3232 {
@@ -39,11 +39,11 @@ async function getFiveVFiveSeasons(): Promise<Array<{ name: string; id: number }
3939 name : x . name ,
4040 id : x . id ,
4141 } ) ) ;
42+ console . log ( { ans } ) ;
43+ return ans ;
4244}
4345
44- async function getFiveVFiveCurrentTeams ( index = 0 ) : Promise < TeamInfo > {
45- const { id, name : seasonName } = ( await getFiveVFiveSeasons ( ) ) [ index ] ;
46-
46+ async function getFiveVFiveCurrentTeams ( { name, id } : { name : string ; id : number } ) : Promise < TeamInfo > {
4747 return (
4848 ( await get ( `http://snokinghockeyleague.com/api/team/list/${ id } /0?v=1021270` ) ) as [
4949 {
@@ -54,7 +54,7 @@ async function getFiveVFiveCurrentTeams(index = 0): Promise<TeamInfo> {
5454 }
5555 ]
5656 ) . map ( ( x ) => ( {
57- name : `5v5: ${ x . name } (${ x . divisionName } - ${ seasonName } )` ,
57+ name : `5v5: ${ x . name } (${ x . divisionName } - ${ name } )` ,
5858 teamId : x . teamId ,
5959 snokingUrl : `https://snokinghockeyleague.com/api/game/list/${ x . seasonId } /0/${ x . teamId } ` ,
6060 isSnoking : true ,
@@ -110,21 +110,15 @@ export async function getCurrentTeams(): Promise<{
110110 }
111111 } ;
112112
113- const seasonData = await Promise . all ( [
114- safelyGetTeams (
115- ( ) => getFiveVFiveCurrentTeams ( ) ,
116- < >
117- < b > SKAHL 5v5</ b > data is not currently available. Please try again later if you require data for that
118- league.
119- </ >
120- ) ,
121- safelyGetTeams (
122- ( ) => getFiveVFiveCurrentTeams ( 1 ) ,
123- < >
124- < b > SKAHL 5v5</ b > data is not currently available. Please try again later if you require data for that
125- league..
126- </ >
127- ) ,
113+ // In the past, this code was clever to try and guess what seasons to show in the dropdown (assuming the last N were relevant)
114+ // As the number of seasons fluctuates (we don't know when playoffs get scheduled, new season type, etc), instead
115+ // we now just show every team that is in a season for this calendar year. This means that we'll at some point have 3 seasons showing
116+ // for the main SKAHL league, but that's less interruptive then new seasons breaking our heuristic.
117+ const currentYear = new Date ( ) . getFullYear ( ) . toString ( ) ;
118+ const allSKAHLTeamsSeasons = await getFiveVFiveSeasons ( ) ;
119+ const allCurrentSKAHLSeasons = allSKAHLTeamsSeasons . filter ( ( season ) => season . name . indexOf ( currentYear ) >= 0 ) ;
120+
121+ const dataForNonSKAHLSite = [
128122 safelyGetTeams (
129123 ( ) => getPondSeasonCurrentTeams ( ) ,
130124 < >
@@ -140,7 +134,19 @@ export async function getCurrentTeams(): Promise<{
140134 later.
141135 </ >
142136 ) ,
143- ] ) ;
137+ ] ;
138+
139+ const dataforSKAHLSite = allCurrentSKAHLSeasons . map ( ( season ) =>
140+ safelyGetTeams (
141+ ( ) => getFiveVFiveCurrentTeams ( season ) ,
142+ < >
143+ < b > { season . name } </ b > data is not currently available. Please try again later if you require data for
144+ that league.
145+ </ >
146+ )
147+ ) ;
148+
149+ const seasonData = await Promise . all ( dataForNonSKAHLSite . concat ( dataforSKAHLSite ) ) ;
144150 return {
145151 teams : seasonData . map ( ( x ) => x . data ) . reduce ( ( a , b ) => a . concat ( b ) ) ,
146152 errors : seasonData . map ( ( x ) => x . error ) . filter ( ( a ) => a != null ) as ReactElement [ ] ,
0 commit comments