import { useState } from "react"; import { CharacterParams, CharacterRole } from "../network/models"; import { network } from "../network/network"; import showToast from "./toast"; import { useTranslation } from "../utils/i18n"; import Button from "./button"; export default function CharacterEditer({character, setCharacter, onDelete}: { character: CharacterParams; setCharacter: (character: CharacterParams) => void; onDelete: () => void; }) { const { t } = useTranslation(); const [isUploading, setUploading] = useState(false); const uploadImage = async () => { const input = document.createElement("input"); input.type = "file"; input.accept = "image/*"; input.onchange = async () => { if (!input.files || input.files.length === 0) { return; } setUploading(true); const file = input.files[0]; const result = await network.uploadImage(file); setUploading(false); if (result.success) { setCharacter({ ...character, image: result.data!, }); } else { showToast({ type: "error", message: `Failed to upload image`, }) } }; input.click(); } return