import { useState } from 'react'; import { Wifi, Trash2, Scan } from 'lucide-react'; import WiFiScanOverlay from './WiFiScanOverlay'; import { toast } from 'sonner'; interface NetworkPageProps { config: any; setConfig: (config: any) => void; } export default function NetworkPage({ config, setConfig }: NetworkPageProps) { const [showWiFiScan, setShowWiFiScan] = useState(false); const updateSetting = (path: string[], value: any) => { const newConfig = JSON.parse(JSON.stringify(config)); let current = newConfig; for (let i = 0; i < path.length - 1; i++) { current = current[path[i]]; } current[path[path.length - 1]] = value; setConfig(newConfig); }; const network = config.network || {}; const bluetooth = config.bluetooth || {}; const wifi = config.wifi || []; const removeWifiNetwork = (index: number) => { const network = wifi[index]; const newWifi = wifi.filter((_: any, i: number) => i !== index); updateSetting(['wifi'], newWifi); toast.success(`Removed ${network.ssid}`); }; const addWifiNetwork = (ssid: string, passphrase: string) => { // Disconnect all existing networks const updatedWifi = wifi.map((network: any) => ({ ...network, enabled: 0 })); // Add new network at the top with enabled status const newWifi = [{ ssid, passphrase, enabled: 1 }, ...updatedWifi]; updateSetting(['wifi'], newWifi); }; return (

Known WiFi Networks

{wifi.map((network: any, index: number) => (
{network.ssid}
{network.enabled === 1 && (
Connected
)}
))} {wifi.length === 0 && (
No WiFi networks configured
)}
{showWiFiScan && ( setShowWiFiScan(false)} onNetworkAdded={addWifiNetwork} existingNetworks={wifi.map((n: any) => n.ssid)} /> )}

Network

updateSetting(['network', 'hostname'], e.target.value)} className="w-full px-3 py-2 border border-neutral-300 rounded-lg" />
updateSetting(['network', 'sntpserver'], e.target.value)} className="w-full px-3 py-2 border border-neutral-300 rounded-lg" />

Bluetooth

updateSetting(['bluetooth', 'devicename'], e.target.value)} className="w-full px-3 py-2 border border-neutral-300 rounded-lg" />
updateSetting(['bluetooth', 'baud'], parseInt(e.target.value))} className="w-full px-3 py-2 border border-neutral-300 rounded-lg" />
); }