refactor(ui): use tanstack virtual+table for book browser table view (#1047)

This commit is contained in:
Alex
2026-05-03 08:11:19 +01:00
committed by GitHub
parent 34eb6ce412
commit 1c9902448f
43 changed files with 2241 additions and 785 deletions
@@ -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);
}
});
}