refactor: simplify input handling?

This commit is contained in:
2026-04-04 00:17:52 +08:00
parent 7501b5f592
commit 3395a315a6
4 changed files with 111 additions and 91 deletions
+3 -4
View File
@@ -4,7 +4,7 @@ import type { PromptEvent, CommandSchema, CommandParamSchema } from 'boardgame-c
interface PromptDialogProps {
prompt: PromptEvent | null;
onSubmit: (input: string) => void;
onSubmit: (input: string) => string | null | void;
onCancel: () => void;
}
@@ -36,11 +36,10 @@ export function PromptDialog({ prompt, onSubmit, onCancel }: PromptDialogProps)
const fieldValues = schemaToFields(prompt.schema).map(f => values[f.label] || '');
const cmdString = [prompt.schema.name, ...fieldValues].join(' ');
const err = prompt.tryCommit(cmdString);
if (err) {
const err = onSubmit(cmdString);
if (err != null) {
setError(err);
} else {
onSubmit(cmdString);
setValues({});
setError(null);
}