feat(book-browser): add responsive grid columns for mobile view (#2446)
This commit is contained in:
+36
-13
@@ -111,20 +111,43 @@
|
||||
<label for="collapse-series-checkbox" class="display-settings-label">Collapse series</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="display-settings-section">
|
||||
<label class="display-settings-label">Grid item size</label>
|
||||
<p-slider
|
||||
[(ngModel)]="coverScalePreferenceService.scaleFactor"
|
||||
[min]="0.5"
|
||||
[max]="1.5"
|
||||
[step]="0.01"
|
||||
[style]="{ width: '100%' }"
|
||||
(onChange)="updateScale()">
|
||||
</p-slider>
|
||||
<div class="scale-value-display">
|
||||
{{ coverScalePreferenceService.scaleFactor.toFixed(2) }}x
|
||||
@if (isMobile) {
|
||||
<div class="display-settings-section">
|
||||
<label class="display-settings-label">Grid columns</label>
|
||||
<div class="column-options">
|
||||
<button
|
||||
type="button"
|
||||
class="column-option-btn"
|
||||
[class.active]="mobileColumnCount === 2"
|
||||
(click)="setMobileColumns(2)">2</button>
|
||||
<button
|
||||
type="button"
|
||||
class="column-option-btn"
|
||||
[class.active]="mobileColumnCount === 3"
|
||||
(click)="setMobileColumns(3)">3</button>
|
||||
<button
|
||||
type="button"
|
||||
class="column-option-btn"
|
||||
[class.active]="mobileColumnCount === 4"
|
||||
(click)="setMobileColumns(4)">4</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="display-settings-section">
|
||||
<label class="display-settings-label">Grid item size</label>
|
||||
<p-slider
|
||||
[(ngModel)]="coverScalePreferenceService.scaleFactor"
|
||||
[min]="0.5"
|
||||
[max]="1.5"
|
||||
[step]="0.01"
|
||||
[style]="{ width: '100%' }"
|
||||
(onChange)="updateScale()">
|
||||
</p-slider>
|
||||
<div class="scale-value-display">
|
||||
{{ coverScalePreferenceService.scaleFactor.toFixed(2) }}x
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<div class="display-settings-section">
|
||||
<div class="display-settings-checkbox-row">
|
||||
<p-checkbox
|
||||
|
||||
@@ -43,6 +43,10 @@
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.125rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
gap: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.entity-title {
|
||||
@@ -51,11 +55,24 @@
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
padding-left: 0.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.series-collapsed-info {
|
||||
font-size: 0.875rem;
|
||||
color: #6b7280;
|
||||
margin: 0;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
display: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.entity-menu-wrapper {
|
||||
@@ -130,6 +147,34 @@
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.column-options {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.column-option-btn {
|
||||
flex: 1;
|
||||
padding: 0.25rem 0.5rem;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 6px;
|
||||
background-color: var(--card-background);
|
||||
color: var(--text-color);
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
|
||||
&.active {
|
||||
background-color: var(--primary-color);
|
||||
border-color: var(--primary-color);
|
||||
color: var(--primary-color-text);
|
||||
}
|
||||
}
|
||||
|
||||
// Sort menu item
|
||||
.sort-menu-item {
|
||||
display: flex;
|
||||
@@ -285,6 +330,12 @@
|
||||
gap: 1.3rem;
|
||||
align-items: start;
|
||||
width: 100%;
|
||||
|
||||
// Mobile: fixed 2 or 3 columns based on phone width
|
||||
@media (max-width: 767px) {
|
||||
gap: 1rem;
|
||||
padding: 0 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.virtual-scroller-item {
|
||||
|
||||
+49
-1
@@ -1,4 +1,4 @@
|
||||
import {AfterViewInit, Component, inject, OnInit, ViewChild} from '@angular/core';
|
||||
import {AfterViewInit, Component, HostListener, inject, OnInit, ViewChild} from '@angular/core';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
import {ConfirmationService, MenuItem, MessageService, PrimeTemplate} from 'primeng/api';
|
||||
import {PageTitleService} from '../../../../shared/service/page-title.service';
|
||||
@@ -45,6 +45,7 @@ import {MetadataRefreshType} from '../../../metadata/model/request/metadata-refr
|
||||
import {TaskHelperService} from '../../../settings/task-management/task-helper.service';
|
||||
import {FilterLabelHelper} from './filter-label.helper';
|
||||
import {LoadingService} from '../../../../core/services/loading.service';
|
||||
import {LocalStorageService} from '../../../../shared/service/local-storage.service';
|
||||
import {BookNavigationService} from '../../service/book-navigation.service';
|
||||
import {BookCardOverlayPreferenceService} from './book-card-overlay-preference.service';
|
||||
import {BookSelectionService, CheckboxClickEvent} from './book-selection.service';
|
||||
@@ -109,6 +110,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
private queryParamsService = inject(BookBrowserQueryParamsService);
|
||||
private entityService = inject(BookBrowserEntityService);
|
||||
private filterOrchestrationService = inject(BookFilterOrchestrationService);
|
||||
private localStorageService = inject(LocalStorageService);
|
||||
|
||||
// Observables
|
||||
bookState$: Observable<BookState> | undefined;
|
||||
@@ -136,6 +138,14 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
currentViewMode: string | undefined;
|
||||
lastAppliedSort: SortOption | null = null;
|
||||
showFilter = false;
|
||||
screenWidth = typeof window !== 'undefined' ? window.innerWidth : 1024;
|
||||
mobileColumnCount = 3;
|
||||
|
||||
private readonly MOBILE_BREAKPOINT = 768;
|
||||
private readonly CARD_ASPECT_RATIO = 7 / 5; // height / width (from aspect-ratio: 5/7)
|
||||
private readonly MOBILE_GAP = 16; // 1rem in px
|
||||
private readonly MOBILE_PADDING = 16; // 0.5rem * 2 sides
|
||||
private readonly MOBILE_COLUMNS_STORAGE_KEY = 'mobileColumnsPreference';
|
||||
|
||||
private settingFiltersFromUrl = false;
|
||||
protected metadataMenuItems: MenuItem[] | undefined;
|
||||
@@ -152,15 +162,40 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild(BookFilterComponent, {static: false})
|
||||
bookFilterComponent!: BookFilterComponent;
|
||||
|
||||
@HostListener('window:resize')
|
||||
onResize(): void {
|
||||
this.screenWidth = window.innerWidth;
|
||||
}
|
||||
|
||||
get isMobile(): boolean {
|
||||
return this.screenWidth < this.MOBILE_BREAKPOINT;
|
||||
}
|
||||
|
||||
get mobileCardSize(): { width: number; height: number } {
|
||||
const columns = this.mobileColumnCount;
|
||||
const totalGaps = (columns - 1) * this.MOBILE_GAP;
|
||||
const totalPadding = this.MOBILE_PADDING * 2;
|
||||
const availableWidth = this.screenWidth - totalGaps - totalPadding;
|
||||
const cardWidth = Math.floor(availableWidth / columns);
|
||||
const cardHeight = Math.floor(cardWidth * this.CARD_ASPECT_RATIO);
|
||||
return { width: cardWidth, height: cardHeight };
|
||||
}
|
||||
|
||||
get selectedBooks(): Set<number> {
|
||||
return this.bookSelectionService.selectedBooks;
|
||||
}
|
||||
|
||||
get currentCardSize() {
|
||||
if (this.isMobile) {
|
||||
return this.mobileCardSize;
|
||||
}
|
||||
return this.coverScalePreferenceService.currentCardSize;
|
||||
}
|
||||
|
||||
get gridColumnMinWidth(): string {
|
||||
if (this.isMobile) {
|
||||
return `${this.mobileCardSize.width}px`;
|
||||
}
|
||||
return this.coverScalePreferenceService.gridColumnMinWidth;
|
||||
}
|
||||
|
||||
@@ -217,6 +252,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
ngOnInit(): void {
|
||||
this.pageTitle.setPageTitle('');
|
||||
this.coverScalePreferenceService.scaleChange$.pipe(debounceTime(1000)).subscribe();
|
||||
this.loadMobileColumnsPreference();
|
||||
|
||||
this.initializeEntityRouting();
|
||||
this.setupRouteChangeHandlers();
|
||||
@@ -704,4 +740,16 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
this.bookSorter.selectedSort!
|
||||
);
|
||||
}
|
||||
|
||||
setMobileColumns(columns: number): void {
|
||||
this.mobileColumnCount = columns;
|
||||
this.localStorageService.set(this.MOBILE_COLUMNS_STORAGE_KEY, columns);
|
||||
}
|
||||
|
||||
private loadMobileColumnsPreference(): void {
|
||||
const saved = this.localStorageService.get<number>(this.MOBILE_COLUMNS_STORAGE_KEY);
|
||||
if (saved !== null && [2, 3, 4].includes(saved)) {
|
||||
this.mobileColumnCount = saved;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+46
@@ -67,6 +67,11 @@
|
||||
text-align: center;
|
||||
margin: 0;
|
||||
padding-left: 0.5rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
font-size: 0.75rem;
|
||||
padding-left: 0.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.info-btn,
|
||||
@@ -79,6 +84,31 @@
|
||||
transition: opacity 0.15s ease, visibility 0.15s ease;
|
||||
z-index: 2;
|
||||
will-change: opacity, visibility;
|
||||
|
||||
::ng-deep .p-button {
|
||||
box-shadow:
|
||||
0 2px 8px rgba(0, 0, 0, 0.4),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.15);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
transition: transform 0.15s ease, box-shadow 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
transform: scale(1.08);
|
||||
box-shadow:
|
||||
0 4px 12px rgba(0, 0, 0, 0.5),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
width: clamp(1.5rem, 8vw, 2.5rem);
|
||||
height: clamp(1.5rem, 8vw, 2.5rem);
|
||||
padding: 0;
|
||||
|
||||
.pi {
|
||||
font-size: clamp(0.65rem, 3.5vw, 1rem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.info-btn {
|
||||
@@ -109,6 +139,11 @@
|
||||
transition: opacity 0.15s ease, visibility 0.15s ease;
|
||||
z-index: 2;
|
||||
will-change: opacity, visibility;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
top: 4px;
|
||||
right: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.select-checkbox .p-checkbox {
|
||||
@@ -203,6 +238,12 @@
|
||||
align-items: flex-start;
|
||||
gap: 4px;
|
||||
z-index: 4;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
top: 4px;
|
||||
left: 4px;
|
||||
gap: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.book-type-pill-overlay,
|
||||
@@ -210,6 +251,11 @@
|
||||
.series-items-count-overlay {
|
||||
position: static;
|
||||
margin: 0;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
font-size: 0.6rem;
|
||||
padding: 1px 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.book-type-epub {
|
||||
|
||||
Reference in New Issue
Block a user