fix(minifigures): fix filter on client side pagination

This commit is contained in:
2025-12-18 21:53:19 -05:00
parent 7f9a7a2afe
commit 349648969c
3 changed files with 19 additions and 12 deletions

View File

@@ -44,7 +44,11 @@ class BrickMinifigureList(BrickRecordList[BrickMinifigure]):
return self
# Load all minifigures with problems filter
def all_filtered(self, /, problems_filter: str = 'all', theme_id: str = 'all', year: str = 'all') -> Self:
def all_filtered(self, /, owner_id: str | None = None, problems_filter: str = 'all', theme_id: str = 'all', year: str = 'all') -> Self:
# Save the owner_id parameter
if owner_id is not None:
self.fields.owner_id = owner_id
context = {}
if problems_filter and problems_filter != 'all':
context['problems_filter'] = problems_filter
@@ -53,7 +57,13 @@ class BrickMinifigureList(BrickRecordList[BrickMinifigure]):
if year and year != 'all':
context['year'] = year
self.list(override_query=self.all_query, **context)
# Choose query based on whether owner filtering is needed
if owner_id and owner_id != 'all':
query = self.all_by_owner_query
else:
query = self.all_query
self.list(override_query=query, **context)
return self
# Load all minifigures by owner

View File

@@ -42,10 +42,7 @@ def list() -> str:
pagination_context = build_pagination_context(page, per_page, total_count, is_mobile)
else:
# ORIGINAL MODE - Single page with all data for client-side search
if owner_id == 'all' or owner_id is None or owner_id == '':
minifigures = BrickMinifigureList().all_filtered(problems_filter=problems_filter, theme_id=theme_id, year=year)
else:
minifigures = BrickMinifigureList().all_by_owner_filtered(owner_id=owner_id, problems_filter=problems_filter, theme_id=theme_id, year=year)
minifigures = BrickMinifigureList().all_filtered(owner_id=owner_id, problems_filter=problems_filter, theme_id=theme_id, year=year)
pagination_context = None

View File

@@ -53,15 +53,15 @@ function applyFilters() {
}
}
// Only reset to page 1 when filtering in server-side pagination mode
// Reset to page 1 when filtering in server-side pagination mode
if (isPaginationMode()) {
currentUrl.searchParams.set('page', '1');
// Navigate to updated URL (server-side pagination)
window.location.href = currentUrl.toString();
} else {
// Client-side mode: Update URL without page reload
window.history.replaceState({}, '', currentUrl.toString());
}
// Navigate to updated URL (reload page with new filters)
// This works for both pagination and client-side modes
// because backend applies filters even in client-side mode
window.location.href = currentUrl.toString();
}
// Legacy function for compatibility