From 9aef27a0ebc2ab69ccd55e2cb6194a040fce8b71 Mon Sep 17 00:00:00 2001 From: Lang <7system7@gmail.com> Date: Sat, 18 Apr 2026 17:56:50 +0200 Subject: [PATCH] chg: usr: improve the Battle reports to change unnecessary data with interesting data #5 --- assets/js/components/BattleDialog.jsx | 30 +++++++++++++++++++++--- templates/Game/battle_share.html.twig | 33 +++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/assets/js/components/BattleDialog.jsx b/assets/js/components/BattleDialog.jsx index 0991af1..ee303f9 100644 --- a/assets/js/components/BattleDialog.jsx +++ b/assets/js/components/BattleDialog.jsx @@ -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 }) {