refactor(ui): create shared grid layout for author/series/book browser (#1193)
This commit is contained in:
+22
-15
@@ -48,19 +48,28 @@
|
||||
}
|
||||
</button>
|
||||
|
||||
@if (!isMobile()) {
|
||||
<button class="display-settings-btn" (click)="displaySettingsPopover.toggle($event)">
|
||||
<i class="pi pi-sliders-h"></i>
|
||||
</button>
|
||||
<p-popover #displaySettingsPopover>
|
||||
<div class="display-settings-content">
|
||||
<span class="display-settings-label">{{ t('cardSize') }}</span>
|
||||
<app-grid-density-buttons (densityChange)="adjustDesktopGridDensity($event)"/>
|
||||
</div>
|
||||
</p-popover>
|
||||
}
|
||||
<button
|
||||
type="button"
|
||||
class="display-settings-btn"
|
||||
[attr.aria-label]="'common.displaySettings' | transloco"
|
||||
[title]="'common.displaySettings' | transloco"
|
||||
(click)="displaySettingsPopover.toggle($event)">
|
||||
<i class="pi pi-sliders-h"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-popover #filterPopover>
|
||||
<p-popover #displaySettingsPopover>
|
||||
<div class="display-settings-content">
|
||||
<span class="display-settings-label">{{ 'common.cardSize' | transloco }}</span>
|
||||
<app-grid-density-buttons
|
||||
[smallerDisabled]="gridDensitySmallerDisabled()"
|
||||
[largerDisabled]="gridDensityLargerDisabled()"
|
||||
(densityChange)="adjustGridDensity($event)"/>
|
||||
</div>
|
||||
</p-popover>
|
||||
|
||||
<p-popover #filterPopover>
|
||||
<div class="filter-popover-content">
|
||||
<div class="filter-group">
|
||||
<span class="filter-label">{{ t('filters.matchStatus') }}</span>
|
||||
@@ -172,9 +181,7 @@
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
</p-popover>
|
||||
</div>
|
||||
</div>
|
||||
</p-popover>
|
||||
</div>
|
||||
|
||||
@if (filteredAuthors(); as authorList) {
|
||||
|
||||
+18
-9
@@ -1,5 +1,7 @@
|
||||
@use "../../../../../assets/layout/styles/layout/variables";
|
||||
|
||||
.author-browser-page {
|
||||
--browser-gutter-inline: 2.1rem;
|
||||
--browser-gutter-inline: var(--page-gutter-inline);
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -150,7 +152,7 @@
|
||||
box-sizing: border-box;
|
||||
overflow-y: auto;
|
||||
|
||||
@media (width <= 768px) {
|
||||
@media #{variables.$mobile-shell-media-query} {
|
||||
padding-block: 0.5rem;
|
||||
}
|
||||
}
|
||||
@@ -201,7 +203,7 @@
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (width <= 768px) {
|
||||
@media #{variables.$mobile-shell-media-query} {
|
||||
max-width: 100%;
|
||||
left: 0;
|
||||
right: 0;
|
||||
@@ -245,16 +247,16 @@
|
||||
|
||||
.action-buttons-group {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
gap: 1.5rem;
|
||||
|
||||
@media (width >= 768px) {
|
||||
gap: 1.5rem;
|
||||
@media #{variables.$mobile-shell-media-query} {
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (width <= 767px) {
|
||||
@media #{variables.$mobile-shell-media-query} {
|
||||
.author-browser-page {
|
||||
--browser-gutter-inline: 0.5rem;
|
||||
--browser-gutter-inline: var(--space-4);
|
||||
|
||||
padding: 1.5rem 0 0;
|
||||
}
|
||||
@@ -272,11 +274,18 @@
|
||||
}
|
||||
|
||||
.filter-sort-wrapper {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) repeat(3, 36px);
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.sort-dropdown {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.sort-direction-btn,
|
||||
.filter-btn,
|
||||
.display-settings-btn {
|
||||
width: 36px;
|
||||
}
|
||||
}
|
||||
|
||||
+50
-36
@@ -7,7 +7,7 @@ import {Popover} from 'primeng/popover';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
import {RouteScrollPositionService} from '../../../../shared/service/route-scroll-position.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {AuthorService} from '../../service/author.service';
|
||||
@@ -19,10 +19,12 @@ import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
import {Book, ReadStatus} from '../../../book/model/book.model';
|
||||
import {createVirtualGrid, scaleForGridColumns} from '../../../../shared/util/virtual-grid.util';
|
||||
import {GridDensityButtonsComponent} from '../../../../shared/components/grid-density-buttons/grid-density-buttons.component';
|
||||
import {createVirtualGrid} from '../../../../shared/util/virtual-grid.util';
|
||||
import {GridDensityButtonsComponent, type GridDensityDirection} from '../../../../shared/components/grid-density-buttons/grid-density-buttons.component';
|
||||
import {LocalStorageService} from '../../../../shared/service/local-storage.service';
|
||||
import {ScalePreference} from '../../../../shared/util/scale-preference.util';
|
||||
import {LayoutService} from '../../../../shared/layout/layout.service';
|
||||
import {createGridDensity} from '../../../../shared/util/grid-density.util';
|
||||
|
||||
type SortDirection = 'asc' | 'desc';
|
||||
|
||||
@@ -63,6 +65,7 @@ const DEFAULT_SORT_DIRECTIONS: Record<string, SortDirection> = {
|
||||
Divider,
|
||||
Tooltip,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe,
|
||||
GridDensityButtonsComponent,
|
||||
AuthorCardComponent,
|
||||
]
|
||||
@@ -73,7 +76,11 @@ export class AuthorBrowserComponent implements OnInit {
|
||||
private static readonly BASE_HEIGHT = 290;
|
||||
private static readonly MOBILE_BASE_WIDTH = 140;
|
||||
private static readonly MOBILE_BASE_HEIGHT = 250;
|
||||
private static readonly DEFAULT_MOBILE_GRID_COLUMNS = 3;
|
||||
private static readonly MIN_MOBILE_GRID_COLUMNS = 2;
|
||||
private static readonly MAX_MOBILE_GRID_COLUMNS = 4;
|
||||
private static readonly SCALE_STORAGE_KEY = 'authorScalePreference';
|
||||
private static readonly MOBILE_COLUMNS_STORAGE_KEY = 'authorMobileColumnsPreference';
|
||||
private static readonly MIN_SCALE = 0.7;
|
||||
private static readonly MAX_SCALE = 1.3;
|
||||
|
||||
@@ -87,9 +94,23 @@ export class AuthorBrowserComponent implements OnInit {
|
||||
private activatedRoute = inject(ActivatedRoute);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
private localStorageService = inject(LocalStorageService);
|
||||
private layoutService = inject(LayoutService);
|
||||
protected userService = inject(UserService);
|
||||
protected selectionService = inject(AuthorSelectionService);
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const authors = this.authorService.allAuthors();
|
||||
if (authors !== null) {
|
||||
this.allAuthorsState.set(authors);
|
||||
}
|
||||
});
|
||||
|
||||
effect(() => {
|
||||
this.selectionService.setCurrentAuthors(this.filteredAuthors());
|
||||
});
|
||||
}
|
||||
|
||||
private static readonly GRID_GAP = 20;
|
||||
private readonly scrollElement = viewChild<ElementRef<HTMLElement>>('scrollElement');
|
||||
private readonly initialScrollOffset = () => this.scrollService.getPosition(this.scrollService.keyFor(this.activatedRoute)) ?? 0;
|
||||
@@ -172,39 +193,50 @@ export class AuthorBrowserComponent implements OnInit {
|
||||
result = this.applyFilters(result, this.filters());
|
||||
return this.applySort(result, this.sortBy(), this.sortDirection());
|
||||
});
|
||||
private readonly syncAuthorsEffect = effect(() => {
|
||||
const authors = this.authorService.allAuthors();
|
||||
if (authors !== null) {
|
||||
this.allAuthorsState.set(authors);
|
||||
}
|
||||
});
|
||||
private readonly syncSelectionEffect = effect(() => {
|
||||
this.selectionService.setCurrentAuthors(this.filteredAuthors());
|
||||
});
|
||||
|
||||
@HostListener('window:resize')
|
||||
onResize(): void {
|
||||
this.screenWidth.set(window.innerWidth);
|
||||
}
|
||||
|
||||
readonly isMobile = computed(() => this.screenWidth() <= 767);
|
||||
readonly isMobile = computed(() => !this.layoutService.isDesktop());
|
||||
private readonly baseCardWidth = computed(() => this.isMobile()
|
||||
? AuthorBrowserComponent.MOBILE_BASE_WIDTH
|
||||
: AuthorBrowserComponent.BASE_WIDTH
|
||||
);
|
||||
private readonly gridDensity = createGridDensity(this.localStorageService, {
|
||||
useFixedColumns: this.isMobile,
|
||||
screenWidth: this.screenWidth,
|
||||
storageKey: AuthorBrowserComponent.MOBILE_COLUMNS_STORAGE_KEY,
|
||||
defaultColumns: AuthorBrowserComponent.DEFAULT_MOBILE_GRID_COLUMNS,
|
||||
minColumns: AuthorBrowserComponent.MIN_MOBILE_GRID_COLUMNS,
|
||||
maxColumns: AuthorBrowserComponent.MAX_MOBILE_GRID_COLUMNS,
|
||||
scale: this.scaleFactor,
|
||||
minScale: AuthorBrowserComponent.MIN_SCALE,
|
||||
maxScale: AuthorBrowserComponent.MAX_SCALE,
|
||||
gap: AuthorBrowserComponent.GRID_GAP,
|
||||
baseWidth: this.baseCardWidth,
|
||||
setScale: scale => this.scalePreference.setScale(scale),
|
||||
});
|
||||
readonly gridDensitySmallerDisabled = this.gridDensity.smallerDisabled;
|
||||
readonly gridDensityLargerDisabled = this.gridDensity.largerDisabled;
|
||||
private readonly cardAspectRatio = computed(() => {
|
||||
const baseHeight = this.isMobile()
|
||||
? AuthorBrowserComponent.MOBILE_BASE_HEIGHT
|
||||
: AuthorBrowserComponent.BASE_HEIGHT;
|
||||
return baseHeight / this.baseCardWidth();
|
||||
});
|
||||
private readonly minCardWidth = computed(() => Math.round(this.baseCardWidth() * this.scaleFactor()));
|
||||
private readonly minCardWidth = computed(() => this.isMobile()
|
||||
? 1
|
||||
: Math.round(this.baseCardWidth() * this.scaleFactor())
|
||||
);
|
||||
readonly virtualGrid = createVirtualGrid({
|
||||
items: this.filteredAuthors,
|
||||
scrollElement: this.scrollElement,
|
||||
minItemWidth: this.minCardWidth,
|
||||
gap: AuthorBrowserComponent.GRID_GAP,
|
||||
gap: this.gridDensity.gap,
|
||||
columns: this.gridDensity.columns,
|
||||
initialOffset: this.initialScrollOffset,
|
||||
fillItemWidth: true,
|
||||
estimateItemHeight: itemWidth => Math.round(itemWidth * this.cardAspectRatio()),
|
||||
});
|
||||
|
||||
@@ -246,26 +278,8 @@ export class AuthorBrowserComponent implements OnInit {
|
||||
this.destroyRef.onDestroy(() => this.selectionService.deselectAll());
|
||||
}
|
||||
|
||||
adjustDesktopGridDensity(direction: 'smaller' | 'larger'): void {
|
||||
const currentColumns = this.virtualGrid.gridColumns();
|
||||
const columns = Math.max(1, direction === 'smaller'
|
||||
? currentColumns + 1
|
||||
: currentColumns - 1);
|
||||
const viewportWidth = this.virtualGrid.viewportWidth() || this.screenWidth();
|
||||
this.virtualGrid.updatePreservingScrollPosition(() => {
|
||||
this.setScale(scaleForGridColumns(
|
||||
viewportWidth,
|
||||
AuthorBrowserComponent.GRID_GAP,
|
||||
columns,
|
||||
this.baseCardWidth(),
|
||||
AuthorBrowserComponent.MIN_SCALE,
|
||||
AuthorBrowserComponent.MAX_SCALE
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
private setScale(scale: number): void {
|
||||
this.scalePreference.setScale(scale);
|
||||
adjustGridDensity(direction: GridDensityDirection): void {
|
||||
this.gridDensity.adjust(direction, this.virtualGrid);
|
||||
}
|
||||
|
||||
onSearchChange(value: string): void {
|
||||
|
||||
@@ -104,7 +104,7 @@
|
||||
tabindex="0"
|
||||
(click)="seriesCollapseOverlay.toggle($event)"
|
||||
(keydown.enter)="seriesCollapseOverlay.toggle($event)"
|
||||
[pTooltip]="t('tooltip.displaySettings')"
|
||||
[pTooltip]="'common.displaySettings' | transloco"
|
||||
tooltipPosition="top">
|
||||
<i class="pi pi-cog"></i>
|
||||
</a>
|
||||
@@ -122,7 +122,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="display-settings-section">
|
||||
<span class="display-settings-label">{{ t('labels.gridItemSize') }}</span>
|
||||
<span class="display-settings-label">{{ 'common.cardSize' | transloco }}</span>
|
||||
<app-grid-density-buttons
|
||||
[smallerDisabled]="gridDensitySmallerDisabled()"
|
||||
[largerDisabled]="gridDensityLargerDisabled()"
|
||||
|
||||
+1
-1
@@ -255,7 +255,7 @@ function createHarness(options?: {
|
||||
},
|
||||
},
|
||||
{provide: AppSettingsService, useValue: {appSettings: vi.fn(() => null)}},
|
||||
{provide: LayoutService, useValue: {sidebarTransitioning: signal(false)}},
|
||||
{provide: LayoutService, useValue: {isDesktop: signal(true), sidebarTransitioning: signal(false)}},
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: {
|
||||
|
||||
@@ -49,14 +49,15 @@ import {BookBrowserEntityService, EntityInfo} from './book-browser-entity.servic
|
||||
import {RouteScrollPositionService} from '../../../../shared/service/route-scroll-position.service';
|
||||
import {AppSettingsService} from '../../../../shared/service/app-settings.service';
|
||||
import {MultiSortPopoverComponent} from './sorting/multi-sort-popover/multi-sort-popover.component';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
import {SortService} from '../../service/sort.service';
|
||||
import {createVirtualGrid, scaleForGridColumns, type VirtualGridMetrics} from '../../../../shared/util/virtual-grid.util';
|
||||
import {createVirtualGrid, type VirtualGridMetrics} from '../../../../shared/util/virtual-grid.util';
|
||||
import {GridDensityButtonsComponent, type GridDensityDirection} from '../../../../shared/components/grid-density-buttons/grid-density-buttons.component';
|
||||
import {filterBooksBySearchTerm} from './filters/HeaderFilter';
|
||||
import {filterBooksByFilters} from './filters/sidebar-filter';
|
||||
import {LayoutService} from '../../../../shared/layout/layout.service';
|
||||
import {createGridDensity} from '../../../../shared/util/grid-density.util';
|
||||
|
||||
export enum EntityType {
|
||||
LIBRARY = 'Library',
|
||||
@@ -81,7 +82,7 @@ const MOBILE_COLUMNS_STORAGE_KEY = 'mobileColumnsPreference';
|
||||
imports: [
|
||||
Button, BookCardComponent, Menu, InputText, FormsModule,
|
||||
BookTableComponent, BookFilterComponent, Tooltip, NgClass, Popover,
|
||||
Checkbox, Divider, MultiSelect, TieredMenu, Badge, MultiSortPopoverComponent, TranslocoDirective, GridDensityButtonsComponent,
|
||||
Checkbox, Divider, MultiSelect, TieredMenu, Badge, MultiSortPopoverComponent, TranslocoDirective, TranslocoPipe, GridDensityButtonsComponent,
|
||||
],
|
||||
providers: [SeriesCollapseFilter],
|
||||
})
|
||||
@@ -117,7 +118,6 @@ export class BookBrowserComponent implements AfterViewInit {
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
|
||||
constructor() {
|
||||
this.loadMobileColumnsPreference();
|
||||
this.setupRouteChangeHandlers();
|
||||
this.setupQueryParamSubscription();
|
||||
this.scrollService.trackRoute({
|
||||
@@ -166,7 +166,6 @@ export class BookBrowserComponent implements AfterViewInit {
|
||||
readonly visibleSortOptions = signal<SortOption[]>([]);
|
||||
readonly currentFilterLabel = signal<string | null>(null);
|
||||
readonly rawFilterParamFromUrl = signal<string | null>(null);
|
||||
readonly gridMobileColumnCount = signal(DEFAULT_MOBILE_GRID_COLUMNS);
|
||||
private readonly seriesCollapsed = this.seriesCollapseFilter.seriesCollapsed;
|
||||
readonly selectedBooks = this.bookSelectionService.selectedBooks;
|
||||
readonly selectedCount = this.bookSelectionService.selectedCount;
|
||||
@@ -229,9 +228,7 @@ export class BookBrowserComponent implements AfterViewInit {
|
||||
readonly booksError = this.bookService.booksError;
|
||||
|
||||
private readonly GRID_GAP = 21;
|
||||
private readonly MOBILE_BREAKPOINT = 768;
|
||||
private readonly CARD_ASPECT_RATIO = 7 / 5;
|
||||
private readonly MOBILE_GAP = 8;
|
||||
private readonly MOBILE_TITLE_BAR_HEIGHT = 32;
|
||||
private readonly DESKTOP_CARD_BASE_WIDTH = 135;
|
||||
private readonly DESKTOP_CARD_BASE_HEIGHT = 220;
|
||||
@@ -240,18 +237,31 @@ export class BookBrowserComponent implements AfterViewInit {
|
||||
private readonly AUDIOBOOK_TITLE_BAR_HEIGHT = 31;
|
||||
private readonly scrollElement = viewChild<ElementRef<HTMLElement>>('scrollElement');
|
||||
private readonly initialScrollOffset = () => this.scrollService.getPosition(this.scrollService.keyFor(this.activatedRoute, 'grid')) ?? 0;
|
||||
readonly isMobile = computed(() => !this.layoutService.isDesktop());
|
||||
private readonly desktopBaseCardWidth = computed(() =>
|
||||
this.isAudiobookOnlyLibrary()
|
||||
? this.DESKTOP_CARD_BASE_WIDTH * 1.1
|
||||
: this.DESKTOP_CARD_BASE_WIDTH
|
||||
);
|
||||
private readonly gridDensity = createGridDensity(this.localStorageService, {
|
||||
useFixedColumns: this.isMobile,
|
||||
screenWidth: this.screenWidth,
|
||||
storageKey: MOBILE_COLUMNS_STORAGE_KEY,
|
||||
defaultColumns: DEFAULT_MOBILE_GRID_COLUMNS,
|
||||
minColumns: MIN_MOBILE_GRID_COLUMNS,
|
||||
maxColumns: MAX_MOBILE_GRID_COLUMNS,
|
||||
scale: this.coverScalePreferenceService.scaleFactor,
|
||||
minScale: this.DESKTOP_MIN_SCALE,
|
||||
maxScale: this.DESKTOP_MAX_SCALE,
|
||||
gap: this.GRID_GAP,
|
||||
baseWidth: this.desktopBaseCardWidth,
|
||||
setScale: scale => this.coverScalePreferenceService.setScale(scale),
|
||||
});
|
||||
private readonly minCardWidth = computed(() =>
|
||||
this.isMobile()
|
||||
? 1
|
||||
: Math.round(this.desktopBaseCardWidth() * this.coverScalePreferenceService.scaleFactor())
|
||||
);
|
||||
private readonly virtualGridGap = computed(() => this.isMobile() ? this.MOBILE_GAP : this.GRID_GAP);
|
||||
private readonly virtualGridColumns = computed(() => this.isMobile() ? this.gridMobileColumnCount() : undefined);
|
||||
readonly virtualRowCount = computed(() => this.bookCountIncludingUnloadedPages(this.books().length));
|
||||
private readonly hasUnloadedBooks = computed(() => this.books().length < this.virtualRowCount());
|
||||
readonly loadedBookCount = computed(() => this.books().length);
|
||||
@@ -259,8 +269,8 @@ export class BookBrowserComponent implements AfterViewInit {
|
||||
items: this.books,
|
||||
scrollElement: this.scrollElement,
|
||||
minItemWidth: this.minCardWidth,
|
||||
gap: this.virtualGridGap,
|
||||
columns: this.virtualGridColumns,
|
||||
gap: this.gridDensity.gap,
|
||||
columns: this.gridDensity.columns,
|
||||
count: this.virtualRowCount,
|
||||
minimumCount: metrics => this.minimumLoadingGridItemCount(metrics),
|
||||
initialOffset: this.initialScrollOffset,
|
||||
@@ -414,13 +424,8 @@ export class BookBrowserComponent implements AfterViewInit {
|
||||
this.screenWidth.set(window.innerWidth);
|
||||
}
|
||||
|
||||
readonly isMobile = computed(() => this.screenWidth() < this.MOBILE_BREAKPOINT);
|
||||
readonly gridDensitySmallerDisabled = computed(() =>
|
||||
this.isMobile() && this.gridMobileColumnCount() >= MAX_MOBILE_GRID_COLUMNS
|
||||
);
|
||||
readonly gridDensityLargerDisabled = computed(() =>
|
||||
this.isMobile() && this.gridMobileColumnCount() <= MIN_MOBILE_GRID_COLUMNS
|
||||
);
|
||||
readonly gridDensitySmallerDisabled = this.gridDensity.smallerDisabled;
|
||||
readonly gridDensityLargerDisabled = this.gridDensity.largerDisabled;
|
||||
|
||||
private cardSizeForWidth(width: number): { width: number; height: number } {
|
||||
const cardWidth = Math.round(width);
|
||||
@@ -1051,58 +1056,6 @@ export class BookBrowserComponent implements AfterViewInit {
|
||||
}
|
||||
|
||||
adjustGridDensity(direction: GridDensityDirection): void {
|
||||
if (this.isMobile()) {
|
||||
this.adjustMobileGridDensity(direction);
|
||||
return;
|
||||
}
|
||||
|
||||
this.adjustDesktopGridDensity(direction);
|
||||
}
|
||||
|
||||
private adjustMobileGridDensity(direction: GridDensityDirection): void {
|
||||
const currentColumns = this.gridMobileColumnCount();
|
||||
const nextColumns = direction === 'smaller'
|
||||
? currentColumns + 1
|
||||
: currentColumns - 1;
|
||||
|
||||
this.setMobileColumns(this.toMobileGridColumns(nextColumns));
|
||||
}
|
||||
|
||||
private setMobileColumns(columns: number): void {
|
||||
this.gridMobileColumnCount.set(columns);
|
||||
this.localStorageService.set(MOBILE_COLUMNS_STORAGE_KEY, columns);
|
||||
}
|
||||
|
||||
private adjustDesktopGridDensity(direction: GridDensityDirection): void {
|
||||
const currentColumns = this.virtualGrid.gridColumns();
|
||||
const columns = Math.max(1, direction === 'smaller'
|
||||
? currentColumns + 1
|
||||
: currentColumns - 1);
|
||||
const viewportWidth = this.virtualGrid.viewportWidth() || this.screenWidth();
|
||||
this.virtualGrid.updatePreservingScrollPosition(() => {
|
||||
this.coverScalePreferenceService.setScale(scaleForGridColumns(
|
||||
viewportWidth,
|
||||
this.GRID_GAP,
|
||||
columns,
|
||||
this.desktopBaseCardWidth(),
|
||||
this.DESKTOP_MIN_SCALE,
|
||||
this.DESKTOP_MAX_SCALE
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
private loadMobileColumnsPreference(): void {
|
||||
const saved = this.localStorageService.get<unknown>(MOBILE_COLUMNS_STORAGE_KEY);
|
||||
if (saved !== null) {
|
||||
this.setMobileColumns(this.toMobileGridColumns(saved));
|
||||
}
|
||||
}
|
||||
|
||||
private toMobileGridColumns(value: unknown): number {
|
||||
const columns = Number(value);
|
||||
if (!Number.isFinite(columns)) {
|
||||
return DEFAULT_MOBILE_GRID_COLUMNS;
|
||||
}
|
||||
return Math.min(MAX_MOBILE_GRID_COLUMNS, Math.max(MIN_MOBILE_GRID_COLUMNS, Math.round(columns)));
|
||||
this.gridDensity.adjust(direction, this.virtualGrid);
|
||||
}
|
||||
}
|
||||
|
||||
+22
-20
@@ -46,19 +46,25 @@
|
||||
class="sort-dropdown">
|
||||
</p-select>
|
||||
|
||||
@if (!isMobile()) {
|
||||
<button class="display-settings-btn" (click)="displaySettingsPopover.toggle($event)">
|
||||
<i class="pi pi-sliders-h"></i>
|
||||
</button>
|
||||
<p-popover #displaySettingsPopover>
|
||||
<div class="display-settings-content">
|
||||
<span class="display-settings-label">{{ t('cardSize') }}</span>
|
||||
<app-grid-density-buttons (densityChange)="adjustDesktopGridDensity($event)"/>
|
||||
</div>
|
||||
</p-popover>
|
||||
}
|
||||
<button
|
||||
type="button"
|
||||
class="display-settings-btn"
|
||||
[attr.aria-label]="'common.displaySettings' | transloco"
|
||||
[title]="'common.displaySettings' | transloco"
|
||||
(click)="displaySettingsPopover.toggle($event)">
|
||||
<i class="pi pi-sliders-h"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p-popover #displaySettingsPopover>
|
||||
<div class="display-settings-content">
|
||||
<span class="display-settings-label">{{ 'common.cardSize' | transloco }}</span>
|
||||
<app-grid-density-buttons
|
||||
[smallerDisabled]="gridDensitySmallerDisabled()"
|
||||
[largerDisabled]="gridDensityLargerDisabled()"
|
||||
(densityChange)="adjustGridDensity($event)"/>
|
||||
</div>
|
||||
</p-popover>
|
||||
</div>
|
||||
|
||||
@if (filteredSeries(); as seriesList) {
|
||||
@@ -77,15 +83,11 @@
|
||||
[style.width.px]="virtualGrid.itemWidth()"
|
||||
[style.height.px]="virtualItem.size"
|
||||
[style.transform]="virtualGrid.itemTransform(virtualItem)">
|
||||
<div class="virtual-scroller-item"
|
||||
[style.width.px]="virtualGrid.itemWidth()"
|
||||
[style.height.px]="virtualGrid.itemHeight()"
|
||||
[style.--card-scale]="currentCardScale()">
|
||||
<app-series-card
|
||||
[series]="series"
|
||||
(cardClick)="navigateToSeries($event)">
|
||||
</app-series-card>
|
||||
</div>
|
||||
<app-series-card
|
||||
[series]="series"
|
||||
[style.--card-scale]="currentCardScale()"
|
||||
(cardClick)="navigateToSeries($event)">
|
||||
</app-series-card>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
+12
-11
@@ -1,5 +1,7 @@
|
||||
@use "../../../../../assets/layout/styles/layout/variables";
|
||||
|
||||
.series-browser-page {
|
||||
--browser-gutter-inline: 2.1rem;
|
||||
--browser-gutter-inline: var(--page-gutter-inline);
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -117,17 +119,11 @@
|
||||
overflow: hidden auto;
|
||||
scrollbar-gutter: stable;
|
||||
|
||||
@media (width <= 768px) {
|
||||
@media #{variables.$mobile-shell-media-query} {
|
||||
padding-block: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.virtual-scroller-item {
|
||||
position: relative;
|
||||
overflow: visible;
|
||||
transition: width 0.2s ease, height 0.2s ease;
|
||||
}
|
||||
|
||||
// Empty state
|
||||
.empty-state {
|
||||
display: flex;
|
||||
@@ -150,9 +146,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
@media (width <= 767px) {
|
||||
@media #{variables.$mobile-shell-media-query} {
|
||||
.series-browser-page {
|
||||
--browser-gutter-inline: 0.5rem;
|
||||
--browser-gutter-inline: var(--space-4);
|
||||
|
||||
padding: 1.5rem 0 0;
|
||||
}
|
||||
@@ -170,12 +166,17 @@
|
||||
}
|
||||
|
||||
.filter-sort-wrapper {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 36px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.filter-dropdown,
|
||||
.sort-dropdown {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.display-settings-btn {
|
||||
width: 36px;
|
||||
}
|
||||
}
|
||||
|
||||
+41
-31
@@ -4,7 +4,7 @@ import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Select} from 'primeng/select';
|
||||
import {Popover} from 'primeng/popover';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
import {SeriesDataService} from '../../service/series-data.service';
|
||||
import {SeriesSummary} from '../../model/series.model';
|
||||
import {SeriesCardComponent} from '../series-card/series-card.component';
|
||||
@@ -12,11 +12,13 @@ import {BookService} from '../../../book/service/book.service';
|
||||
import {ReadStatus} from '../../../book/model/book.model';
|
||||
import {PageTitleService} from '../../../../shared/service/page-title.service';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {createVirtualGrid, scaleForGridColumns} from '../../../../shared/util/virtual-grid.util';
|
||||
import {createVirtualGrid} from '../../../../shared/util/virtual-grid.util';
|
||||
import {RouteScrollPositionService} from '../../../../shared/service/route-scroll-position.service';
|
||||
import {GridDensityButtonsComponent} from '../../../../shared/components/grid-density-buttons/grid-density-buttons.component';
|
||||
import {GridDensityButtonsComponent, type GridDensityDirection} from '../../../../shared/components/grid-density-buttons/grid-density-buttons.component';
|
||||
import {LocalStorageService} from '../../../../shared/service/local-storage.service';
|
||||
import {ScalePreference} from '../../../../shared/util/scale-preference.util';
|
||||
import {LayoutService} from '../../../../shared/layout/layout.service';
|
||||
import {createGridDensity} from '../../../../shared/util/grid-density.util';
|
||||
|
||||
interface FilterOption {
|
||||
label: string;
|
||||
@@ -40,6 +42,7 @@ interface SortOption {
|
||||
Select,
|
||||
Popover,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe,
|
||||
GridDensityButtonsComponent,
|
||||
SeriesCardComponent,
|
||||
]
|
||||
@@ -51,7 +54,11 @@ export class SeriesBrowserComponent implements OnInit {
|
||||
private static readonly MOBILE_BASE_WIDTH = 180;
|
||||
private static readonly MOBILE_BASE_HEIGHT = 250;
|
||||
private static readonly GRID_GAP = 20;
|
||||
private static readonly DEFAULT_MOBILE_GRID_COLUMNS = 2;
|
||||
private static readonly MIN_MOBILE_GRID_COLUMNS = 2;
|
||||
private static readonly MAX_MOBILE_GRID_COLUMNS = 3;
|
||||
private static readonly SCALE_STORAGE_KEY = 'seriesScalePreference';
|
||||
private static readonly MOBILE_COLUMNS_STORAGE_KEY = 'seriesMobileColumnsPreference';
|
||||
private static readonly MIN_SCALE = 0.7;
|
||||
private static readonly MAX_SCALE = 1.3;
|
||||
|
||||
@@ -64,6 +71,7 @@ export class SeriesBrowserComponent implements OnInit {
|
||||
private destroyRef = inject(DestroyRef);
|
||||
private scrollService = inject(RouteScrollPositionService);
|
||||
private localStorageService = inject(LocalStorageService);
|
||||
private layoutService = inject(LayoutService);
|
||||
|
||||
readonly isBooksLoading = this.bookService.isBooksLoading;
|
||||
private readonly searchTerm = signal('');
|
||||
@@ -93,6 +101,27 @@ export class SeriesBrowserComponent implements OnInit {
|
||||
});
|
||||
private readonly scaleFactor = this.scalePreference.scaleFactor;
|
||||
readonly screenWidth = signal(typeof window !== 'undefined' ? window.innerWidth : 1024);
|
||||
readonly isMobile = computed(() => !this.layoutService.isDesktop());
|
||||
private readonly baseCardWidth = computed(() => this.isMobile()
|
||||
? SeriesBrowserComponent.MOBILE_BASE_WIDTH
|
||||
: SeriesBrowserComponent.BASE_WIDTH
|
||||
);
|
||||
private readonly gridDensity = createGridDensity(this.localStorageService, {
|
||||
useFixedColumns: this.isMobile,
|
||||
screenWidth: this.screenWidth,
|
||||
storageKey: SeriesBrowserComponent.MOBILE_COLUMNS_STORAGE_KEY,
|
||||
defaultColumns: SeriesBrowserComponent.DEFAULT_MOBILE_GRID_COLUMNS,
|
||||
minColumns: SeriesBrowserComponent.MIN_MOBILE_GRID_COLUMNS,
|
||||
maxColumns: SeriesBrowserComponent.MAX_MOBILE_GRID_COLUMNS,
|
||||
scale: this.scaleFactor,
|
||||
minScale: SeriesBrowserComponent.MIN_SCALE,
|
||||
maxScale: SeriesBrowserComponent.MAX_SCALE,
|
||||
gap: SeriesBrowserComponent.GRID_GAP,
|
||||
baseWidth: this.baseCardWidth,
|
||||
setScale: scale => this.scalePreference.setScale(scale),
|
||||
});
|
||||
readonly gridDensitySmallerDisabled = this.gridDensity.smallerDisabled;
|
||||
readonly gridDensityLargerDisabled = this.gridDensity.largerDisabled;
|
||||
filterOptions: FilterOption[] = [];
|
||||
sortOptions: SortOption[] = [];
|
||||
|
||||
@@ -101,25 +130,24 @@ export class SeriesBrowserComponent implements OnInit {
|
||||
this.screenWidth.set(window.innerWidth);
|
||||
}
|
||||
|
||||
readonly isMobile = computed(() => this.screenWidth() <= 767);
|
||||
|
||||
private readonly baseCardWidth = computed(() => this.isMobile()
|
||||
? SeriesBrowserComponent.MOBILE_BASE_WIDTH
|
||||
: SeriesBrowserComponent.BASE_WIDTH
|
||||
);
|
||||
private readonly cardAspectRatio = computed(() => {
|
||||
const baseHeight = this.isMobile()
|
||||
? SeriesBrowserComponent.MOBILE_BASE_HEIGHT
|
||||
: SeriesBrowserComponent.BASE_HEIGHT;
|
||||
return baseHeight / this.baseCardWidth();
|
||||
});
|
||||
private readonly minCardWidth = computed(() => Math.round(this.baseCardWidth() * this.scaleFactor()));
|
||||
private readonly minCardWidth = computed(() => this.isMobile()
|
||||
? 1
|
||||
: Math.round(this.baseCardWidth() * this.scaleFactor())
|
||||
);
|
||||
readonly virtualGrid = createVirtualGrid({
|
||||
items: this.filteredSeries,
|
||||
scrollElement: this.scrollElement,
|
||||
minItemWidth: this.minCardWidth,
|
||||
gap: SeriesBrowserComponent.GRID_GAP,
|
||||
gap: this.gridDensity.gap,
|
||||
columns: this.gridDensity.columns,
|
||||
initialOffset: this.initialScrollOffset,
|
||||
fillItemWidth: true,
|
||||
estimateItemHeight: itemWidth => Math.round(itemWidth * this.cardAspectRatio()),
|
||||
});
|
||||
readonly currentCardScale = computed(() => this.virtualGrid.itemWidth() / this.baseCardWidth());
|
||||
@@ -174,26 +202,8 @@ export class SeriesBrowserComponent implements OnInit {
|
||||
this.sortBy.set(value);
|
||||
}
|
||||
|
||||
adjustDesktopGridDensity(direction: 'smaller' | 'larger'): void {
|
||||
const currentColumns = this.virtualGrid.gridColumns();
|
||||
const columns = Math.max(1, direction === 'smaller'
|
||||
? currentColumns + 1
|
||||
: currentColumns - 1);
|
||||
const viewportWidth = this.virtualGrid.viewportWidth() || this.screenWidth();
|
||||
this.virtualGrid.updatePreservingScrollPosition(() => {
|
||||
this.setScale(scaleForGridColumns(
|
||||
viewportWidth,
|
||||
SeriesBrowserComponent.GRID_GAP,
|
||||
columns,
|
||||
this.baseCardWidth(),
|
||||
SeriesBrowserComponent.MIN_SCALE,
|
||||
SeriesBrowserComponent.MAX_SCALE
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
private setScale(scale: number): void {
|
||||
this.scalePreference.setScale(scale);
|
||||
adjustGridDensity(direction: GridDensityDirection): void {
|
||||
this.gridDensity.adjust(direction, this.virtualGrid);
|
||||
}
|
||||
|
||||
navigateToSeries(series: SeriesSummary): void {
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import {Signal, computed, signal} from '@angular/core';
|
||||
import {LocalStorageService} from '../service/local-storage.service';
|
||||
import {scaleForGridColumns} from './virtual-grid.util';
|
||||
|
||||
const FIXED_COLUMN_GAP = 8;
|
||||
|
||||
type GridDensityDirection = 'smaller' | 'larger';
|
||||
|
||||
interface GridDensityOptions {
|
||||
useFixedColumns: Signal<boolean>;
|
||||
screenWidth: Signal<number>;
|
||||
storageKey: string;
|
||||
defaultColumns: number;
|
||||
minColumns: number;
|
||||
maxColumns: number;
|
||||
scale: Signal<number>;
|
||||
minScale: number;
|
||||
maxScale: number;
|
||||
gap: number;
|
||||
baseWidth: Signal<number>;
|
||||
setScale: (scale: number) => void;
|
||||
}
|
||||
|
||||
interface GridDensityGrid {
|
||||
gridColumns: Signal<number>;
|
||||
viewportWidth: Signal<number>;
|
||||
updatePreservingScrollPosition: (update: () => void) => void;
|
||||
}
|
||||
|
||||
export function createGridDensity(localStorageService: LocalStorageService, options: GridDensityOptions) {
|
||||
const defaultColumns = clampColumns(options.defaultColumns, options.minColumns, options.maxColumns);
|
||||
const toColumns = (value: unknown) => {
|
||||
const columns = Number(value);
|
||||
return Number.isFinite(columns)
|
||||
? clampColumns(columns, options.minColumns, options.maxColumns)
|
||||
: defaultColumns;
|
||||
};
|
||||
const savedColumns = localStorageService.get<unknown>(options.storageKey);
|
||||
const fixedColumns = signal(savedColumns === null ? defaultColumns : toColumns(savedColumns));
|
||||
|
||||
const adjustFixedColumns = (direction: GridDensityDirection): void => {
|
||||
const columns = toColumns(fixedColumns() + (direction === 'smaller' ? 1 : -1));
|
||||
fixedColumns.set(columns);
|
||||
localStorageService.set(options.storageKey, columns);
|
||||
};
|
||||
|
||||
const adjustScale = (direction: GridDensityDirection, grid: GridDensityGrid): void => {
|
||||
const columns = Math.max(1, grid.gridColumns() + (direction === 'smaller' ? 1 : -1));
|
||||
const viewportWidth = grid.viewportWidth() || options.screenWidth();
|
||||
grid.updatePreservingScrollPosition(() => {
|
||||
options.setScale(scaleForGridColumns(
|
||||
viewportWidth,
|
||||
options.gap,
|
||||
columns,
|
||||
options.baseWidth(),
|
||||
options.minScale,
|
||||
options.maxScale
|
||||
));
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
gap: computed(() => options.useFixedColumns() ? FIXED_COLUMN_GAP : options.gap),
|
||||
columns: computed(() => options.useFixedColumns() ? fixedColumns() : undefined),
|
||||
smallerDisabled: computed(() => options.useFixedColumns()
|
||||
? fixedColumns() >= options.maxColumns
|
||||
: options.scale() <= options.minScale
|
||||
),
|
||||
largerDisabled: computed(() => options.useFixedColumns()
|
||||
? fixedColumns() <= options.minColumns
|
||||
: options.scale() >= options.maxScale
|
||||
),
|
||||
adjust: (direction: GridDensityDirection, grid: GridDensityGrid) =>
|
||||
options.useFixedColumns() ? adjustFixedColumns(direction) : adjustScale(direction, grid),
|
||||
};
|
||||
}
|
||||
|
||||
function clampColumns(value: number, min: number, max: number): number {
|
||||
return Math.min(max, Math.max(min, Math.round(value)));
|
||||
}
|
||||
Reference in New Issue
Block a user