import { useState, useEffect } from 'react'; import { api } from '../utils/api.js'; import { useToast } from '../contexts/ToastContext.jsx'; export default function SettingsModal({ onClose }) { const toast = useToast(); const [vapidPublic, setVapidPublic] = useState(''); const [loading, setLoading] = useState(true); const [generating, setGenerating] = useState(false); const [showRegenWarning, setShowRegenWarning] = useState(false); useEffect(() => { api.getSettings().then(({ settings }) => { setVapidPublic(settings.vapid_public || ''); setLoading(false); }).catch(() => setLoading(false)); }, []); const doGenerate = async () => { setGenerating(true); setShowRegenWarning(false); try { const { publicKey } = await api.generateVapidKeys(); setVapidPublic(publicKey); toast('VAPID keys generated. Push notifications are now active.', 'success'); } catch (e) { toast(e.message || 'Failed to generate keys', 'error'); } finally { setGenerating(false); } }; const handleGenerateClick = () => { if (vapidPublic) { setShowRegenWarning(true); } else { doGenerate(); } }; return (
e.target === e.currentTarget && onClose()}>

Settings

Web Push Notifications (VAPID)
{loading ? (

Loading…

) : ( <> {vapidPublic ? (
Public Key
{vapidPublic}
Push notifications active
) : (

No VAPID keys found. Generate keys to enable Web Push notifications — users can then receive alerts when the app is closed or in the background.

)} {showRegenWarning && (

⚠️ Regenerate VAPID keys?

Generating new keys will invalidate all existing push subscriptions. Every user will stop receiving push notifications immediately and will need to re-enable them by opening the app. This cannot be undone.

)} {!showRegenWarning && ( )}

Requires HTTPS. After generating, users will be prompted to enable notifications on their next visit. On iOS, the app must be installed to the home screen first.

)}
); }