refactor: simplify input handling?
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user