diff --git a/app/components/DashboardTile.js b/app/components/DashboardTile.js index da4e78f..3136824 100644 --- a/app/components/DashboardTile.js +++ b/app/components/DashboardTile.js @@ -4,19 +4,6 @@ import styles from '@/app/styles/DashboardTile.module.css' import { useData } from '@/app/DataProvider' -// Calculate winner of match -const calculateWinner = (player1, player2) => { - const player1Total = player1.reduce( - (total, current) => (!isNaN(current.score) ? total + current.score : total), - 0 - ) - const player2Total = player2.reduce( - (total, current) => (!isNaN(current.score) ? total + current.score : total), - 0 - ) - return player1Total > player2Total -} - const DashboardTile = ({ clientTeam, opponentTeam, @@ -35,96 +22,100 @@ const DashboardTile = ({ const isOpaque = (player1Scores, player2Scores) => { return player1Scores.map((score, index) => { - const player1Score = !isNaN(score.score) ? score.score : 0; - const player2Score = !isNaN(player2Scores[index]?.score) ? player2Scores[index].score : 0; - return player1Score > player2Score; - }); - }; + const player1Score = !isNaN(score.score) ? score.score : 0 + const player2Score = !isNaN(player2Scores[index]?.score) + ? player2Scores[index].score + : 0 + return player1Score > player2Score + }) + } // Calculate opacity map before rendering - const player1Opacity = isOpaque(player1FinalScores, player2FinalScores); + const player1Opacity = isOpaque(player1FinalScores, player2FinalScores) useEffect(() => { setClientLogo(logos[clientTeam]) setOpponentLogo(logos[opponentTeam]) }, [clientTeam, opponentTeam, logos]) - // Render function for scores - const renderScore = (score, index, isPlayer1, tieScores) => { - const opacity = isPlayer1 ? - (player1Opacity[index] ? '100%' : '40%') : - (!player1Opacity[index] ? '100%' : '40%'); + // Render function for scores + const renderScore = (score, index, isPlayer1, tieScores) => { + const opacity = isPlayer1 + ? player1Opacity[index] + ? '100%' + : '40%' + : !player1Opacity[index] + ? '100%' + : '40%' - return ( - !isNaN(score.score) && ( -
- {score.score} - {tieScores[index] && ( - - {tieScores[index]} - - )} -
- ) - ); -}; - -return loading ? ( -

Loading ...

-) : ( -
-
-
-
Final Score
- {isTagged &&
Tagged
} -
- - {/* Player 1 */} -
-
- {`${clientTeam} -
-
- {player1Name} {isUnfinished && '(UF)'} -
-
- {player1FinalScores.map((score, index) => - renderScore(score, index, true, player1TieScores) + return ( + !isNaN(score.score) && ( +
+ {score.score} + {tieScores[index] && ( + + {tieScores[index]} + )}
-
+ ) + ) + } - {/* Player 2 */} -
-
- {`${opponentTeam} + return loading ? ( +

Loading ...

+ ) : ( +
+
+
+
Final Score
+ {isTagged &&
Tagged
}
-
- {player2Name} + + {/* Player 1 */} +
+
+ {`${clientTeam} +
+
+ {player1Name} {isUnfinished && '(UF)'} +
+
+ {player1FinalScores.map((score, index) => + renderScore(score, index, true, player1TieScores) + )} +
-
- {player2FinalScores.map((score, index) => - renderScore(score, index, false, player2TieScores) - )} + + {/* Player 2 */} +
+
+ {`${opponentTeam} +
+
{player2Name}
+
+ {player2FinalScores.map((score, index) => + renderScore(score, index, false, player2TieScores) + )} +
-
-); -}; + ) +} -export default DashboardTile; \ No newline at end of file +export default DashboardTile diff --git a/app/components/MatchTiles.js b/app/components/MatchTiles.js index 53d77c0..3854f88 100644 --- a/app/components/MatchTiles.js +++ b/app/components/MatchTiles.js @@ -3,27 +3,16 @@ import React, { useEffect, useState } from 'react' import styles from '@/app/styles/MatchTiles.module.css' import getTeams from '@/app/services/getTeams.js' -// Calculate winner of match -const calculateWinner = (player1, player2) => { - const player1Total = player1.reduce( - (total, current) => (!isNaN(current.score) ? total + current.score : total), - 0 - ) - const player2Total = player2.reduce( - (total, current) => (!isNaN(current.score) ? total + current.score : total), - 0 - ) - return player1Total > player2Total -} - // Calculate opacity for individual scores const isOpaque = (player1Scores, player2Scores) => { return player1Scores.map((score, index) => { - const player1Score = !isNaN(score.score) ? score.score : 0; - const player2Score = !isNaN(player2Scores[index]?.score) ? player2Scores[index].score : 0; - return player1Score > player2Score; - }); -}; + const player1Score = !isNaN(score.score) ? score.score : 0 + const player2Score = !isNaN(player2Scores[index]?.score) + ? player2Scores[index].score + : 0 + return player1Score > player2Score + }) +} const MatchTiles = ({ // matchName, @@ -44,8 +33,8 @@ const MatchTiles = ({ const [clientLogo, setClientLogo] = useState('') const [opponentLogo, setOpponentLogo] = useState('') - // to calculate the opcaity - const player1Opacity = isOpaque(player1FinalScores, player2FinalScores); + // to calculate the opcaity + const player1Opacity = isOpaque(player1FinalScores, player2FinalScores) useEffect(() => { const fetchLogos = async () => { @@ -69,35 +58,41 @@ const MatchTiles = ({ // Render function for scores const renderScore = (score, index, isPlayer1, tieScores) => { - const opacity = isPlayer1 ? - (player1Opacity[index] ? '100%' : '40%') : - (!player1Opacity[index] ? '100%' : '40%'); + const opacity = isPlayer1 + ? player1Opacity[index] + ? '100%' + : '40%' + : !player1Opacity[index] + ? '100%' + : '40%' - return !isNaN(score.score) && ( -
- {score.score} - {tieScores[index] && ( - - {tieScores[index]} - - )} -
- ); - }; + return ( + !isNaN(score.score) && ( +
+ {score.score} + {tieScores[index] && ( + + {tieScores[index]} + + )} +
+ ) + ) + } return (
@@ -117,7 +112,7 @@ const MatchTiles = ({ {player1Name} {isUnfinished && '(UF)'}
- {player1FinalScores.map((score, index) => + {player1FinalScores.map((score, index) => renderScore(score, index, true, player1TieScores) )}
@@ -127,20 +122,15 @@ const MatchTiles = ({
{`${opponentTeam}
-
- {player2Name} -
+
{player2Name}
- {player2FinalScores.map((score, index) => + {player2FinalScores.map((score, index) => renderScore(score, index, false, player2TieScores) )}
- - - {/* Match Location */} {displaySections.info && (
diff --git a/app/components/ScoreBoard.js b/app/components/ScoreBoard.js index f31ece2..876505f 100644 --- a/app/components/ScoreBoard.js +++ b/app/components/ScoreBoard.js @@ -1,5 +1,5 @@ -import React, { useState, useEffect } from 'react'; -import styles from '../styles/Scoreboard.module.css'; +import React, { useState, useEffect } from 'react' +import styles from '../styles/Scoreboard.module.css' const ScoreBoard = ({ playData, @@ -20,42 +20,43 @@ const ScoreBoard = ({ player2TiebreakScore = 0, serverName = '', pointScore = true - } = playData || {}; + } = playData || {} - const [localPlayData, setLocalPlayData] = useState(playData); + const [localPlayData, setLocalPlayData] = useState(playData) useEffect(() => { if (playData) { const timeout = setTimeout(() => { - setLocalPlayData(playData); - }, 500); - return () => clearTimeout(timeout); + setLocalPlayData(playData) + }, 500) + return () => clearTimeout(timeout) } - }, [playData]); + }, [playData]) // Get the server name safely - const currentServerName = localPlayData?.serverName || serverName; + const currentServerName = localPlayData?.serverName || serverName return (
- + {player1FinalScores.map((score, index) => - localPlayData && !isNaN(score.score) && index + 1 < localPlayData.setNum ? ( - ) : null )} - + {player2FinalScores.map((score, index) => - localPlayData && !isNaN(score.score) && index + 1 < localPlayData.setNum ? ( -
- Live Score {isUnfinished && '(UF)'} - Live Score {isUnfinished && '(UF)'}
{player1Name} player2FinalScores[index].score ? 1 : 0.4 + localPlayData && + !isNaN(score.score) && + index + 1 < localPlayData.setNum ? ( + player2FinalScores[index].score ? 1 : 0.4 }} > {player1TieScores[index] ? ( @@ -67,7 +68,7 @@ const ScoreBoard = ({ fontSize: '0.6em', top: '0.1em', right: '0em', - letterSpacing: '1px', + letterSpacing: '1px' }} > {player1TieScores[index]} @@ -79,23 +80,28 @@ const ScoreBoard = ({ {player1GameScore} {pointScore ? player1PointScore : player1TiebreakScore} - {currentServerName && player1Name === currentServerName && } + {currentServerName && player1Name === currentServerName && ( + + )}
{player2Name} player1FinalScores[index].score ? 1 : 0.4 + localPlayData && + !isNaN(score.score) && + index + 1 < localPlayData.setNum ? ( + player1FinalScores[index].score ? 1 : 0.4 }} > {player2TieScores[index] ? ( @@ -123,13 +129,15 @@ const ScoreBoard = ({ {pointScore ? player2PointScore : player2TiebreakScore} - {currentServerName && player2Name === currentServerName && } + {currentServerName && player2Name === currentServerName && ( + + )}
- ); -}; + ) +} -export default ScoreBoard; \ No newline at end of file +export default ScoreBoard