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

create links to adjacent matches #1540

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
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
120 changes: 112 additions & 8 deletions src/routes/event-match.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,21 @@ import { cleanYoutubeUrl } from '@/utils/clean-youtube-url'
import { MatchReports } from '@/components/match-reports'
import { getReports } from '@/api/report/get-reports'
import Icon from '@/components/icon'
import { mdiCloudOffOutline, mdiPlus } from '@mdi/js'
import {
mdiArrowLeft,
mdiArrowRight,
mdiCloudOffOutline,
mdiPlus,
} from '@mdi/js'
import { createShadow } from '@/utils/create-shadow'
import {
ConnectionType,
useNetworkConnection,
} from '@/utils/use-network-connection'
import { useEventMatches } from '@/cache/event-matches/use'
import { compareMatches } from '@/utils/compare-matches'
import { route } from '@/router'
import IconButton from '@/components/icon-button'

interface Props {
eventKey: string
Expand Down Expand Up @@ -58,12 +67,14 @@ const loadedMatchStyle = css`
display: grid;
grid-template-columns: 1fr auto 1fr;
grid-template-areas:
'matchLinks matchLinks matchLinks'
'. leftColumn .'
'analysisTable analysisTable analysisTable';
padding: 0.75rem;
@media (max-width: 930px) {
grid-template-columns: 1fr;
grid-template-areas:
'matchLinks'
'leftColumn'
'analysisTable';
}
Expand All @@ -76,11 +87,13 @@ const matchWithVideoStyle = css`
grid-template-columns: 1fr auto 30rem 1fr;
align-items: start;
grid-template-areas:
'matchLinks matchLinks matchLinks matchLinks'
'. leftColumn rightColumn .'
'analysisTable analysisTable analysisTable analysisTable';
@media (max-width: 930px) {
grid-template-columns: 1fr;
grid-template-areas:
'matchLinks'
'leftColumn'
'analysisTable'
'rightColumn';
Expand Down Expand Up @@ -112,6 +125,15 @@ const offlineDisplayInfo = css`
}
`

const matchLinksStyle = css`
display: grid;
font-weight: bold;
grid-area: matchLinks;
grid-template-columns: 2.5em 20em auto 20em 2.5em;
align-items: center;
justify-items: center;
`

const showMatchResults = 'Match Results'
const showEventResults = 'Event Results'

Expand All @@ -123,7 +145,6 @@ const EventMatch = ({ eventKey, matchKey }: Props) => {
const netConn = useNetworkConnection()
const isOnline = netConn !== ConnectionType.Offline

const m = formatMatchKey(matchKey)
const event = useEventInfo(eventKey)
const match = useMatchInfo(eventKey, matchKey)
const reports = usePromise(() => {
Expand Down Expand Up @@ -160,16 +181,47 @@ const EventMatch = ({ eventKey, matchKey }: Props) => {
}
}, [match, isOnline])

const sortedMatches = useEventMatches(eventKey)?.sort(compareMatches)
let previousMatch:
| {
redAlliance: string[]
blueAlliance: string[]
time?: Date | undefined
key: string
videos?: string[] | null | undefined
redScore?: number | undefined
blueScore?: number | undefined
scheduledTime?: Date | undefined
}
| undefined,
nextMatch:
| {
redAlliance: string[]
blueAlliance: string[]
time?: Date | undefined
key: string
videos?: string[] | null | undefined
redScore?: number | undefined
blueScore?: number | undefined
scheduledTime?: Date | undefined
}
| undefined
const matchIndex = sortedMatches?.findIndex((m) => m.key === matchKey)
if (matchIndex || matchIndex === 0) {
previousMatch = sortedMatches ? sortedMatches[matchIndex - 1] : undefined
nextMatch = sortedMatches ? sortedMatches[matchIndex + 1] : undefined
}

const getMatchName = (key: string) => {
const props = formatMatchKey(key)
return props.group + (props.num ? ' Match ' + props.num : '')
}

return (
// page setup
<Page
back={`/events/${eventKey}`}
name={
m.group +
(m.num ? ' Match ' + m.num : '') +
' - ' +
(event ? event.name : eventKey)
}
name={getMatchName(matchKey) + ' - ' + (event ? event.name : eventKey)}
class={clsx(
matchStyle,
match && loadedMatchStyle,
Expand All @@ -181,6 +233,58 @@ const EventMatch = ({ eventKey, matchKey }: Props) => {
>
{match ? (
<>
<div class={matchLinksStyle}>
{previousMatch && (
<>
<IconButton
icon={mdiArrowLeft}
aria-label="Previous Match"
onClick={() =>
route(`/events/${eventKey}/matches/${previousMatch?.key}`)
}
class={css`
grid-row: 1;
grid-column: 1;
justify-self: start;
`}
/>
<span
class={css`
grid-row: 1;
grid-column: 2;
justify-self: start;
`}
>
Previous Match: {getMatchName(previousMatch.key)}
</span>
</>
)}
{nextMatch && (
<>
<span
class={css`
grid-row: 1;
grid-column: 4;
justify-self: end;
`}
>
Next Match: {getMatchName(nextMatch.key)}
</span>
<IconButton
icon={mdiArrowRight}
aria-label="Next Match"
onClick={() =>
route(`/events/${eventKey}/matches/${nextMatch?.key}`)
}
class={css`
grid-row: 1;
grid-column: 5;
justify-self: end;
`}
/>
</>
)}
</div>
<div class={leftColumnStyle}>
{!isOnline && (
<Card class={offlineDisplayInfo}>
Expand Down
Loading