Skip to content

Commit

Permalink
Merge pull request #220 from bruin-tennis-consulting/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Fredenck authored Oct 28, 2024
2 parents d6f6db3 + a1db912 commit 885b394
Show file tree
Hide file tree
Showing 15 changed files with 1,054 additions and 1,034 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll": true, // Auto-fix ESLint issues on save
"source.fixAll.eslint": true // Specific to ESLint
"source.fixAll": "explicit",
"source.fixAll.eslint": "explicit"
},
"prettier.requireConfig": true,
"eslint.format.enable": true,
Expand Down
85 changes: 49 additions & 36 deletions app/(interactive)/match-list/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ import React, { useState } from 'react'
import Link from 'next/link'
import { useMatchData } from '../../components/MatchDataProvider' // Assuming the hook is located in the context folder

const formatMatches = (matches) => {
return matches
.filter((match) => match.version === 'v1') // Filter for version 'v1'
.sort((a, b) => new Date(b.matchDate) - new Date(a.matchDate)) // Sort by matchDate in descending order
}

export default function MatchList() {
const { matches, updateMatch, refresh } = useMatchData()
const [newName, setNewName] = useState('')
// const [newName, setNewName] = useState('')

const formattedMatches = formatMatches(matches)

const handleDelete = async (id) => {
try {
Expand All @@ -30,46 +38,51 @@ export default function MatchList() {
URL.revokeObjectURL(url)
}

const handleRename = async (id) => {
try {
await updateMatch(id, { name: newName })
} catch (error) {
console.error('Error renaming match:', error)
}
}
// const handleRename = async (id) => {
// try {
// await updateMatch(id, { name: newName })
// } catch (error) {
// console.error('Error renaming match:', error)
// }
// }

return (
<div>
<h1>Match List</h1>
{matches.length > 0 ? (
{formattedMatches.length > 0 ? (
<ul>
{matches.map((match) => (
<div key={match.id}>
<li>
<span>
{match.name}
<button onClick={() => handleDelete(match.id)}>Delete</button>
</span>
<span>
<button
onClick={() => handleDownload(match.points, match.id)}
>
Download JSON
</button>
</span>
<br />
<Link href={`/tag-match/${match.id}`}>
<button>Tag Match - Full</button>
</Link>
<Link href={`/timestamp-tagger?videoId=${match.videoId}`}>
<button>Tag Match - Timestamp</button>
</Link>
<br />
<input onChange={(e) => setNewName(e.target.value)} />
<button onClick={() => handleRename(match.id)}>Rename</button>
</li>
</div>
))}
{formattedMatches.map((match) => {
const name = `${match.players.client.firstName} ${match.players.client.lastName} ${match.teams.clientTeam} vs. ${match.players.opponent.firstName} ${match.players.opponent.lastName} ${match.teams.opponentTeam} [${match.id}] `
return (
<div key={match.id}>
<li>
<span>
{name}
<button onClick={() => handleDelete(match.id)}>
Delete
</button>
</span>
<span>
<button
onClick={() => handleDownload(match.pointsJson, match.id)}
>
Download JSON
</button>
</span>
<br />
<Link href={`/tag-match/${match.id}`}>
<button>Tag Match - Full</button>
</Link>
<Link href={`/timestamp-tagger?videoId=${match.videoId}`}>
<button>Tag Match - Timestamp</button>
</Link>
{/* <br />
<input onChange={(e) => setNewName(e.target.value)} />
<button onClick={() => handleRename(match.id)}>Rename</button> */}
</li>
</div>
)
})}
</ul>
) : (
<p>Loading...</p>
Expand Down
13 changes: 6 additions & 7 deletions app/(interactive)/matches/[slug]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ const MatchPage = () => {
const selectedMatch = matches.find((match) => match.id === docId)
if (selectedMatch) {
setMatchData(selectedMatch)

// Set initial bookmarks
const initialBookmarks = selectedMatch.points.filter(
const initialBookmarks = selectedMatch.pointsJson.filter(
(point) => point.bookmarked
)
setBookmarks(initialBookmarks)
Expand All @@ -53,7 +52,7 @@ const MatchPage = () => {
}

const handleBookmark = async (point) => {
const updatedPoints = matchData.points.map((p) => {
const updatedPoints = matchData.pointsJson.map((p) => {
if (p.Name === point.Name) {
return { ...p, bookmarked: !p.bookmarked }
}
Expand Down Expand Up @@ -105,7 +104,7 @@ const MatchPage = () => {
}, [triggerScroll, showPDF])

const returnFilteredPoints = () => {
let filteredPoints = matchData.points
let filteredPoints = matchData.pointsJson
const filterMap = new Map()

filterList.forEach((filter) => {
Expand Down Expand Up @@ -152,7 +151,7 @@ const MatchPage = () => {
}
}

const matchSetScores = matchData ? extractSetScores(matchData.points) : {}
const matchSetScores = matchData ? extractSetScores(matchData.pointsJson) : {}

return (
<div className={styles.container}>
Expand Down Expand Up @@ -269,7 +268,7 @@ const MatchPage = () => {
</div>
<div className={styles.sidecontent}>
<FilterList
pointsData={matchData.points}
pointsData={matchData.pointsJson}
filterList={filterList}
setFilterList={setFilterList}
showPercent={showPercent}
Expand Down Expand Up @@ -348,7 +347,7 @@ const MatchPage = () => {
: styles.toggle_buttona_inactive
}
>
Points
Points Played
</button>
{showPDF ? (
<iframe
Expand Down
39 changes: 17 additions & 22 deletions app/(interactive)/upload-match/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default function UploadMatchForm() {

const { userProfile } = useAuth()

console.log(collections)
useEffect(() => {
const fetchCollectionsAndTeams = async () => {
try {
Expand Down Expand Up @@ -74,7 +73,6 @@ export default function UploadMatchForm() {
const updatePlayerOptions = useCallback(
(formData) => {
const clientPlayers = getPlayersForTeam(formData.clientTeam)
const opponentPlayers = getPlayersForTeam(formData.opponentTeam)

setSchema((prevSchema) => ({
...prevSchema,
Expand All @@ -83,10 +81,6 @@ export default function UploadMatchForm() {
clientPlayer: {
...prevSchema.properties.clientPlayer,
enum: clientPlayers
},
opponentPlayer: {
...prevSchema.properties.opponentPlayer,
enum: opponentPlayers
}
}
}))
Expand Down Expand Up @@ -118,49 +112,50 @@ export default function UploadMatchForm() {
client: {
firstName: formData.clientPlayer.split(' ')[0],
lastName: formData.clientPlayer.split(' ')[1],
UTR: formData.clientUTR
UTR: formData.clientUTR || null
},
opponent: {
firstName: formData.opponentPlayer.split(' ')[0],
lastName: formData.opponentPlayer.split(' ')[1],
UTR: formData.opponentUTR
UTR: formData.opponentUTR || null
}
}
const weather = {
temperature: formData.temperature,
cloudy: formData.weather.includes('Cloudy'),
windy: formData.weather.includes('Windy')
temperature: formData.temperature || null,
cloudy: formData.weather ? formData.weather.includes('Cloudy') : null,
windy: formData.weather ? formData.weather.includes('Windy') : null
}
const matchDetails = {
weather,
division: formData.division,
event: formData.event,
lineup: formData.lineup,
matchVenue: formData.matchVenue,
round: formData.round,
indoor: formData.court === 'Indoor',
surface: formData.surface
weather: weather || null,
division: formData.division || null,
event: formData.event || null,
lineup: formData.lineup || null,
matchVenue: formData.matchVenue || null,
round: formData.round || null,
indoor: formData.court ? formData.court === 'Indoor' : null,
surface: formData.surface || null
}
// const sets = parseMatchScore(formData.matchScore);
const sets = [
formData.matchScore.set1,
formData.matchScore.set2,
...(formData.matchScore.set3 ? formData.matchScore.set3 : [])
formData.matchScore.set3 || {}
]

// Use the createMatch hook to upload the match
await createMatch(formData.collection, {
sets,
videoId: formData.videoID,
pointsJson,
pdfFile: formData.pdfFile,
pdfFile: formData.pdfFile || null,
teams,
players,
matchDate: formData.date,
singles: formData.singlesDoubles === 'Singles',
matchDetails,
searchableProperties,
version: 'v1' // Current version for new matches added
version: 'v1', // Current version for new matches added
published: true
})

alert('Match uploaded successfully!')
Expand Down
32 changes: 14 additions & 18 deletions app/components/DashTileContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,21 @@ const DashTileContainer = ({ matches, matchType, onTileClick }) => {
>
<DashboardTile
matchName={`${match.opponent} ${match.date}`}
clientTeam={match.clientTeam}
opponentTeam={match.opponentTeam}
player1Name={match.clientPlayer}
player2Name={match.opponentPlayer}
player1FinalScores={Object.values(match.matchScore).map(
(set) => ({
score: set ? set.clientGames : null
})
clientTeam={match.teams.clientTeam}
opponentTeam={match.teams.opponentTeam}
player1Name={`${match.players.client.firstName} ${match.players.client.lastName}`}
player2Name={`${match.players.opponent.firstName} ${match.players.opponent.lastName}`}
player1FinalScores={match.sets.map((set) => ({
score: set ? set.clientGames : null
}))}
player2FinalScores={match.sets.map((set) => ({
score: set ? set.opponentGames : null
}))}
player1TieScores={match.sets.map((set) =>
set ? set.clientTiebreak : null
)}
player2FinalScores={Object.values(match.matchScore).map(
(set) => ({
score: set ? set.opponentGames : null
})
)}
player1TieScores={Object.values(match.matchScore).map(
(set) => (set ? set.clientTiebreak : null)
)}
player2TieScores={Object.values(match.matchScore).map(
(set) => (set ? set.opponentTiebreak : null)
player2TieScores={match.sets.map((set) =>
set ? set.opponentTiebreak : null
)}
isUnfinished={false}
isTagged={match.isTagged}
Expand Down
Loading

0 comments on commit 885b394

Please sign in to comment.