"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { toast } from "sonner"; export interface DeviceRow { id: number; displayName: string | null; bleName: string; lastConnectedAt: number | null; } function DeviceNameCell({ device }: { device: DeviceRow }) { const router = useRouter(); const [value, setValue] = useState(device.displayName ?? device.bleName); const [saving, setSaving] = useState(false); async function handleSave() { if (value.trim().length === 0) return; setSaving(true); const res = await fetch(`/api/devices/${device.id}`, { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ displayName: value.trim() }), }); setSaving(false); if (res.ok) { toast.success("Renamed"); router.refresh(); } else { toast.error("Could not rename device"); } } return (
setValue(e.target.value)} className="h-8 max-w-48" />
); } export function DevicesTable({ devices }: { devices: DeviceRow[] }) { if (devices.length === 0) { return

No devices seen yet - connect one from the Control page.

; } return ( Display name Advertised name Last connected {devices.map((d) => ( {d.bleName} {d.lastConnectedAt ? new Date(d.lastConnectedAt).toLocaleString() : "Never"} ))}
); }