import clsx from 'clsx'; import { Dialog, DialogPanel, DialogTitle, Button, Input, Label, Field } from '@headlessui/react'; import { useOptions } from '/src/utils/optionsContext'; import { useState, useEffect } from 'react'; const PanicKeyDialog = ({ state, set }) => { const { options, updateOption } = useOptions(); const [form, setForm] = useState({ key: '', url: '', }); useEffect(() => { if (state) { const saved = options.panic || { key: '', url: '' }; setForm(saved); } }, [state, options.panic]); useEffect(() => { const handleKeyDown = (e) => { e.preventDefault(); let combo = []; if (e.ctrlKey) combo.push('Ctrl'); if (e.altKey) combo.push('Alt'); if (e.shiftKey) combo.push('Shift'); if (e.metaKey) combo.push('Meta'); combo.push(e.key.length === 1 ? e.key.toUpperCase() : e.key); setForm((prev) => ({ ...prev, key: combo.join('+') })); }; const input = document.getElementById('panic-key-input'); if (input) { input.addEventListener('keydown', handleKeyDown); } return () => { if (input) input.removeEventListener('keydown', handleKeyDown); }; }, []); const regex = (link) => (/^(https?:)?\/\//.test(link) ? link : `https://${link}`); const action = () => { set(false); updateOption({ panic: { key: form.key, url: regex(form.url.trim()), }, }); location.reload(); }; const filled = form.key && form.url; return ( set(false)} className="fixed inset-0 bg-black/40 z-50">
Set Panic Key {}} // block typing /> setForm({ ...form, url: e.target.value })} />
); }; export default PanicKeyDialog;