fix: preserve tab ownership filter across category and search changes in script library
setCategory and setSearch called loadTemplates() with no arguments, dropping the mine/shared filter set by the active tab — causing the list to show all templates instead of the current user's scripts after any filter interaction. Store now persists tabFilters whenever loadTemplates is called with explicit filters, and reuses them for subsequent no-arg calls from setCategory/setSearch. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,7 @@ interface ScriptGeneratorState {
|
||||
selectedTemplate: ScriptTemplateDetail | null
|
||||
searchQuery: string
|
||||
activeCategoryId: string | null // null = "All"
|
||||
tabFilters: { mine?: boolean; shared?: boolean } // current tab's ownership filter
|
||||
isLoadingTemplates: boolean // drives skeleton in ScriptTemplateList
|
||||
isLoadingDetail: boolean // drives spinner in ScriptConfigurePane
|
||||
|
||||
@@ -48,6 +49,7 @@ export const useScriptGeneratorStore = create<ScriptGeneratorState>()((set, get)
|
||||
selectedTemplate: null,
|
||||
searchQuery: '',
|
||||
activeCategoryId: null,
|
||||
tabFilters: {},
|
||||
isLoadingTemplates: false,
|
||||
isLoadingDetail: false,
|
||||
paramValues: {},
|
||||
@@ -68,6 +70,10 @@ export const useScriptGeneratorStore = create<ScriptGeneratorState>()((set, get)
|
||||
},
|
||||
|
||||
loadTemplates: async (filters) => {
|
||||
// When filters are provided (e.g. tab change), persist them so that
|
||||
// subsequent setCategory/setSearch calls reuse the same ownership filter.
|
||||
const resolvedFilters = filters !== undefined ? filters : get().tabFilters
|
||||
if (filters !== undefined) set({ tabFilters: filters })
|
||||
set({ isLoadingTemplates: true })
|
||||
try {
|
||||
const { activeCategoryId, categories, searchQuery } = get()
|
||||
@@ -75,8 +81,8 @@ export const useScriptGeneratorStore = create<ScriptGeneratorState>()((set, get)
|
||||
const params: { category_slug?: string; search?: string; mine?: boolean; shared?: boolean } = {}
|
||||
if (category) params.category_slug = category.slug
|
||||
if (searchQuery) params.search = searchQuery
|
||||
if (filters?.mine) params.mine = true
|
||||
if (filters?.shared) params.shared = true
|
||||
if (resolvedFilters.mine) params.mine = true
|
||||
if (resolvedFilters.shared) params.shared = true
|
||||
const templates = await scriptsApi.getTemplates(params)
|
||||
set({ templates, isLoadingTemplates: false })
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user