fix: reset loading flags on error in scriptGeneratorStore

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
chihlasm
2026-03-13 02:06:06 -04:00
parent 9d10aa90ad
commit 054f3acd67

View File

@@ -65,6 +65,7 @@ export const useScriptGeneratorStore = create<ScriptGeneratorState>()((set, get)
loadTemplates: async () => {
set({ isLoadingTemplates: true })
try {
const { activeCategoryId, categories, searchQuery } = get()
const category = categories.find(c => c.id === activeCategoryId)
const params: { category_slug?: string; search?: string } = {}
@@ -72,10 +73,14 @@ export const useScriptGeneratorStore = create<ScriptGeneratorState>()((set, get)
if (searchQuery) params.search = searchQuery
const templates = await scriptsApi.getTemplates(params)
set({ templates, isLoadingTemplates: false })
} catch {
set({ isLoadingTemplates: false })
}
},
selectTemplate: async (id: string) => {
set({ isLoadingDetail: true })
try {
const detail = await scriptsApi.getTemplateDetail(id)
// Populate paramValues from parameter defaults
const schema = detail.parameters_schema as ScriptParametersSchema
@@ -97,6 +102,9 @@ export const useScriptGeneratorStore = create<ScriptGeneratorState>()((set, get)
generateError: null,
isLoadingDetail: false,
})
} catch {
set({ isLoadingDetail: false })
}
},
setCategory: (id: string | null) => {