fix sort resetting to default when toggling series collapse (#3031)

This commit is contained in:
ACX
2026-02-26 09:46:13 -07:00
committed by GitHub
parent 2e5470aaff
commit 19c6abe3aa
2 changed files with 8 additions and 3 deletions
@@ -287,7 +287,7 @@ export class BookBrowserQueryParamsService {
} }
const currentParams = this.activatedRoute.snapshot.queryParams; const currentParams = this.activatedRoute.snapshot.queryParams;
const changed = Object.keys(queryParams).some(k => currentParams[k] !== queryParams[k]); const changed = Object.keys(queryParams).some(k => (queryParams[k] ?? undefined) !== (currentParams[k] ?? undefined));
if (changed) { if (changed) {
const mergedParams = {...currentParams, ...queryParams}; const mergedParams = {...currentParams, ...queryParams};
@@ -470,8 +470,13 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy {
this.visibleSortOptions = visibleFields.map(f => sortOptionsByField.get(f)).filter((o): o is SortOption => !!o); this.visibleSortOptions = visibleFields.map(f => sortOptionsByField.get(f)).filter((o): o is SortOption => !!o);
// Only update sort criteria if they actually changed to avoid resetting popover/CDK state // Only update sort criteria if they actually changed to avoid resetting popover/CDK state.
if (!this.areSortCriteriaEqual(this.bookSorter.selectedSortCriteria, parseResult.sortCriteria)) { // Skip preference-based sort re-derivation when sort is already established (prevents
// userState$ emissions from non-sort preference changes like seriesCollapsed from
// resetting the sort during the race window before syncQueryParams writes to URL).
const sortFromUrl = !!queryParamMap.get('sort');
const sortNotYetEstablished = this.bookSorter.selectedSortCriteria.length === 0;
if ((sortFromUrl || sortNotYetEstablished) && !this.areSortCriteriaEqual(this.bookSorter.selectedSortCriteria, parseResult.sortCriteria)) {
this.bookSorter.setSortCriteria(parseResult.sortCriteria); this.bookSorter.setSortCriteria(parseResult.sortCriteria);
} }
this.currentViewMode = parseResult.viewMode; this.currentViewMode = parseResult.viewMode;