From cc11ddc9f9eed5e795f98d6efe75f01cfb20c789 Mon Sep 17 00:00:00 2001 From: 4gray Date: Thu, 26 Mar 2026 19:25:19 +0100 Subject: [PATCH] feat: optimize category selection and sorting logic with early returns and state management improvements Entire-Checkpoint: 56d3e3141f61 --- .../stores/features/with-stalker-selection.feature.ts | 8 ++++++-- .../src/lib/stores/features/with-selection.feature.ts | 3 +++ .../feature/src/lib/xtream-catalog-facade.service.ts | 11 +++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/libs/portal/stalker/data-access/src/lib/stores/features/with-stalker-selection.feature.ts b/libs/portal/stalker/data-access/src/lib/stores/features/with-stalker-selection.feature.ts index 33beafe27..5272ef698 100644 --- a/libs/portal/stalker/data-access/src/lib/stores/features/with-stalker-selection.feature.ts +++ b/libs/portal/stalker/data-access/src/lib/stores/features/with-stalker-selection.feature.ts @@ -49,9 +49,13 @@ export function withStalkerSelection() { patchState(store, { selectedContentType: type }); }, setSelectedCategory(id: string | number | null) { + const newId = + id !== null && id !== undefined ? String(id) : null; + if (store.selectedCategoryId() === newId) { + return; + } patchState(store, { - selectedCategoryId: - id !== null && id !== undefined ? String(id) : null, + selectedCategoryId: newId, page: 0, }); }, diff --git a/libs/portal/xtream/data-access/src/lib/stores/features/with-selection.feature.ts b/libs/portal/xtream/data-access/src/lib/stores/features/with-selection.feature.ts index 376ffbe58..8f9e61c59 100644 --- a/libs/portal/xtream/data-access/src/lib/stores/features/with-selection.feature.ts +++ b/libs/portal/xtream/data-access/src/lib/stores/features/with-selection.feature.ts @@ -457,6 +457,9 @@ export function withSelection() { * Set category content sort mode */ setContentSortMode(mode: XtreamCategorySortMode): void { + if (store.contentSortMode() === mode) { + return; + } patchState(store, { contentSortMode: mode, page: 0, diff --git a/libs/portal/xtream/feature/src/lib/xtream-catalog-facade.service.ts b/libs/portal/xtream/feature/src/lib/xtream-catalog-facade.service.ts index 964ef5271..7d6e8d923 100644 --- a/libs/portal/xtream/feature/src/lib/xtream-catalog-facade.service.ts +++ b/libs/portal/xtream/feature/src/lib/xtream-catalog-facade.service.ts @@ -16,6 +16,7 @@ export class XtreamCatalogFacadeService PortalCatalogFacade, Record, unknown> { private readonly xtreamStore = inject(XtreamStore); + private savedPageBeforeDetail: number | null = null; readonly provider = 'xtream' as const; readonly pageSizeOptions = [10, 25, 50, 100] as const; @@ -68,10 +69,14 @@ export class XtreamCatalogFacadeService if (categoryId) { this.xtreamStore.setSelectedCategory(Number(categoryId)); - return; + } else { + this.xtreamStore.setSelectedCategory(null); } - this.xtreamStore.setSelectedCategory(null); + if (this.savedPageBeforeDetail !== null) { + this.xtreamStore.setPage(this.savedPageBeforeDetail); + this.savedPageBeforeDetail = null; + } } clearSelectedItem(): void { @@ -92,6 +97,8 @@ export class XtreamCatalogFacadeService } selectItem(item: Record): string[] | null { + this.savedPageBeforeDetail = this.xtreamStore.page(); + const xtreamId = item['xtream_id']; if (xtreamId === undefined || xtreamId === null) { return null;