import React, { useState, useRef } from 'react'; export default function CreateServerModal({ onClose, onSave }) { const [serverName, setServerName] = useState(''); const [serverIcon, setServerIcon] = useState(null); const[allowAnyone, setAllowAnyone] = useState(true); 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 handleCreate = () => { if (serverName.trim() === '') return; onSave(serverName.trim(), serverIcon, allowAnyone); }; return (
e.stopPropagation()}>

Create Your Hub

Give your new hub a personality with a name and an icon.

fileInputRef.current?.click()} > {serverIcon ? ( hub icon ) : (
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} autoFocus />
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.

); }