Files
sexy/components/devices/DevicesTable.tsx
T
valknarandClaude Sonnet 5 5484d3cefe
CI / Static checks (push) Successful in 1m7s
CI / Build and push image (push) Successful in 1m2s
Fix device/replay/session UX issues, add pagination, bump to 0.3.0
- Fix device rename input collapsing on mobile (fixed width vs w-full
  inside an auto-layout table column).
- Add cascade-delete confirmation for sessions with a saved recording.
- Fix header connection LED: derive state from scanning/device-count/
  recording instead of the Buttplug client's raw connected flag; drop
  the label text and hide the indicator entirely when idle.
- Add a per-device disconnect button (stop + remove from store, the
  closest equivalent Buttplug's protocol allows per device).
- Fix replay ending early: duration now comes from the recording's
  actual durationMs, not the last event's timestamp.
- Replay robustness: show which devices are being replayed to, reset
  actuators to zero on start/play/pause, fully disconnect devices and
  the whole client on stop/unmount, surface command failures via toast.
- Stop flagging the header LED red during replay - recording is only
  for live sessions.
- Add page-number pagination to recordings/sessions/devices lists.
- Wordmark SEXY -> Sexy; add proper per-page <title>s including
  dynamic titles for recording/session detail and replay pages.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-25 21:26:18 +02:00

79 lines
2.4 KiB
TypeScript

"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 (
<div className="flex items-center gap-2">
<Input value={value} onChange={(e) => setValue(e.target.value)} className="h-8 w-40 min-w-40" />
<Button size="sm" variant="outline" onClick={handleSave} disabled={saving} className="shrink-0">
Save
</Button>
</div>
);
}
export function DevicesTable({ devices }: { devices: DeviceRow[] }) {
if (devices.length === 0) {
return <p className="text-sm text-muted-foreground">No devices seen yet - connect one from the Control page.</p>;
}
return (
<Table>
<TableHeader>
<TableRow>
<TableHead>Display name</TableHead>
<TableHead>Advertised name</TableHead>
<TableHead>Last connected</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{devices.map((d) => (
<TableRow key={d.id}>
<TableCell>
<DeviceNameCell device={d} />
</TableCell>
<TableCell className="bp-readout text-muted-foreground">{d.bleName}</TableCell>
<TableCell className="bp-readout text-muted-foreground">
{d.lastConnectedAt ? new Date(d.lastConnectedAt).toLocaleString() : "Never"}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
);
}