refactor: update submit handlers to return boolean for success indication in label and post dialogs
Some checks failed
Frontend CI / build (push) Failing after 55s
Auto Comment On PR / add_improve_comment (pull_request) Successful in 16s
PR Title Check / pr-title-check (pull_request) Successful in 17s

This commit is contained in:
SquidSpirit 2025-10-15 12:08:17 +08:00
parent f6eece7071
commit 9b33ea6c7a
4 changed files with 20 additions and 6 deletions

View File

@ -30,7 +30,7 @@
onSubmit: createLabel, onSubmit: createLabel,
}: { }: {
disabled: boolean; disabled: boolean;
onSubmit: (params: FormParams) => Promise<void>; onSubmit: (params: FormParams) => Promise<boolean>;
} = $props(); } = $props();
let open = $state(false); let open = $state(false);
@ -62,7 +62,11 @@
return; return;
} }
await createLabel(formData); const isSuccess = await createLabel(formData);
if (!isSuccess) {
return;
}
formData = { formData = {
name: '', name: '',
color: '#dddddd', color: '#dddddd',

View File

@ -23,7 +23,7 @@
const labelsListedState = $derived($labelsListedStore); const labelsListedState = $derived($labelsListedStore);
const { trigger: loadLabels } = labelsListedStore; const { trigger: loadLabels } = labelsListedStore;
async function onCreateLabelDialogSubmit(params: CreateLabelDialogFormParams) { async function onCreateLabelDialogSubmit(params: CreateLabelDialogFormParams): Promise<boolean> {
const colorViewModel = ColorViewModel.fromHex(params.color); const colorViewModel = ColorViewModel.fromHex(params.color);
const color = colorViewModel.toEntity(); const color = colorViewModel.toEntity();
@ -39,7 +39,10 @@
toast.error('Failed to create label', { toast.error('Failed to create label', {
description: state.error.message, description: state.error.message,
}); });
return false;
} }
return true;
} }
onMount(() => loadLabels()); onMount(() => loadLabels());

View File

@ -30,7 +30,7 @@
onSubmit: createPost, onSubmit: createPost,
}: { }: {
disabled: boolean; disabled: boolean;
onSubmit: (params: FormParams) => Promise<void>; onSubmit: (params: FormParams) => Promise<boolean>;
} = $props(); } = $props();
let open = $state(false); let open = $state(false);
@ -50,7 +50,11 @@
return; return;
} }
await createPost(formData); const isSuccess = await createPost(formData);
if (!isSuccess) {
return;
}
formData = { semanticId: '', title: '' }; formData = { semanticId: '', title: '' };
open = false; open = false;
} }

View File

@ -22,7 +22,7 @@
const postsListedState = $derived($postsListedStore); const postsListedState = $derived($postsListedStore);
const { trigger: loadPosts } = postsListedStore; const { trigger: loadPosts } = postsListedStore;
async function onCreatePostDialogSubmit(params: CreatePostDialogFormParams) { async function onCreatePostDialogSubmit(params: CreatePostDialogFormParams): Promise<boolean> {
const state = await createPost(params); const state = await createPost(params);
if (state.isSuccess()) { if (state.isSuccess()) {
@ -32,7 +32,10 @@
toast.error('Failed to create post', { toast.error('Failed to create post', {
description: state.error.message, description: state.error.message,
}); });
return false;
} }
return true;
} }
onMount(() => loadPosts({ showUnpublished: true })); onMount(() => loadPosts({ showUnpublished: true }));