feat: real worker status, covers on Recently Pressed, library counter
- Worker stamps a throttled worker.heartbeat; GET /api/worker reports online from its updatedAt recency (DB-time); masthead shows a live listening/offline dot instead of a static decoration. - /api/requests enriched with rgMbid; Recently Pressed shows cover thumbs. - Library album count moved from the filter row into a section header. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
/** Live worker liveness in the masthead — polls /api/worker (heartbeat recency). */
|
||||
export function WorkerStatus() {
|
||||
const [online, setOnline] = useState<boolean | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
async function check() {
|
||||
try {
|
||||
const d = await (await fetch("/api/worker")).json();
|
||||
if (alive) setOnline(!!d.online);
|
||||
} catch {
|
||||
if (alive) setOnline(false);
|
||||
}
|
||||
}
|
||||
check();
|
||||
const id = setInterval(check, 10000);
|
||||
return () => {
|
||||
alive = false;
|
||||
clearInterval(id);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const label = online === null ? "…" : online ? "listening" : "offline";
|
||||
return (
|
||||
<div className={`worker-status${online === false ? " off" : ""}`}>
|
||||
<span className="live-dot" />
|
||||
Worker · {label}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user