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 () => {
|
loadTemplates: async () => {
|
||||||
set({ isLoadingTemplates: true })
|
set({ isLoadingTemplates: true })
|
||||||
const { activeCategoryId, categories, searchQuery } = get()
|
try {
|
||||||
const category = categories.find(c => c.id === activeCategoryId)
|
const { activeCategoryId, categories, searchQuery } = get()
|
||||||
const params: { category_slug?: string; search?: string } = {}
|
const category = categories.find(c => c.id === activeCategoryId)
|
||||||
if (category) params.category_slug = category.slug
|
const params: { category_slug?: string; search?: string } = {}
|
||||||
if (searchQuery) params.search = searchQuery
|
if (category) params.category_slug = category.slug
|
||||||
const templates = await scriptsApi.getTemplates(params)
|
if (searchQuery) params.search = searchQuery
|
||||||
set({ templates, isLoadingTemplates: false })
|
const templates = await scriptsApi.getTemplates(params)
|
||||||
|
set({ templates, isLoadingTemplates: false })
|
||||||
|
} catch {
|
||||||
|
set({ isLoadingTemplates: false })
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
selectTemplate: async (id: string) => {
|
selectTemplate: async (id: string) => {
|
||||||
set({ isLoadingDetail: true })
|
set({ isLoadingDetail: true })
|
||||||
const detail = await scriptsApi.getTemplateDetail(id)
|
try {
|
||||||
// Populate paramValues from parameter defaults
|
const detail = await scriptsApi.getTemplateDetail(id)
|
||||||
const schema = detail.parameters_schema as ScriptParametersSchema
|
// Populate paramValues from parameter defaults
|
||||||
const parameters = schema?.parameters ?? []
|
const schema = detail.parameters_schema as ScriptParametersSchema
|
||||||
const paramValues: Record<string, string> = {}
|
const parameters = schema?.parameters ?? []
|
||||||
for (const param of parameters) {
|
const paramValues: Record<string, string> = {}
|
||||||
const d = param.default
|
for (const param of parameters) {
|
||||||
if (d === null || d === undefined) paramValues[param.key] = ''
|
const d = param.default
|
||||||
else if (typeof d === 'boolean') paramValues[param.key] = d ? 'true' : 'false'
|
if (d === null || d === undefined) paramValues[param.key] = ''
|
||||||
else paramValues[param.key] = String(d)
|
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) => {
|
setCategory: (id: string | null) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user