diff --git a/bricktracker/minifigure_list.py b/bricktracker/minifigure_list.py index f45a22b..35bafad 100644 --- a/bricktracker/minifigure_list.py +++ b/bricktracker/minifigure_list.py @@ -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 diff --git a/bricktracker/views/minifigure.py b/bricktracker/views/minifigure.py index 0a290a2..7fbb833 100644 --- a/bricktracker/views/minifigure.py +++ b/bricktracker/views/minifigure.py @@ -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 diff --git a/static/scripts/minifigures.js b/static/scripts/minifigures.js index 4984c8b..8924cb4 100644 --- a/static/scripts/minifigures.js +++ b/static/scripts/minifigures.js @@ -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