diff --git a/src/router/index.ts b/src/router/index.ts index b1f6e9f..2e7d0f1 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -27,9 +27,10 @@ export const routes: RouteRecordRaw[] = [ props: castPlayersRouteParams }, { - path: '/standings', + path: '/standings/:seasonNumber', name: 'standings', - component: () => import('../views/StandingsView.vue') + component: () => import('../views/StandingsView.vue'), + props: castStandingsRouteParams }, { path: '/leaderboards', @@ -86,6 +87,12 @@ function castPlayersRouteParams(route: { params: { playerName: string, seasonNum } } +function castStandingsRouteParams(route: { params: { seasonNumber: string } }) { + return { + seasonNumber: Number.isNaN(Number.parseInt(route.params.seasonNumber)) ? undefined : Number(route.params.seasonNumber) + } +} + function castScheduleRouteParams(route: { params: { seasonNumber: string, weekNumber: string } }) { return { seasonNumber: Number.isNaN(Number.parseInt(route.params.seasonNumber)) ? undefined : Number(route.params.seasonNumber), diff --git a/src/views/StandingsView.vue b/src/views/StandingsView.vue index 9520d7c..a235a1d 100644 --- a/src/views/StandingsView.vue +++ b/src/views/StandingsView.vue @@ -8,7 +8,7 @@
-

{{ weekNumber ? `Week ${weekNumber}` : '' }}

+

{{ weekNumber ? `Week ${weekNumber}` : '' }}

@@ -37,6 +37,18 @@ +

+ Standings Archive +

+ + + S{{ season }} + + + +
@@ -56,22 +68,37 @@ export default { }, data() { return { - seasonNumber: CURRENT_SEASON as number, + currentSeason: CURRENT_SEASON, weekNumber: undefined as number | undefined, teamStandings: [] as TeamStanding[], wildcardTeams: [] as TeamStanding[], standingsByDivision: [[]] as TeamStanding[][] } }, + props: { + seasonNumber: { type: Number, default: CURRENT_SEASON } + }, created() { this.fetchData() }, + computed: { + isCurrentSeason(): boolean { + return this.seasonNumber == CURRENT_SEASON + } + }, + watch: { + seasonNumber(newValue, oldValue) { + if (newValue !== oldValue) { + this.fetchData() + } + } + }, methods: { async fetchData(): Promise { const leagueInfo: LeagueInfo = await fetchCurrentLeagueInfo() this.weekNumber = leagueInfo.week - this.teamStandings = await fetchStandings(CURRENT_SEASON) + this.teamStandings = await fetchStandings(this.seasonNumber) this.wildcardTeams = this.teamStandings.filter(ts => ts.isWildcardTeam) const teamStandingsByDivisionAbbreviation: { [key: string]: TeamStanding[] } = {}