Public changes compared with the previous published export: 19 files changed. Affected areas: - backend/app: 3 files - dependencies: 2 files - documentation: 1 file - frontend: 2 files - frontend/src: 10 files - tests: 1 file Changed files: - Updated: "backend/app/acquisition.py" - Added: "backend/app/icons.py" - Updated: "backend/app/main.py" - Added: "backend/tests/test_icons.py" - Updated: "docs/ARCHITECTURE.md" - Updated: "frontend/package-lock.json" - Updated: "frontend/package.json" - Updated: "frontend/playwright.config.ts" - Updated: "frontend/src/App.tsx" - Updated: "frontend/src/components/DashboardView.tsx" - Added: "frontend/src/components/HealthRing.tsx" - Updated: "frontend/src/components/HistoryView.tsx" - Added: "frontend/src/components/Icon.tsx" - Updated: "frontend/src/components/PortfolioAtlas.tsx" - Updated: "frontend/src/components/RemediationCenter.tsx" - Added: "frontend/src/components/RepoAvatar.tsx" - Updated: "frontend/src/main.tsx" - Updated: "frontend/src/styles.css" - Updated: "frontend/vite.config.ts" Export provenance/manifests refreshed; excluded from the change summary. Publish curated RepoPulse source from 7a60c53ee2c1daebecd66a01656e323f1db72e56
52 lines
2.6 KiB
TypeScript
52 lines
2.6 KiB
TypeScript
import { useEffect, useState } from 'react'
|
||
|
||
import type { Readiness } from '../catalog'
|
||
|
||
function prefersReducedMotion() {
|
||
try { return window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false } catch { return false }
|
||
}
|
||
|
||
/** Animate a number from 0 to its value once; static when reduced motion is requested. */
|
||
export function useCountUp(value: number, duration = 700) {
|
||
const [display, setDisplay] = useState(() => (prefersReducedMotion() || typeof window.requestAnimationFrame !== 'function' ? value : 0))
|
||
useEffect(() => {
|
||
if (prefersReducedMotion() || typeof window.requestAnimationFrame !== 'function') { setDisplay(value); return }
|
||
let frame = 0
|
||
let synchronous = true
|
||
const start = performance.now()
|
||
const tick = () => {
|
||
// Some environments run animation callbacks synchronously; settle immediately there.
|
||
if (synchronous) { setDisplay(value); return }
|
||
const progress = Math.max(0, Math.min(1, (performance.now() - start) / duration))
|
||
const eased = 1 - Math.pow(1 - progress, 3)
|
||
setDisplay(Math.round(value * eased))
|
||
if (progress < 1) frame = window.requestAnimationFrame(tick)
|
||
}
|
||
frame = window.requestAnimationFrame(tick)
|
||
synchronous = false
|
||
return () => window.cancelAnimationFrame(frame)
|
||
}, [value, duration])
|
||
return display
|
||
}
|
||
|
||
export function CountUp({ value }: { value: number }) {
|
||
return <>{useCountUp(value)}</>
|
||
}
|
||
|
||
/** A compact health gauge: the arc follows the retained 0–100 score, coloured by readiness. */
|
||
export function HealthRing({ value, readiness, size = 40, label = true }: { value: number | null; readiness: Readiness; size?: number; label?: boolean }) {
|
||
const stroke = size >= 64 ? 5 : 3.5
|
||
const radius = (size - stroke) / 2
|
||
const circumference = 2 * Math.PI * radius
|
||
const score = value == null ? 0 : Math.max(0, Math.min(100, value))
|
||
return (
|
||
<span className={`health-ring ${readiness} ${value == null ? 'unknown' : ''}`} style={{ width: size, height: size }} title={value == null ? 'Not scanned' : `${value} / 100 health`}>
|
||
<svg viewBox={`0 0 ${size} ${size}`} width={size} height={size} aria-hidden="true">
|
||
<circle className="health-ring-track" cx={size / 2} cy={size / 2} r={radius} strokeWidth={stroke} fill="none" />
|
||
<circle className="health-ring-value" cx={size / 2} cy={size / 2} r={radius} strokeWidth={stroke} fill="none" strokeLinecap="round" strokeDasharray={circumference} strokeDashoffset={circumference * (1 - score / 100)} transform={`rotate(-90 ${size / 2} ${size / 2})`} style={{ ['--ring-length' as string]: circumference }} />
|
||
</svg>
|
||
{label && <b>{value ?? '—'}</b>}
|
||
</span>
|
||
)
|
||
}
|