"use client"; import React, { useEffect, useState } from "react"; import { useAppSelector } from "@/redux/store"; export default function GlobalActivityOverlay() { const anyLoop = useAppSelector((s) => s.deviceEvents.anyLoopActive); const anyTdr = useAppSelector((s) => s.deviceEvents.anyTdrActive); const anyCompare = useAppSelector((s) => s.deviceEvents.anyComparisonActive); const ksx = useAppSelector((s) => s.deviceEvents.ksx); const ksy = useAppSelector((s) => s.deviceEvents.ksy); const ksz = useAppSelector((s) => s.deviceEvents.ksz); const loopStartedAt = useAppSelector((s) => s.deviceEvents.loopStartedAt); const tdrStartedAt = useAppSelector((s) => s.deviceEvents.tdrStartedAt); const comparisonStartedAt = useAppSelector( (s) => s.deviceEvents.comparisonStartedAt ); const fmt = (arr: number[]) => arr .map((v, i) => (v ? i + 1 : 0)) .filter((n) => n !== 0) .join(", "); // Simple 1s ticker so progress bars advance while overlay is shown const [now, setNow] = useState(Date.now()); useEffect(() => { const active = anyLoop || anyTdr || anyCompare; if (!active) return; const id = setInterval(() => setNow(Date.now()), 1000); return () => clearInterval(id); }, [anyLoop, anyTdr, anyCompare]); const active = anyLoop || anyTdr || anyCompare; if (!active) return null; const clamp = (v: number, min = 0, max = 1) => Math.max(min, Math.min(max, v)); const compute = (startedAt: number | null, durationMs: number) => { if (!startedAt) return { pct: 0, remaining: durationMs }; const elapsed = now - startedAt; const pct = clamp(elapsed / durationMs) * 100; const remaining = Math.max(0, durationMs - Math.max(0, elapsed)); return { pct, remaining }; }; // Durations const LOOP_MS = 2 * 60 * 1000; // ~2 min const TDR_MS = 30 * 1000; // ~30 s const ALIGN_MS = 10 * 60 * 1000; // ~10 min return (
Bitte warten…
{anyLoop && (
Schleifenmessung läuft… (KÜ: {fmt(ksx)})
{(() => { const { pct } = compute(loopStartedAt, LOOP_MS); return (
{Math.round(pct)}%
); })()}
)} {anyTdr && (
TDR-Messung läuft… (KÜ: {fmt(ksy)})
{(() => { const { pct } = compute(tdrStartedAt, TDR_MS); return (
{Math.round(pct)}%
); })()}
)} {anyCompare && (
Comparison läuft… (KÜ: {fmt(ksz)}) kann bis zu 10 Minuten dauern
{(() => { const { pct } = compute(comparisonStartedAt, ALIGN_MS); return (
{Math.round(pct)}%
); })()}
)}
); }