feat: optimize category selection and sorting logic with early returns and state management improvements

Entire-Checkpoint: 56d3e3141f61
This commit is contained in:
4gray committed 2026-03-26 19:25:19 +01:00
1 parent d85ef89893
commit cc11ddc9f9
3 files changed
+18 -4

No files matched your search

@@ -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,
});
},
@@ -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,
@@ -16,6 +16,7 @@ export class XtreamCatalogFacadeService
PortalCatalogFacade<Record<string, unknown>, Record<string, unknown>, 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, unknown>): string[] | null {
this.savedPageBeforeDetail = this.xtreamStore.page();
const xtreamId = item['xtream_id'];
if (xtreamId === undefined || xtreamId === null) {
return null;