Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing "next match" feature #1498

Open
wants to merge 28 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
196ef83
updated comment-card max width
varCepheid Jan 20, 2022
b15c69f
Merge branch 'dev' of https://github.com/Pigmice2733/peregrine-fronte…
varCepheid Jan 21, 2022
3d02bc5
Merge branch 'dev' of https://github.com/Pigmice2733/peregrine-fronte…
varCepheid Feb 8, 2022
09065da
Merge branch 'dev' of https://github.com/Pigmice2733/peregrine-fronte…
varCepheid Apr 7, 2022
dbc3385
changed "next match" to be based on time
varCepheid Apr 8, 2022
1c64487
the problem has been solved, it now shows five matches, in theory two…
ev118 Apr 10, 2022
cd1f954
[WIP] change implementation and fix some CSS bugs
calebeby Apr 16, 2022
68f5247
[WIP] formatting changes on event-team pages. I couldn't test on any …
varCepheid Apr 19, 2022
0dbddee
merge
varCepheid Feb 17, 2023
ba3b4e6
Merge branch 'dev' into fixing-next-match
varCepheid Feb 17, 2023
986f621
testing with manual date/time
varCepheid Feb 17, 2023
9031061
Merge branch 'fixing-next-match' of https://github.com/Pigmice2733/pe…
varCepheid Feb 17, 2023
fb93a3c
same
varCepheid Feb 17, 2023
b56f416
testing changes
varCepheid Feb 17, 2023
b5ca60d
same
varCepheid Feb 17, 2023
0b58f9d
testing is hard
varCepheid Feb 17, 2023
d43b795
removed score check for upcoming matches function
varCepheid Feb 17, 2023
54f2c01
changed time span for upcoming-matches
varCepheid Feb 17, 2023
5a0c320
changed times again
varCepheid Feb 17, 2023
c807a00
more testing for upcoming matches
varCepheid Feb 17, 2023
235dbb5
reverted testing changes
varCepheid Feb 17, 2023
c515dce
removed comments
varCepheid Nov 9, 2023
b6427c6
requested edits
varCepheid Nov 15, 2023
4eef22c
Merge branch 'main' into dev
varCepheid Mar 5, 2024
cebff6b
merge from dev
varCepheid Jul 7, 2024
89d62ce
Merge branch 'dev' into fixing-next-match
varCepheid Jul 7, 2024
81ad391
Revert changes to `package-lock.json`
calebeby Aug 28, 2024
3b8258f
Merge branch 'dev' into fixing-next-match
varCepheid Sep 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions src/routes/event-team.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
})
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -195,10 +184,26 @@ const EventTeam = ({ eventKey, teamNum }: Props) => {
back={`/events/${eventKey}`}
class={eventTeamStyle}
>
{nextMatch && (
{upcomingMatches && upcomingMatches.length > 0 && (
<>
<h2 class={sectionStyle}>Next Match</h2>
<MatchDetailsCard match={nextMatch} eventKey={eventKey} link />
<Heading level={2}>Upcoming Matches</Heading>
varCepheid marked this conversation as resolved.
Show resolved Hide resolved
<div
class={css`
display: grid;
grid-template-columns: 20rem;
justify-self: stretch;
margin-top: ${spacing};
`}
>
{upcomingMatches.map((match) => (
<MatchDetailsCard
key={match.key}
match={match}
eventKey={eventKey}
link
/>
))}
</div>
</>
)}
<EventTeamInfoCard
Expand Down
61 changes: 47 additions & 14 deletions src/routes/event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { useEventInfo } from '@/cache/event-info/use'
import { css } from '@linaria/core'
import { EventInfoCard } from '@/components/event-info-card'
import Button from '@/components/button'
import { nextIncompleteMatch } from '@/utils/next-incomplete-match'
import { getUpcomingMatches } from '@/utils/upcoming-matches'
import { Heading } from '@/components/heading'
import { EventMatches } from '@/components/event-matches'
import Loader from '@/components/loader'
import { useEventMatches } from '@/cache/event-matches/use'
import { useCurrentTime } from '@/utils/use-current-time'
import clsx from 'clsx'

interface Props {
eventKey: string
Expand All @@ -32,8 +34,8 @@ const eventStyle = css`

const sectionStyle = css`
display: grid;
grid-template-columns: auto;
grid-gap: 2.5rem;
grid-template-columns: 1fr;
grid-gap: ${spacing};
`

const headingStyle = css`
Expand All @@ -51,7 +53,11 @@ const noMatchesStyle = css`
const Event = ({ eventKey }: Props) => {
const matches = useEventMatches(eventKey)
const eventInfo = useEventInfo(eventKey)
const newestIncompleteMatch = matches && nextIncompleteMatch(matches)

const currentTime = useCurrentTime().getTime()
const upcomingMatches = matches
? getUpcomingMatches(matches, currentTime)
: []

return (
<Page
Expand All @@ -68,16 +74,43 @@ const Event = ({ eventKey }: Props) => {
</div>

<div class={sectionStyle}>
<Heading level={2} class={headingStyle}>
{newestIncompleteMatch ? 'Next Match' : 'Matches'}
</Heading>
{newestIncompleteMatch && (
<MatchDetailsCard
key={newestIncompleteMatch.key}
match={newestIncompleteMatch}
eventKey={eventKey}
link
/>
{upcomingMatches.length > 0 ? (
<>
<Heading level={2} class={headingStyle}>
Upcoming Matches
</Heading>
<div
class={css`
display: grid;
grid-template-columns: auto;
grid-gap: 1.1rem;
`}
>
{upcomingMatches.map((match) => (
<MatchDetailsCard
key={match.key}
match={match}
eventKey={eventKey}
link
/>
))}
</div>
<Heading
level={2}
class={clsx(
headingStyle,
css`
margin-top: ${spacing};
`,
)}
>
All Matches
</Heading>
</>
) : (
<Heading level={2} class={headingStyle}>
Matches
</Heading>
)}
{matches ? (
matches.length > 0 ? (
Expand Down
1 change: 1 addition & 0 deletions src/utils/clean-field-name.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-warning-comments */
// TODO: Remove once we can handle multiple fields of the same name
export const cleanFieldName = (fieldName: string) =>
fieldName.replace(/\((?:auto|teleop)\)/, '').trim()
1 change: 1 addition & 0 deletions src/utils/move-focus-inside/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const tababblesStr = tabbables.join(',')

export const moveFocusInside = (el: HTMLElement) => {
if (el.matches(tababblesStr)) return el.focus()
// eslint-disable-next-line no-warning-comments
// TODO: Should this handle elements with modified tabindex, like https://github.com/theKashey/focus-lock/blob/master/src/utils/tabOrder.js
const firstFocusableElement = el.querySelector(tababblesStr)
if (firstFocusableElement) (firstFocusableElement as HTMLElement).focus()
Expand Down
11 changes: 0 additions & 11 deletions src/utils/next-incomplete-match.ts

This file was deleted.

16 changes: 16 additions & 0 deletions src/utils/upcoming-matches.ts
Original file line number Diff line number Diff line change
@@ -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)
Loading