diff --git a/src/components/HostCard.tsx b/src/components/HostCard.tsx new file mode 100644 index 0000000..774e131 --- /dev/null +++ b/src/components/HostCard.tsx @@ -0,0 +1,107 @@ +import { useState } from "react"; +import { Host, api } from "../api"; + +interface Props { + host: Host; + onRefresh: () => void; +} + +export function HostCard({ host, onRefresh }: Props) { + const [connecting, setConnecting] = useState(false); + const [pairing, setPairing] = useState(false); + const [flash, setFlash] = useState(null); + + function showFlash(msg: string) { + setFlash(msg); + setTimeout(() => setFlash(null), 3000); + } + + async function handleConnect() { + setConnecting(true); + try { + await api.connect(host.ip); + showFlash("Launching Moonlight…"); + } catch (e: unknown) { + showFlash(e instanceof Error ? e.message : "Failed to connect"); + } finally { + setConnecting(false); + } + } + + async function handlePair() { + setPairing(true); + try { + await api.pair(host.ip); + showFlash("Pairing dialog opened…"); + onRefresh(); + } catch (e: unknown) { + showFlash(e instanceof Error ? e.message : "Pairing failed"); + } finally { + setPairing(false); + } + } + + const onlineDot = host.online ? "bg-green-400" : "bg-gray-500"; + + return ( +
+ {/* Online indicator */} + + + {/* Host icon placeholder */} +
+ 🖥 +
+ +
+

{host.name}

+

+ {host.ip}:{host.port} +

+
+ + {/* Flash message */} + {flash && ( +

{flash}

+ )} + + {/* Actions */} +
+ + +
+
+ ); +}