Skip to content

Commit 6441e45

Browse files
committed
feat: Enhance HealthBar component with clickable opponent usernames
- Added a new prop, isOpponent, to the HealthBar component to conditionally render opponent usernames as clickable links. - Implemented styling for the links to improve user interaction and navigation to opponent profiles. - Updated gameUI component to pass the isOpponent prop for the relevant player. - Minor text change in user.js for improved clarity in navigation button.
1 parent 8d4fb76 commit 6441e45

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

components/duelHealthbar.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useState, useEffect, useRef } from 'react';
22
import { getLeague } from './utils/leagues';
3+
import Link from 'next/link';
34

45
const easeOutElastic = (t) => {
56
const c4 = (2 * Math.PI) / 3;
@@ -16,7 +17,7 @@ const easeOutBack = (t) => {
1617
return 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
1718
};
1819

19-
const HealthBar = ({ health, maxHealth, name, elo, start, isStartingDuel }) => {
20+
const HealthBar = ({ health, maxHealth, name, elo, start, isStartingDuel, isOpponent = false }) => {
2021
const [displayHealth, setDisplayHealth] = useState(health);
2122
const [prevHealth, setPrevHealth] = useState(health);
2223
const [isAnimating, setIsAnimating] = useState(false);
@@ -101,7 +102,30 @@ const HealthBar = ({ health, maxHealth, name, elo, start, isStartingDuel }) => {
101102

102103
<div className={`player-info-modern ${isStartingDuel ? 'starting' : ''}`}>
103104
<div className="player-name-wrapper">
104-
<span className="player-name">{name}</span>
105+
{isOpponent && name ? (
106+
<Link
107+
href={`/user?u=${encodeURIComponent(name)}`}
108+
target="_blank"
109+
className="player-name"
110+
style={{
111+
color: 'white',
112+
textDecoration: 'underline',
113+
cursor: 'pointer',
114+
transition: 'opacity 0.2s ease',
115+
pointerEvents: 'auto'
116+
}}
117+
onMouseEnter={(e) => {
118+
e.currentTarget.style.opacity = '0.8';
119+
}}
120+
onMouseLeave={(e) => {
121+
e.currentTarget.style.opacity = '1';
122+
}}
123+
>
124+
{name}
125+
</Link>
126+
) : (
127+
<span className="player-name">{name}</span>
128+
)}
105129
{elo && (
106130
<span
107131
className="player-elo"

components/gameUI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ isStartingDuel={isStartingDuel}
531531
name={
532532
// get your name from the game state
533533
multiplayerState?.gameData?.players.find(p => p.id !== multiplayerState?.gameData?.myId)?.username
534-
} elo={multiplayerState?.gameData?.players.find(p => p.id !== multiplayerState?.gameData?.myId)?.elo} start={true || isStartingDuel} />
534+
} elo={multiplayerState?.gameData?.players.find(p => p.id !== multiplayerState?.gameData?.myId)?.elo} start={true || isStartingDuel} isOpponent={true} />
535535
</div>
536536
</div>
537537

pages/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export default function UserProfilePage() {
190190
className="back-to-wg-button"
191191
onClick={() => router.push('/')}
192192
>
193-
Back to WorldGuessr
193+
Go to WorldGuessr
194194
</button>
195195
</div>
196196

0 commit comments

Comments
 (0)