import { useState, useEffect } from 'react'; import { ChevronLeft, ChevronRight, ClipboardList, Bell, Info } from 'lucide-react'; import { api } from '@/lib/api'; import { AdapterIcon } from './AdapterIcon'; import { SavedInstructionsView } from './SavedInstructionsView'; import { AdapterSettingsSection } from './AdapterSettingsSection'; import { usePushNotifications } from '@/hooks/usePushNotifications'; interface Adapter { id: string; displayName: string; available: boolean; } export function SettingsView({ onBack }: { onBack: () => void }) { const [subView, setSubView] = useState<'main' | 'instructions' | string>('main'); const [adapters, setAdapters] = useState([]); const [version, setVersion] = useState(''); const { supported, subscribed, subscribe, unsubscribe } = usePushNotifications(); const [toggling, setToggling] = useState(false); useEffect(() => { api.adapters().then(setAdapters).catch(() => {}); fetch('/api/health') .then(r => r.json()) .then((data: { version: string }) => setVersion(data.version)) .catch(() => {}); }, []); if (subView === 'instructions') { return setSubView('main')} />; } const matchedAdapter = adapters.find(a => a.id === subView); if (matchedAdapter) { return setSubView('main')} />; } const handleNotificationToggle = async () => { if (toggling) return; setToggling(true); try { if (subscribed) { await unsubscribe(); } else { await subscribe(); } } finally { setToggling(false); } }; const availableAdapters = adapters.filter(a => a.available); return (
{/* Header */}
Settings
{/* Main list */}
{/* Saved Instructions */} {/* Per-adapter rows */} {availableAdapters.map(adapter => ( ))} {/* Notifications */} {supported && (
Notifications
)} {/* About */}
About {version ? `ClawTap v${version}` : 'ClawTap'}
); }