mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-14 05:06:16 -08:00
fix: reset catalog pagination on search
Entire-Checkpoint: f957cd9849e0
This commit is contained in:
1 parent
1a09e696b4
commit
568c03fe0e
5 files changed
+219
-3
No files matched your search
+58
@@ -214,6 +214,64 @@ describe('CategoryContentViewComponent', () => {
|
||||
expect(catalog.setPage).toHaveBeenCalledWith(2);
|
||||
});
|
||||
|
||||
it('preserves the initial search and page query params on direct route loads', () => {
|
||||
queryParamMap$.next(
|
||||
convertToParamMap({
|
||||
q: 'matrix',
|
||||
page: '3',
|
||||
})
|
||||
);
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(catalog.setSearchQuery).toHaveBeenCalledWith('matrix');
|
||||
expect(catalog.setPage).toHaveBeenCalledWith(2);
|
||||
expect(router.navigate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('resets to the first page and removes stale page query params when search changes', () => {
|
||||
fixture.detectChanges();
|
||||
catalog.setPage.mockClear();
|
||||
|
||||
queryParamMap$.next(
|
||||
convertToParamMap({
|
||||
q: 'matrix',
|
||||
page: '3',
|
||||
})
|
||||
);
|
||||
|
||||
expect(catalog.setSearchQuery).toHaveBeenCalledWith('matrix');
|
||||
expect(catalog.setPage).toHaveBeenCalledWith(0);
|
||||
expect(router.navigate).toHaveBeenCalledWith([], {
|
||||
relativeTo: expect.any(Object),
|
||||
queryParams: {
|
||||
page: null,
|
||||
},
|
||||
queryParamsHandling: 'merge',
|
||||
replaceUrl: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('restores page changes while the search query is unchanged', () => {
|
||||
queryParamMap$.next(
|
||||
convertToParamMap({
|
||||
q: 'matrix',
|
||||
})
|
||||
);
|
||||
fixture.detectChanges();
|
||||
catalog.setPage.mockClear();
|
||||
|
||||
queryParamMap$.next(
|
||||
convertToParamMap({
|
||||
q: 'matrix',
|
||||
page: '3',
|
||||
})
|
||||
);
|
||||
|
||||
expect(catalog.setPage).toHaveBeenCalledWith(2);
|
||||
expect(router.navigate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('falls back to the first catalog page when the page query param is absent or invalid', () => {
|
||||
fixture.detectChanges();
|
||||
catalog.setPage.mockClear();
|
||||
|
||||
+38
-2
@@ -64,6 +64,8 @@ export class CategoryContentViewComponent implements OnInit {
|
||||
private readonly hostElement = inject(ElementRef<HTMLElement>);
|
||||
private readonly router = inject(Router);
|
||||
private readonly translate = inject(TranslateService);
|
||||
private hasAppliedInitialQueryParams = false;
|
||||
private previousSearchQuery: string | null = null;
|
||||
private readonly catalog = inject(
|
||||
PORTAL_CATALOG_FACADE
|
||||
) as PortalCatalogFacade<
|
||||
@@ -130,8 +132,31 @@ export class CategoryContentViewComponent implements OnInit {
|
||||
this.activatedRoute.queryParamMap
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe((params) => {
|
||||
this.catalog.setSearchQuery?.(params.get('q') ?? '');
|
||||
this.catalog.setPage(this.toPageIndex(params.get('page')));
|
||||
const searchQuery = params.get('q') ?? '';
|
||||
const pageIndex = this.toPageIndex(params.get('page'));
|
||||
|
||||
this.catalog.setSearchQuery?.(searchQuery);
|
||||
|
||||
if (!this.hasAppliedInitialQueryParams) {
|
||||
this.hasAppliedInitialQueryParams = true;
|
||||
this.previousSearchQuery = searchQuery;
|
||||
this.catalog.setPage(pageIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
const didSearchChange =
|
||||
searchQuery !== this.previousSearchQuery;
|
||||
this.previousSearchQuery = searchQuery;
|
||||
|
||||
if (didSearchChange) {
|
||||
this.catalog.setPage(0);
|
||||
if (params.has('page')) {
|
||||
this.clearPageQueryParam();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
this.catalog.setPage(pageIndex);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -172,6 +197,17 @@ export class CategoryContentViewComponent implements OnInit {
|
||||
gridList?.scrollTo?.({ top: 0 });
|
||||
}
|
||||
|
||||
private clearPageQueryParam(): void {
|
||||
void this.router.navigate([], {
|
||||
relativeTo: this.activatedRoute,
|
||||
queryParams: {
|
||||
page: null,
|
||||
},
|
||||
queryParamsHandling: 'merge',
|
||||
replaceUrl: true,
|
||||
});
|
||||
}
|
||||
|
||||
private openStalkerItemFromNavigationState(): void {
|
||||
if (this.catalog.provider !== 'stalker') {
|
||||
return;
|
||||
|
||||
@@ -67,6 +67,7 @@ describe('StalkerCatalogFacadeService', () => {
|
||||
getSelectedCategoryName: jest.fn(() => null),
|
||||
setSelectedCategory: jest.fn(),
|
||||
clearSelectedItem: jest.fn(),
|
||||
setSearchPhrase: jest.fn(),
|
||||
setPage: jest.fn(),
|
||||
setLimit: jest.fn(),
|
||||
setSelectedItem: jest.fn(),
|
||||
@@ -86,6 +87,17 @@ describe('StalkerCatalogFacadeService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('delegates category search query updates to the Stalker store', () => {
|
||||
const service = TestBed.inject(StalkerCatalogFacadeService);
|
||||
const store = TestBed.inject(StalkerStore) as unknown as {
|
||||
setSearchPhrase: jest.Mock;
|
||||
};
|
||||
|
||||
service.setSearchQuery('matrix');
|
||||
|
||||
expect(store.setSearchPhrase).toHaveBeenCalledWith('matrix');
|
||||
});
|
||||
|
||||
it('persists matching external playback updates for the current playlist', async () => {
|
||||
TestBed.inject(StalkerCatalogFacadeService);
|
||||
await Promise.resolve();
|
||||
|
||||
@@ -167,6 +167,10 @@ export class StalkerCatalogFacadeService
|
||||
this.stalkerStore.clearSelectedItem();
|
||||
}
|
||||
|
||||
setSearchQuery(query: string): void {
|
||||
this.stalkerStore.setSearchPhrase(query);
|
||||
}
|
||||
|
||||
setPage(page: number): void {
|
||||
this.stalkerStore.setPage(page);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user