import React, { useState, useRef } from 'react'; import { network } from '../p2p/index.js'; export default function ServerSettingsModal({ onClose, activeServerObj, onDeleteServer }) { const [serverName, setServerName] = useState(activeServerObj.name || ''); const [serverIcon, setServerIcon] = useState(activeServerObj.icon || null); const[allowAnyone, setAllowAnyone] = useState(activeServerObj.allowAnyoneToInvite); const fileInputRef = useRef(null); const handleImageUpload = (e) => { const file = e.target.files[0]; if (!file) return; const reader = new FileReader(); reader.onload = (event) => { const img = new Image(); img.onload = () => { const canvas = document.createElement('canvas'); const MAX_SIZE = 128; let width = img.width; let height = img.height; if (width > height) { if (width > MAX_SIZE) { height *= MAX_SIZE / width; width = MAX_SIZE; } } else { if (height > MAX_SIZE) { width *= MAX_SIZE / height; height = MAX_SIZE; } } canvas.width = width; canvas.height = height; const ctx = canvas.getContext('2d'); ctx.drawImage(img, 0, 0, width, height); const dataUrl = canvas.toDataURL(file.type === 'image/png' ? 'image/png' : 'image/jpeg', 0.8); setServerIcon(dataUrl); }; img.src = event.target.result; }; reader.readAsDataURL(file); }; const handleSave = () => { if (serverName.trim() === '') return; network.updateServerSettings(activeServerObj.topicHex, serverName.trim(), serverIcon, allowAnyone); onClose(); }; const handleDelete = () => { if (window.confirm("Are you sure you want to completely delete this hub? All members will be removed and message history will be permanently wiped for everyone. This cannot be undone.")) { onDeleteServer(); } }; return (
e.stopPropagation()}>

Hub Settings

fileInputRef.current?.click()} > {serverIcon ? ( hub icon ) : (
Change
)}
Upload
setServerName(e.target.value)} className="w-full bg-panel text-text rounded p-3 outline-none focus:ring-2 focus:ring-accent mb-4" placeholder="e.g. My Cool Club" maxLength={32} />
setAllowAnyone(e.target.checked)} className="w-5 h-5 accent-accent cursor-pointer" /> Anyone can invite people to this hub

If unchecked, only you (the Admin) can send invites.

Danger Zone

); }