Private
Public Access
1
0

chg: usr: improve the Battle reports to change unnecessary data with interesting data #5

This commit is contained in:
2026-04-18 17:56:50 +02:00
parent c00ed57240
commit 9aef27a0eb
2 changed files with 58 additions and 5 deletions

View File

@@ -198,6 +198,24 @@ export default function BattleDialog({ games }) {
: 'Points';
const shareUrl = `${window.location.origin}/battle/${game.uuid}`;
const formatDuration = (from, to) => {
if (!from || !to) return null;
const diffMs = new Date(to.replace(' ', 'T')) - new Date(from.replace(' ', 'T'));
if (isNaN(diffMs) || 0 >= diffMs) return null;
const totalSec = Math.floor(diffMs / 1000);
const h = Math.floor(totalSec / 3600);
const m = Math.floor((totalSec % 3600) / 60);
const s = totalSec % 60;
if (0 < h) return `${h}h ${m}m ${s}s`;
if (0 < m) return `${m}m ${s}s`;
return `${s}s`;
};
const duration = formatDuration(game.created, game.date);
const pointDiff = Math.abs((game.redPoints ?? 0) - (game.bluePoints ?? 0));
const winnerColor = (game.redPoints ?? 0) > (game.bluePoints ?? 0) ? '#f67d52'
: (game.bluePoints ?? 0) > (game.redPoints ?? 0) ? '#95cff5'
: 'rgba(255,255,255,0.45)';
const handleShare = () => {
navigator.clipboard.writeText(shareUrl).then(() => {
setCopied(true);
@@ -261,15 +279,21 @@ export default function BattleDialog({ games }) {
<div className="bd-stats">
<StatRow icon="fa-calendar" label="Date" value={game.date ?? '—'} />
<StatRow icon="fa-flag-checkered" label="End reason" value={endReason} />
{duration && (
<StatRow icon="fa-hourglass-half" label="Match duration" value={duration} />
)}
{0 < pointDiff && (
<StatRow icon="fa-balance-scale" label="Winning margin" value={`${pointDiff} mine${1 === pointDiff ? '' : 's'}`} valueColor={winnerColor} />
)}
<StatRow
icon="fa-bomb" label="Red hit a mine"
icon="fa-bomb" label="Red used bomb"
value={game.redExplodedBomb ? 'Yes' : 'No'}
valueColor={game.redExplodedBomb ? '#f67d52' : 'rgba(255,255,255,0.45)'}
/>
<StatRow
icon="fa-bomb" label="Blue hit a mine"
icon="fa-bomb" label="Blue used bomb"
value={game.blueExplodedBomb ? 'Yes' : 'No'}
valueColor={game.blueExplodedBomb ? '#f67d52' : 'rgba(255,255,255,0.45)'}
valueColor={game.blueExplodedBomb ? '#95cff5' : 'rgba(255,255,255,0.45)'}
/>
{game.created && game.date && game.created !== game.date && (
<StatRow icon="fa-clock-o" label="Started" value={game.created} />