refactor: integrate KpiTilesOverview component for enhanced KPI display
- Introduced the KpiTilesOverview component to streamline the presentation of KPI tiles, replacing the previous BodyKpiOverview implementation. - Updated the PilotKpiBoard and History components to utilize the new KpiTilesOverview for better touch and hover interactions. - Refactored CSS styles to accommodate the new component structure, ensuring a responsive design across devices. - Enhanced the logic for generating KPI tiles, improving data handling and user experience.
This commit is contained in:
1 parent
8c60601ed1
commit
08b7aa0ca1
4 files changed
+248
-176
No files matched your search
@@ -6,7 +6,7 @@ import {
|
||||
XAxis, YAxis, Tooltip, ResponsiveContainer, CartesianGrid,
|
||||
ReferenceLine, PieChart, Pie, Cell, ComposedChart
|
||||
} from 'recharts'
|
||||
import { ChevronRight, Brain, ChevronDown, ChevronUp, Trash2, Info } from 'lucide-react'
|
||||
import { ChevronRight, Brain, ChevronDown, ChevronUp, Trash2 } from 'lucide-react'
|
||||
import { api } from '../utils/api'
|
||||
import { photoMonthKey, photoSortKey, formatPhotoCaption } from '../utils/photoDisplay'
|
||||
import { getBfCategory } from '../utils/calc'
|
||||
@@ -15,6 +15,7 @@ import Markdown from '../utils/Markdown'
|
||||
import TrainingTypeDistribution from '../components/TrainingTypeDistribution'
|
||||
import NutritionCharts from '../components/NutritionCharts'
|
||||
import RecoveryCharts from '../components/RecoveryCharts'
|
||||
import KpiTilesOverview from '../components/KpiTilesOverview'
|
||||
import dayjs from 'dayjs'
|
||||
import 'dayjs/locale/de'
|
||||
dayjs.locale('de')
|
||||
@@ -232,122 +233,6 @@ function buildBodyKpiTiles({
|
||||
return tiles
|
||||
}
|
||||
|
||||
function kpiTileDetailParts(t) {
|
||||
const registryLine = t.keys?.length ? `Registry: ${t.keys.join(', ')}` : ''
|
||||
const body = [t.hoverBody, registryLine].filter(Boolean).join('\n\n')
|
||||
return { title: t.hoverTop || t.category, body }
|
||||
}
|
||||
|
||||
/** KPI-Kacheln: Desktop — Hover (`title`). Touch — ℹ öffnet gleichen Text im Bottom-Sheet (iOS hat kein Hover). */
|
||||
function BodyKpiOverview({ tiles }) {
|
||||
const [touchUi, setTouchUi] = useState(false)
|
||||
const [openKey, setOpenKey] = useState(null)
|
||||
|
||||
useEffect(() => {
|
||||
const mq = window.matchMedia('(hover: none)')
|
||||
const apply = () => setTouchUi(mq.matches)
|
||||
apply()
|
||||
mq.addEventListener('change', apply)
|
||||
return () => mq.removeEventListener('change', apply)
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (!openKey) return
|
||||
const onKey = e => { if (e.key === 'Escape') setOpenKey(null) }
|
||||
const prev = document.body.style.overflow
|
||||
document.body.style.overflow = 'hidden'
|
||||
window.addEventListener('keydown', onKey)
|
||||
return () => {
|
||||
document.body.style.overflow = prev
|
||||
window.removeEventListener('keydown', onKey)
|
||||
}
|
||||
}, [openKey])
|
||||
|
||||
if (!tiles?.length) return null
|
||||
|
||||
const openTile = openKey ? tiles.find(x => x.key === openKey) : null
|
||||
const openParts = openTile ? kpiTileDetailParts(openTile) : null
|
||||
|
||||
return (
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)', marginBottom: 8 }}>Kennzahlen</div>
|
||||
{touchUi && (
|
||||
<div style={{ fontSize: 10, color: 'var(--text3)', marginBottom: 8, lineHeight: 1.4 }}>
|
||||
<Info size={12} style={{ display: 'inline', verticalAlign: 'middle', marginRight: 4 }} aria-hidden />
|
||||
Auf dem Smartphone: <strong>ℹ</strong> für Erklärung und Details.
|
||||
</div>
|
||||
)}
|
||||
<div className="body-kpi-overview">
|
||||
{tiles.map(t => {
|
||||
const accent = getStatusColor(t.status)
|
||||
const tip = [t.hoverTop, t.hoverBody, t.keys?.length ? `Registry: ${t.keys.join(', ')}` : ''].filter(Boolean).join('\n\n')
|
||||
return (
|
||||
<div
|
||||
key={t.key}
|
||||
className="body-kpi-card"
|
||||
style={{ borderLeft: `4px solid ${accent}`, position: 'relative' }}
|
||||
title={touchUi ? undefined : tip}
|
||||
>
|
||||
{touchUi && (
|
||||
<button
|
||||
type="button"
|
||||
className="body-kpi-info-btn"
|
||||
aria-label={`Details: ${t.category}`}
|
||||
aria-expanded={openKey === t.key}
|
||||
onClick={() => setOpenKey(k => (k === t.key ? null : t.key))}
|
||||
>
|
||||
<Info size={16} strokeWidth={2.25} aria-hidden />
|
||||
</button>
|
||||
)}
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', gap: 6, paddingRight: touchUi ? 28 : 0 }}>
|
||||
<span style={{ fontSize: 14, lineHeight: 1 }}>{t.icon}</span>
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<div style={{ fontSize: 9, fontWeight: 600, color: 'var(--text3)', textTransform: 'uppercase', letterSpacing: '0.04em' }}>{t.category}</div>
|
||||
<div style={{ fontSize: 18, fontWeight: 700, color: t.valueColor || 'var(--text1)', marginTop: 2, lineHeight: 1.2 }}>{t.value}</div>
|
||||
{t.sublabel && (
|
||||
<div style={{ fontSize: 10, color: 'var(--text3)', marginTop: 2, lineHeight: 1.25 }}>{t.sublabel}</div>
|
||||
)}
|
||||
</div>
|
||||
<div style={{ textAlign: 'right', flexShrink: 0 }}>
|
||||
<div style={{ fontSize: 10, fontWeight: 700, color: accent, lineHeight: 1.2 }}>{t.verdict}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{openParts && (
|
||||
<div
|
||||
className="body-kpi-touch-backdrop"
|
||||
role="presentation"
|
||||
onClick={() => setOpenKey(null)}
|
||||
>
|
||||
<div
|
||||
className="body-kpi-touch-sheet"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="body-kpi-touch-title"
|
||||
onClick={e => e.stopPropagation()}
|
||||
>
|
||||
<div className="body-kpi-touch-sheet__head">
|
||||
<h3 id="body-kpi-touch-title" className="body-kpi-touch-sheet__title">{openParts.title}</h3>
|
||||
<button type="button" className="body-kpi-touch-sheet__close" onClick={() => setOpenKey(null)} aria-label="Schließen">
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
{openParts.body ? (
|
||||
<div className="body-kpi-touch-sheet__body">{openParts.body}</div>
|
||||
) : (
|
||||
<div className="body-kpi-touch-sheet__body body-kpi-touch-sheet__body--muted">Keine weiteren Details.</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function BodyGoalsStrip({ grouped }) {
|
||||
const nav = useNavigate()
|
||||
const goals = (grouped?.body || []).filter(g => g.status === 'active').slice(0, 4)
|
||||
@@ -613,7 +498,7 @@ function BodySection({ profile, insights, onRequest, loadingSlug, filterActiveSl
|
||||
</div>
|
||||
)}
|
||||
|
||||
<BodyKpiOverview tiles={kpiTiles} />
|
||||
<KpiTilesOverview tiles={kpiTiles} />
|
||||
|
||||
{vizLoading && (
|
||||
<div style={{ fontSize: 11, color: 'var(--text3)', marginBottom: 8 }}>Aktualisiere…</div>
|
||||
|
||||
Reference in new issue
Block a user