From 8a0dfa6848ae37fb0cb7e729ec6adcd65e6701d4 Mon Sep 17 00:00:00 2001 From: SaiKarthik-M6 Date: Mon, 6 Jan 2025 19:22:45 -0800 Subject: [PATCH] Bolding issue for scoreboard and dashboard made sure the winning score for the bolding issue is fixed, so only the winning score is bolded --- app/components/DashboardTile.js | 172 +++++++++++--------------------- app/components/ScoreBoard.js | 4 +- 2 files changed, 59 insertions(+), 117 deletions(-) diff --git a/app/components/DashboardTile.js b/app/components/DashboardTile.js index 78e61a5..8a6b970 100644 --- a/app/components/DashboardTile.js +++ b/app/components/DashboardTile.js @@ -2,22 +2,6 @@ import React, { useEffect, useState } from 'react'; import styles from '../styles/DashboardTile.module.css'; import { useData } from './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, @@ -30,9 +14,9 @@ const DashboardTile = ({ isUnfinished, isTagged }) => { - const { logos, loading } = useData() - const [clientLogo, setClientLogo] = useState(null) - const [opponentLogo, setOpponentLogo] = useState(null) + const { logos, loading } = useData(); + const [clientLogo, setClientLogo] = useState(null); + const [opponentLogo, setOpponentLogo] = useState(null); const isOpaque = (player1Scores, player2Scores) => { return player1Scores.map((score, index) => { @@ -40,15 +24,49 @@ const DashboardTile = ({ 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]) + 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%'); + + return ( + !isNaN(score.score) && ( +
+ {score.score} + {tieScores[index] && ( + + {tieScores[index]} + + )} +
+ ) + ); + }; return loading ? (

Loading ...

@@ -59,115 +77,39 @@ const DashboardTile = ({
Final Score
{isTagged &&
Tagged
} + + {/* Player 1 */}
{`${clientTeam}
-
+
{player1Name} {isUnfinished && '(UF)'}
-
- {player1FinalScores.map( - (score, index) => - !isNaN(score.score) && ( -
- {score.score} - {player1TieScores[index] && ( - - {player1TieScores[index]} - - )} -
- ) +
+ {player1FinalScores.map((score, index) => + renderScore(score, index, true, player1TieScores) )}
+ + {/* Player 2 */}
{`${opponentTeam}
-
+
{player2Name}
-
- {player2FinalScores.map( - (score, index) => - !isNaN(score.score) && ( -
- {score.score} - {player2TieScores[index] && ( - - {player2TieScores[index]} - - )} -
- ) +
+ {player2FinalScores.map((score, index) => + renderScore(score, index, false, player2TieScores) )}
- ) -} + ); +}; -export default DashboardTile +export default DashboardTile; \ No newline at end of file diff --git a/app/components/ScoreBoard.js b/app/components/ScoreBoard.js index d611a8f..3cebd19 100644 --- a/app/components/ScoreBoard.js +++ b/app/components/ScoreBoard.js @@ -24,11 +24,11 @@ const ScoreBoard = ({ const [localPlayData, setLocalPlayData] = useState(playData); - useEffect(() => { + useEffect(() => { //smooth transition effect when scores change if (playData) { const timeout = setTimeout(() => { setLocalPlayData(playData); - }, 500); + }, 100); return () => clearTimeout(timeout); } }, [playData]);