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 {
|
||||
|
||||
Reference in New Issue
Block a user