fix: reset loading state when prompt save fails

When onSubmit throws an error (e.g. network failure), the loading
flag was left as true, permanently disabling the Save button and
showing an infinite spinner with no user feedback.

Wrap the onSubmit call in try/catch so loading is always reset to
false and an error toast is shown to the user on failure.
This commit is contained in:
Extra Small 2026-04-08 09:08:51 -07:00
parent 9bd84258d0
commit bd71938b71

View file

@ -82,23 +82,28 @@
loading = true;
if (validateCommandString(command)) {
await onSubmit({
id: prompt?.id,
name,
command,
content,
tags: tags.map((tag) => tag.name),
access_grants: accessGrants,
commit_message: commitMessage || undefined,
is_production: isProduction
});
showEditModal = false;
commitMessage = '';
isProduction = true;
await loadHistory(true); // Reset and reload
// Select the newest version after saving
if (history.length > 0) {
selectedHistoryEntry = history[0];
try {
await onSubmit({
id: prompt?.id,
name,
command,
content,
tags: tags.map((tag) => tag.name),
access_grants: accessGrants,
commit_message: commitMessage || undefined,
is_production: isProduction
});
showEditModal = false;
commitMessage = '';
isProduction = true;
await loadHistory(true); // Reset and reload
// Select the newest version after saving
if (history.length > 0) {
selectedHistoryEntry = history[0];
}
} catch (e) {
console.error('Failed to save prompt:', e);
toast.error($i18n.t('Failed to save prompt. Please try again.'));
}
} else {
toast.error(