Skip to content

Commit

Permalink
remove old upload match
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredenck committed Nov 14, 2024
1 parent fe9016f commit b37bf65
Showing 1 changed file with 1 addition and 66 deletions.
67 changes: 1 addition & 66 deletions app/services/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,71 +11,6 @@ import {
} from 'firebase/firestore'
import { ref, uploadBytes, getDownloadURL } from 'firebase/storage' // Import storage functions
import { db, storage } from '../services/initializeFirebase.js' // Ensure storage is exported from initializeFirebase.js
import { useData } from '../components/DataProvider.js' // Import the hook

async function useUploadMatch(
sets,
videoId,
pointsJson,
pdfFile,
teams,
players,
matchDate,
singles,
matchDetails,
collectionName
) {
// Use the createMatch function from the useMatchData hook
const { createMatch } = useData()
if (
!sets ||
!videoId ||
!teams ||
!players ||
!matchDate ||
!singles ||
!matchDetails ||
!collectionName
) {
console.error('All fields are required.')
return // Exit the function if any field is empty
}

try {
let pdfUrl = null
if (pdfFile) {
// First, upload the PDF to Firebase Storage
const pdfRef = ref(storage, `match-pdfs/${pdfFile.name}`)
const snapshot = await uploadBytes(pdfRef, pdfFile)
pdfUrl = await getDownloadURL(snapshot.ref)
}

// untagged matches
let published = true
if (pointsJson === null) published = false

// matchName: P1 T1 vs. P2 T2
const matchName = `${players.client.firstName} ${players.client.lastName} ${teams.clientTeam} vs. ${players.opponent.firstName} ${players.opponent.lastName} ${teams.opponentTeam}`

await createMatch(collectionName, {
name: matchName,
videoId,
sets,
pdfUrl,
matchDate,
teams,
players,
published,
singles,
matchDetails,
points: pointsJson || []
})

console.log('Match Document uploaded successfully.')
} catch (e) {
console.error('Error uploading Match Document: ', e)
}
}

async function uploadTeam(teamName, logoFile) {
if (!teamName || !logoFile) {
Expand Down Expand Up @@ -179,4 +114,4 @@ async function uploadPlayer(
}
}

export { useUploadMatch, uploadTeam, uploadPlayer }
export { uploadTeam, uploadPlayer }

0 comments on commit b37bf65

Please sign in to comment.