Skip to content

Commit 79e4fca

Browse files
authored
Merge pull request #372 from bruin-tennis-consulting/369-feature-integrate-d3js-from-analytics-into-site
369 feature integrate d3js from analytics into site
2 parents 6a53f3f + 4a121b7 commit 79e4fca

5 files changed

Lines changed: 70 additions & 25 deletions

File tree

app/DataProvider.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,25 @@ export const DataProvider = ({ children }) => {
121121
const createMatch = useCallback(
122122
async (collectionName, newMatchData) => {
123123
try {
124-
let pdfUrl = null
125-
if (newMatchData.pdfFile) {
126-
const pdfRef = ref(storage, `match-pdfs/${newMatchData.pdfFile.name}`)
124+
let htmlUrl = null
125+
if (newMatchData.htmlFile) {
126+
const htmlRef = ref(
127+
storage,
128+
`match-html/${newMatchData.htmlFile.name}`
129+
)
127130
const metadata = {
128-
contentType: 'application/pdf'
131+
contentType: 'text/html'
129132
}
130133

131134
const snapshot = await uploadBytes(
132-
pdfRef,
133-
newMatchData.pdfFile.blob,
135+
htmlRef,
136+
newMatchData.htmlFile.blob,
134137
metadata
135138
)
136-
pdfUrl = await getDownloadURL(snapshot.ref)
139+
htmlUrl = await getDownloadURL(snapshot.ref)
137140
}
138-
console.log(pdfUrl)
139-
newMatchData.pdfFile = pdfUrl
141+
console.log(htmlUrl)
142+
newMatchData.htmlFile = htmlUrl
140143
newMatchData._deleted = false
141144

142145
const newMatch = {

app/matches/[slug]/page.js

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ const MatchPage = ({ params }) => {
4646
const [showPercent, setShowPercent] = useState(false)
4747
const [showCount, setShowCount] = useState(false)
4848
const [playingPoint, setPlayingPoint] = useState(null)
49-
const [showPDF, setShowPDF] = useState(true)
49+
const [showHTML, setShowHTML] = useState(false)
50+
const [showPDF, setShowPDF] = useState(false)
5051
const [tab, setTab] = useState(1)
5152
const [bookmarks, setBookmarks] = useState([])
5253
const [triggerScroll, setTriggerScroll] = useState(false)
@@ -113,6 +114,20 @@ const MatchPage = ({ params }) => {
113114
}
114115
}, [matches, params.slug, fetchMatchDetails])
115116

117+
// Set showHTML/showPDF based on available files (prioritize HTML, fallback to PDF)
118+
useEffect(() => {
119+
if (matchData?.htmlFile != null) {
120+
setShowHTML(true)
121+
setShowPDF(false)
122+
} else if (matchData?.pdfFile != null) {
123+
setShowHTML(false)
124+
setShowPDF(true)
125+
} else {
126+
setShowHTML(false)
127+
setShowPDF(false)
128+
}
129+
}, [matchData])
130+
116131
const handleJumpToTime = (time) => {
117132
if (videoObject && videoObject.seekTo) {
118133
videoObject.seekTo(time / 1000, true)
@@ -221,13 +236,13 @@ const MatchPage = ({ params }) => {
221236
}, [videoObject, matchData, returnFilteredPoints])
222237

223238
useEffect(() => {
224-
if (triggerScroll && !showPDF) {
239+
if (triggerScroll && !showHTML && !showPDF) {
225240
if (tableRef.current) {
226241
tableRef.current.scrollIntoView({ behavior: 'smooth' })
227242
}
228243
setTriggerScroll(false)
229244
}
230-
}, [triggerScroll, showPDF])
245+
}, [triggerScroll, showHTML, showPDF])
231246

232247
const removeFilter = (key, value) => {
233248
const updatedFilterList = filterList.filter(
@@ -238,6 +253,7 @@ const MatchPage = ({ params }) => {
238253
}
239254

240255
const scrollToDetailedList = () => {
256+
setShowHTML(false)
241257
setShowPDF(false)
242258
setTriggerScroll(true)
243259
}
@@ -595,29 +611,47 @@ const MatchPage = ({ params }) => {
595611
</div>
596612
<div className={styles.toggle}>
597613
<button
598-
onClick={() => setShowPDF(true)}
614+
onClick={() => {
615+
if (matchData?.htmlFile != null) {
616+
setShowHTML(true)
617+
setShowPDF(false)
618+
} else if (matchData?.pdfFile != null) {
619+
setShowPDF(true)
620+
setShowHTML(false)
621+
}
622+
}}
599623
className={
600-
showPDF
624+
showHTML || showPDF
601625
? styles.toggle_buttonb_inactive
602626
: styles.toggle_buttonb_active
603627
}
604628
>
605629
Key Stats & Visuals
606630
</button>
607631
<button
608-
onClick={() => setShowPDF(false)}
632+
onClick={() => {
633+
setShowHTML(false)
634+
setShowPDF(false)
635+
}}
609636
className={
610-
showPDF
637+
!showHTML && !showPDF
611638
? styles.toggle_buttona_active
612639
: styles.toggle_buttona_inactive
613640
}
614641
>
615642
Detailed Point List
616643
</button>
617-
{showPDF ? (
644+
{showHTML ? (
645+
<iframe
646+
className={styles.VisualsView}
647+
src={matchData?.htmlFile}
648+
width="90%"
649+
height="1550"
650+
/>
651+
) : showPDF ? (
618652
<iframe
619-
className={styles.pdfView}
620-
src={matchData.pdfFile}
653+
className={styles.VisualsView}
654+
src={matchData?.pdfFile}
621655
width="90%"
622656
height="1550"
623657
/>

app/services/matchSchemas.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,14 @@ const initialSchema = {
161161
title: 'JSON File',
162162
format: 'data-url'
163163
},
164-
pdfFile: {
164+
// pdfFile: {
165+
// type: 'string',
166+
// title: 'PDF File'
167+
// },
168+
htmlFile: {
165169
type: 'string',
166-
title: 'PDF File'
170+
title: 'HTML File',
171+
format: 'data-url'
167172
}
168173
},
169174
required: [
@@ -182,7 +187,10 @@ const uiSchema = {
182187
jsonFile: {
183188
'ui:widget': 'file'
184189
},
185-
pdfFile: {
190+
// pdfFile: {
191+
// 'ui:widget': 'file'
192+
// },
193+
htmlFile: {
186194
'ui:widget': 'file'
187195
},
188196
event: {

app/styles/Match.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
margin: 0 auto; /* This may help maintain the centering if other elements are taking up space */
107107
}
108108

109-
.pdfView {
109+
.VisualsView {
110110
width: 100%;
111111
border: 1px solid #eaeaea;
112112
border-radius: 10px;

app/upload-match/page.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export default function UploadMatchForm() {
189189

190190
// Validate the File types
191191
validateFileType(formData.jsonFile, 'application/json', 'JSON file')
192-
validateFileType(formData.pdfFile, 'application/pdf', 'PDF file')
192+
validateFileType(formData.htmlFile, 'text/html', 'HTML file')
193193

194194
const pointsJson = formData.jsonFile
195195
? JSON.parse(atob(formData.jsonFile.split(',')[1]))
@@ -261,7 +261,7 @@ export default function UploadMatchForm() {
261261
sets,
262262
videoId: formData.videoID,
263263
pointsJson,
264-
pdfFile: formData.pdfFile ? dataURItoBlob(formData.pdfFile) : null,
264+
htmlFile: formData.htmlFile ? dataURItoBlob(formData.htmlFile) : null,
265265
teams: teamsData,
266266
players,
267267
matchDate: formData.date,

0 commit comments

Comments
 (0)