Skip to content

Commit 19c6abe

Browse files
authored
fix sort resetting to default when toggling series collapse (#3031)
1 parent 2e5470a commit 19c6abe

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

booklore-ui/src/app/features/book/components/book-browser/book-browser-query-params.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export class BookBrowserQueryParamsService {
287287
}
288288

289289
const currentParams = this.activatedRoute.snapshot.queryParams;
290-
const changed = Object.keys(queryParams).some(k => currentParams[k] !== queryParams[k]);
290+
const changed = Object.keys(queryParams).some(k => (queryParams[k] ?? undefined) !== (currentParams[k] ?? undefined));
291291

292292
if (changed) {
293293
const mergedParams = {...currentParams, ...queryParams};

booklore-ui/src/app/features/book/components/book-browser/book-browser.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,13 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy {
470470
this.visibleSortOptions = visibleFields.map(f => sortOptionsByField.get(f)).filter((o): o is SortOption => !!o);
471471

472472

473-
// Only update sort criteria if they actually changed to avoid resetting popover/CDK state
474-
if (!this.areSortCriteriaEqual(this.bookSorter.selectedSortCriteria, parseResult.sortCriteria)) {
473+
// Only update sort criteria if they actually changed to avoid resetting popover/CDK state.
474+
// Skip preference-based sort re-derivation when sort is already established (prevents
475+
// userState$ emissions from non-sort preference changes like seriesCollapsed from
476+
// resetting the sort during the race window before syncQueryParams writes to URL).
477+
const sortFromUrl = !!queryParamMap.get('sort');
478+
const sortNotYetEstablished = this.bookSorter.selectedSortCriteria.length === 0;
479+
if ((sortFromUrl || sortNotYetEstablished) && !this.areSortCriteriaEqual(this.bookSorter.selectedSortCriteria, parseResult.sortCriteria)) {
475480
this.bookSorter.setSortCriteria(parseResult.sortCriteria);
476481
}
477482
this.currentViewMode = parseResult.viewMode;

0 commit comments

Comments
 (0)