refactor(ui): use tanstack virtual+table for book browser table view (#1047)
This commit is contained in:
@@ -55,6 +55,21 @@ describe('RouteScrollPositionService', () => {
|
||||
expect(service.keyFor(route)).toBe('authors/42:id=42');
|
||||
});
|
||||
|
||||
it('can suffix route keys for independent view scroll positions', () => {
|
||||
const route = {
|
||||
snapshot: {
|
||||
pathFromRoot: [
|
||||
{url: []},
|
||||
{url: [{path: 'books'}]},
|
||||
],
|
||||
params: {libraryId: '1'},
|
||||
},
|
||||
} as unknown as ActivatedRoute;
|
||||
|
||||
expect(service.keyFor(route, 'grid')).toBe('books:libraryId=1:grid');
|
||||
expect(service.keyFor(route, 'table')).toBe('books:libraryId=1:table');
|
||||
});
|
||||
|
||||
it('encodes route key values and falls back to the path when params are empty', () => {
|
||||
expect(service.createKey('/books', {slug: 'one-two', type: 'magic&shelf'})).toBe('/books:slug=one-two;type=magic%26shelf');
|
||||
expect(service.createKey('/books', {})).toBe('/books');
|
||||
|
||||
@@ -7,6 +7,7 @@ interface TrackRouteOptions {
|
||||
scrollElement: Signal<ElementRef<HTMLElement> | undefined>;
|
||||
route: ActivatedRoute;
|
||||
destroyRef: DestroyRef;
|
||||
keySuffix?: string;
|
||||
dismissOverlaysBeforeSave?: boolean;
|
||||
beforeSave?: () => void;
|
||||
}
|
||||
@@ -47,13 +48,14 @@ export class RouteScrollPositionService {
|
||||
return paramPairs ? `${path}:${paramPairs}` : path;
|
||||
}
|
||||
|
||||
keyFor(route: ActivatedRoute): string {
|
||||
keyFor(route: ActivatedRoute, suffix?: string): string {
|
||||
const path = route.snapshot.pathFromRoot
|
||||
.flatMap(snapshot => snapshot.url)
|
||||
.map(segment => segment.path)
|
||||
.filter(Boolean)
|
||||
.join('/');
|
||||
return this.createKey(path, route.snapshot.params);
|
||||
const key = this.createKey(path, route.snapshot.params);
|
||||
return suffix ? `${key}:${suffix}` : key;
|
||||
}
|
||||
|
||||
dismissBodyOverlays(): void {
|
||||
@@ -71,7 +73,7 @@ export class RouteScrollPositionService {
|
||||
options.beforeSave?.();
|
||||
const element = options.scrollElement()?.nativeElement;
|
||||
if (element) {
|
||||
this.savePosition(this.keyFor(options.route), element.scrollTop);
|
||||
this.savePosition(this.keyFor(options.route, options.keySuffix), element.scrollTop);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user