diff --git a/src/routes/event-team.tsx b/src/routes/event-team.tsx index 53873a750..844808e2f 100644 --- a/src/routes/event-team.tsx +++ b/src/routes/event-team.tsx @@ -13,7 +13,7 @@ import { getEventTeamInfo } from '@/api/event-team-info/get-event-team-info' import { css } from '@linaria/core' import { useEventInfo } from '@/cache/event-info/use' import { usePromise } from '@/utils/use-promise' -import { nextIncompleteMatch } from '@/utils/next-incomplete-match' +import { getUpcomingMatches } from '@/utils/upcoming-matches' import { ChartCard } from '@/components/chart' import { useEventMatches } from '@/cache/event-matches/use' import { useSchema } from '@/cache/schema/use' @@ -27,12 +27,7 @@ import { useCurrentTime } from '@/utils/use-current-time' import { saveTeam, useSavedTeams, removeTeam } from '@/api/save-teams' import IconButton from '@/components/icon-button' import { EventTeamInfo } from '@/api/event-team-info' - -const sectionStyle = css` - font-weight: normal; - text-align: center; - font-size: 1.2rem; -` +import { Heading } from '@/components/heading' interface Props { eventKey: string @@ -60,8 +55,6 @@ const queueDuration = 20 * minute const isCurrent = (now: Date) => (match: ProcessedMatchInfo): boolean => { const matchStartTime = match.time if (!matchStartTime) return false - // match starts at 3:04 - // match is current till 3:11 (+7m) const matchEndTime = new Date(matchStartTime.getTime() + matchCycleDuration) return matchStartTime < now && now < matchEndTime } @@ -108,9 +101,6 @@ const guessTeamLocation = ( if (!m.time) return false const matchStartTime = m.time.getTime() - // match starts at 3:04 - // match queueing starts at 2:39 - // verify that 2:39 < now < 3:04 const matchQueueStartTime = matchStartTime - queueDuration return matchQueueStartTime < currentTime && currentTime < matchStartTime }) @@ -121,9 +111,6 @@ const guessTeamLocation = ( if (!m.time) return false const matchStartTime = m.time.getTime() const matchEndTime = matchStartTime + matchCycleDuration - // match started at 3:04 - // match ended at 3:11 (+7m) - // verify that 3:11 < now < 3:21 (+10m) return ( matchEndTime < currentTime && currentTime < matchEndTime + afterMatchDuration @@ -167,7 +154,9 @@ const EventTeam = ({ eventKey, teamNum }: Props) => { compareMatches, ) - const nextMatch = teamMatches && nextIncompleteMatch(teamMatches) + const currentTime = useCurrentTime().getTime() + const upcomingMatches = + teamMatches && getUpcomingMatches(teamMatches, currentTime) const savedTeams = useSavedTeams() const isTeamSaved = savedTeams.some( @@ -195,10 +184,26 @@ const EventTeam = ({ eventKey, teamNum }: Props) => { back={`/events/${eventKey}`} class={eventTeamStyle} > - {nextMatch && ( + {upcomingMatches && upcomingMatches.length > 0 && ( <> -

Next Match

- + Upcoming Matches +
+ {upcomingMatches.map((match) => ( + + ))} +
)} { const matches = useEventMatches(eventKey) const eventInfo = useEventInfo(eventKey) - const newestIncompleteMatch = matches && nextIncompleteMatch(matches) + + const currentTime = useCurrentTime().getTime() + const upcomingMatches = matches + ? getUpcomingMatches(matches, currentTime) + : [] return ( {
- - {newestIncompleteMatch ? 'Next Match' : 'Matches'} - - {newestIncompleteMatch && ( - + {upcomingMatches.length > 0 ? ( + <> + + Upcoming Matches + +
+ {upcomingMatches.map((match) => ( + + ))} +
+ + All Matches + + + ) : ( + + Matches + )} {matches ? ( matches.length > 0 ? ( diff --git a/src/utils/next-incomplete-match.ts b/src/utils/next-incomplete-match.ts deleted file mode 100644 index 77e531ef2..000000000 --- a/src/utils/next-incomplete-match.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { ProcessedMatchInfo } from '@/api/match-info' -import { compareMatches } from './compare-matches' - -export const nextIncompleteMatch = (matches: ProcessedMatchInfo[]) => - matches.reduce((prev, match) => { - // if match is complete, it is not a candidate - if (match.redScore !== undefined) return prev - // nothing to compare against so this one must be the best so far - if (!prev) return match - return compareMatches(prev, match) > 1 ? match : prev - }, null) diff --git a/src/utils/upcoming-matches.ts b/src/utils/upcoming-matches.ts new file mode 100644 index 000000000..0bd8155c9 --- /dev/null +++ b/src/utils/upcoming-matches.ts @@ -0,0 +1,16 @@ +import { ProcessedMatchInfo } from '@/api/match-info' + +const ONE_DAY = 24 * 60 * 60 * 1000 + +/** Return the first three matches of the given set that haven't finished yet (no scores posted) + * and are less than one day past their expected start times. */ +export const getUpcomingMatches = ( + matches: ProcessedMatchInfo[], + currentTime: number, +) => + matches + .filter((match) => match.redScore === undefined) + .filter( + (match) => match.time && match.time.getTime() > currentTime - ONE_DAY, + ) + .slice(0, 3)