fix: reset loading flags on error in scriptGeneratorStore
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -65,38 +65,46 @@ export const useScriptGeneratorStore = create<ScriptGeneratorState>()((set, get)
|
||||
|
||||
loadTemplates: async () => {
|
||||
set({ isLoadingTemplates: true })
|
||||
const { activeCategoryId, categories, searchQuery } = get()
|
||||
const category = categories.find(c => c.id === activeCategoryId)
|
||||
const params: { category_slug?: string; search?: string } = {}
|
||||
if (category) params.category_slug = category.slug
|
||||
if (searchQuery) params.search = searchQuery
|
||||
const templates = await scriptsApi.getTemplates(params)
|
||||
set({ templates, isLoadingTemplates: false })
|
||||
try {
|
||||
const { activeCategoryId, categories, searchQuery } = get()
|
||||
const category = categories.find(c => c.id === activeCategoryId)
|
||||
const params: { category_slug?: string; search?: string } = {}
|
||||
if (category) params.category_slug = category.slug
|
||||
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 })
|
||||
const detail = await scriptsApi.getTemplateDetail(id)
|
||||
// Populate paramValues from parameter defaults
|
||||
const schema = detail.parameters_schema as ScriptParametersSchema
|
||||
const parameters = schema?.parameters ?? []
|
||||
const paramValues: Record<string, string> = {}
|
||||
for (const param of parameters) {
|
||||
const d = param.default
|
||||
if (d === null || d === undefined) paramValues[param.key] = ''
|
||||
else if (typeof d === 'boolean') paramValues[param.key] = d ? 'true' : 'false'
|
||||
else paramValues[param.key] = String(d)
|
||||
try {
|
||||
const detail = await scriptsApi.getTemplateDetail(id)
|
||||
// Populate paramValues from parameter defaults
|
||||
const schema = detail.parameters_schema as ScriptParametersSchema
|
||||
const parameters = schema?.parameters ?? []
|
||||
const paramValues: Record<string, string> = {}
|
||||
for (const param of parameters) {
|
||||
const d = param.default
|
||||
if (d === null || d === undefined) paramValues[param.key] = ''
|
||||
else if (typeof d === 'boolean') paramValues[param.key] = d ? 'true' : 'false'
|
||||
else paramValues[param.key] = String(d)
|
||||
}
|
||||
set({
|
||||
selectedTemplate: detail,
|
||||
paramValues,
|
||||
formErrors: {},
|
||||
generatedScript: null,
|
||||
generationId: null,
|
||||
generationWarnings: [],
|
||||
generateError: null,
|
||||
isLoadingDetail: false,
|
||||
})
|
||||
} catch {
|
||||
set({ isLoadingDetail: false })
|
||||
}
|
||||
set({
|
||||
selectedTemplate: detail,
|
||||
paramValues,
|
||||
formErrors: {},
|
||||
generatedScript: null,
|
||||
generationId: null,
|
||||
generationWarnings: [],
|
||||
generateError: null,
|
||||
isLoadingDetail: false,
|
||||
})
|
||||
},
|
||||
|
||||
setCategory: (id: string | null) => {
|
||||
|
||||
Reference in New Issue
Block a user