Files
homelab-optimized/dashboard/ui/components/activity-feed.tsx
Gitea Mirror Bot c1a6970aa7
Some checks failed
Documentation / Build Docusaurus (push) Failing after 5m1s
Documentation / Deploy to GitHub Pages (push) Has been skipped
Sanitized mirror from private repository - 2026-04-05 05:50:13 UTC
2026-04-05 05:50:13 +00:00

84 lines
2.8 KiB
TypeScript

"use client";
import { useSSE } from "@/lib/use-sse";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { ScrollArea } from "@/components/ui/scroll-area";
import type { ActivityEvent } from "@/lib/types";
const typeColors: Record<string, string> = {
stack_healthy: "bg-green-500 glow-green",
backup_result: "bg-green-500 glow-green",
email_classified: "bg-blue-500 glow-blue",
receipt_extracted: "bg-amber-500 glow-amber",
container_unhealthy: "bg-red-500 glow-red",
};
function formatTime(ts: string) {
try {
return new Date(ts).toLocaleTimeString("en-US", {
hour: "2-digit",
minute: "2-digit",
});
} catch {
return ts;
}
}
function eventMessage(event: ActivityEvent): string {
if (event.raw) return event.raw;
return `${event.type} from ${event.source}`;
}
export function ActivityFeed() {
const events = useSSE("/api/activity");
return (
<Card className="col-span-full lg:col-span-3 overflow-hidden relative">
<div className="absolute top-0 left-0 right-0 h-[2px] bg-gradient-to-r from-green-500 via-blue-500 to-violet-500" />
<CardHeader className="flex flex-row items-center justify-between pb-2">
<CardTitle className="text-sm font-medium">Activity Feed</CardTitle>
<Badge
variant="outline"
className="text-[10px] border-green-500/50 text-green-400 animate-live-pulse"
>
<span className="inline-block w-1.5 h-1.5 rounded-full bg-green-400 mr-1.5 glow-green" />
LIVE
</Badge>
</CardHeader>
<CardContent>
<ScrollArea className="h-[220px]">
{events.length === 0 && (
<p className="text-xs text-muted-foreground py-4 text-center">
Waiting for events...
</p>
)}
<div className="space-y-2">
{events.map((event, i) => (
<div
key={`${event.timestamp}-${i}`}
className="flex items-start gap-2 text-xs animate-slide-in"
style={{ animationDelay: `${i * 30}ms` }}
>
<span
className={`w-2 h-2 rounded-full mt-1 shrink-0 ${
typeColors[event.type] ?? "bg-gray-500"
}`}
/>
<div className="flex-1 min-w-0">
<p className="text-foreground truncate">
{eventMessage(event)}
</p>
<p className="text-muted-foreground">
{formatTime(event.timestamp)} &middot; {event.source}
</p>
</div>
</div>
))}
</div>
</ScrollArea>
</CardContent>
</Card>
);
}