From 8c319122bb2c93b30cb9ff15761383f1ec9f4502 Mon Sep 17 00:00:00 2001 From: ACX <8075870+acx10@users.noreply.github.com> Date: Sat, 14 Feb 2026 15:32:12 -0700 Subject: [PATCH] feat: move sidebar width from global setting to localStorage with view preferences UI (#2749) --- .../book-browser/book-browser.component.scss | 4 +- .../book-filter/book-filter.component.scss | 2 +- .../view-preferences-parent.component.html | 34 +++++++ .../view-preferences-parent.component.scss | 90 +++++++++++++++++++ .../view-preferences-parent.component.ts | 32 ++++++- .../layout-main/app.layout.component.html | 2 +- .../layout-main/app.layout.component.ts | 12 ++- .../layout-menu/app.menu.component.html | 31 +++++-- .../layout-menu/app.menu.component.scss | 38 ++++++++ .../layout-menu/app.menu.component.ts | 18 +++- .../layout-menu/app.menuitem.component.scss | 1 + .../layout-sidebar/app.sidebar.component.scss | 3 - .../assets/layout/styles/layout/_menu.scss | 2 +- .../layout/styles/layout/_responsive.scss | 2 +- booklore-ui/src/i18n/en/settings-view.json | 7 ++ booklore-ui/src/i18n/es/settings-view.json | 7 ++ 16 files changed, 262 insertions(+), 23 deletions(-) diff --git a/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.scss b/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.scss index 981afea1f..7efed4313 100644 --- a/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.scss +++ b/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.scss @@ -447,7 +447,7 @@ z-index: 50; @media (max-width: 991px) { - width: 225px; + width: var(--sidebar-width, 225px); position: fixed; top: 3.85rem; right: 0; @@ -478,7 +478,7 @@ } &.active { - width: 225px; + width: var(--sidebar-width, 225px); opacity: 1; pointer-events: auto; margin-left: 1rem; diff --git a/booklore-ui/src/app/features/book/components/book-browser/book-filter/book-filter.component.scss b/booklore-ui/src/app/features/book/components/book-browser/book-filter/book-filter.component.scss index eeff3e830..b169bcd96 100644 --- a/booklore-ui/src/app/features/book/components/book-browser/book-filter/book-filter.component.scss +++ b/booklore-ui/src/app/features/book/components/book-browser/book-filter/book-filter.component.scss @@ -7,7 +7,7 @@ } :host ::ng-deep .cdk-virtual-scroll-orientation-vertical .cdk-virtual-scroll-content-wrapper { - width: 190px !important; + width: calc(var(--sidebar-width, 225px) - 35px) !important; min-width: unset; } diff --git a/booklore-ui/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.html b/booklore-ui/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.html index 1c1b148cc..9f7ae3b98 100644 --- a/booklore-ui/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.html +++ b/booklore-ui/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.html @@ -17,5 +17,39 @@

+

+ +
+
+

+ + {{ t('layout.sectionTitle') }} +

+
+ +
+
+
+
+ +
+ + +
+
+

+ + {{ t('layout.sidebarWidthDesc') }} +

+
+
+
+
diff --git a/booklore-ui/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.scss b/booklore-ui/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.scss index 8712923ac..253aabd07 100644 --- a/booklore-ui/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.scss +++ b/booklore-ui/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.scss @@ -16,3 +16,93 @@ } @include settings.settings-section-divider; + +.preferences-section { + @media (min-width: 768px) { + padding: 0 1rem; + } +} + +.section-header { + @include settings.settings-section-header; + margin-bottom: 1rem; +} + +.section-title { + @include settings.settings-section-title; + margin: 0; +} + +.settings-card { + @include settings.settings-card; +} + +.setting-item { + display: flex; + align-items: flex-start; + gap: 2rem; + + &:last-child { + border-bottom: none; + padding-bottom: 0; + } + + @media (max-width: 768px) { + flex-direction: column; + gap: 1rem; + } +} + +.setting-info { + flex: 1; + min-width: 0; + + .setting-label { + display: block; + font-weight: settings.$settings-section-title-weight; + color: var(--p-text-color); + font-size: 1rem; + margin-bottom: 0.5rem; + } + + .setting-label-row { + display: flex; + align-items: center; + gap: 1rem; + margin-bottom: 0.5rem; + flex-wrap: wrap; + + .setting-label { + margin-bottom: 0; + flex-shrink: 0; + min-width: 180px; + } + } + + .setting-description { + display: flex; + align-items: flex-start; + gap: 0.5rem; + color: var(--p-text-muted-color); + font-size: settings.$settings-section-description-size; + line-height: 1.5; + margin: 0; + + .pi { + color: var(--p-primary-color); + margin-top: 0.125rem; + flex-shrink: 0; + } + } +} + +.slider-container { + flex: 1; + min-width: 200px; + max-width: 300px; + + @media (max-width: 768px) { + min-width: 180px; + max-width: 250px; + } +} diff --git a/booklore-ui/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.ts b/booklore-ui/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.ts index c08dd6748..8e8ae6b15 100644 --- a/booklore-ui/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.ts +++ b/booklore-ui/src/app/features/settings/view-preferences-parent/view-preferences-parent.component.ts @@ -1,4 +1,4 @@ -import {Component} from '@angular/core'; +import {Component, inject, OnInit} from '@angular/core'; import {FormsModule} from '@angular/forms'; import {TableModule} from 'primeng/table'; import {ToastModule} from 'primeng/toast'; @@ -6,7 +6,10 @@ import {ViewPreferencesComponent} from './view-preferences/view-preferences.comp import {SidebarSortingPreferencesComponent} from './sidebar-sorting-preferences/sidebar-sorting-preferences.component'; import {MetaCenterViewModeComponent} from './meta-center-view-mode/meta-center-view-mode-component'; import {FilterPreferencesComponent} from './filter-preferences/filter-preferences.component'; -import {TranslocoDirective} from '@jsverse/transloco'; +import {TranslocoDirective, TranslocoService} from '@jsverse/transloco'; +import {Slider} from 'primeng/slider'; +import {MessageService} from 'primeng/api'; +import {LocalStorageService} from '../../../shared/service/local-storage.service'; @Component({ selector: 'app-view-preferences-parent', @@ -20,10 +23,33 @@ import {TranslocoDirective} from '@jsverse/transloco'; MetaCenterViewModeComponent, FilterPreferencesComponent, TranslocoDirective, + Slider, ], templateUrl: './view-preferences-parent.component.html', styleUrl: './view-preferences-parent.component.scss' }) -export class ViewPreferencesParentComponent { +export class ViewPreferencesParentComponent implements OnInit { + sidebarWidth = 225; + + private localStorageService = inject(LocalStorageService); + private messageService = inject(MessageService); + private t = inject(TranslocoService); + + ngOnInit(): void { + this.sidebarWidth = this.localStorageService.get('sidebarWidth') ?? 225; + } + + onSidebarWidthChange(): void { + document.documentElement.style.setProperty('--sidebar-width', this.sidebarWidth + 'px'); + } + + saveSidebarWidth(): void { + this.localStorageService.set('sidebarWidth', this.sidebarWidth); + this.messageService.add({ + severity: 'success', + summary: this.t.translate('settingsView.layout.saved'), + detail: this.t.translate('settingsView.layout.savedDetail') + }); + } } diff --git a/booklore-ui/src/app/shared/layout/component/layout-main/app.layout.component.html b/booklore-ui/src/app/shared/layout/component/layout-main/app.layout.component.html index 13e3242e1..72aa99804 100644 --- a/booklore-ui/src/app/shared/layout/component/layout-main/app.layout.component.html +++ b/booklore-ui/src/app/shared/layout/component/layout-main/app.layout.component.html @@ -1,6 +1,6 @@
-
+
diff --git a/booklore-ui/src/app/shared/layout/component/layout-main/app.layout.component.ts b/booklore-ui/src/app/shared/layout/component/layout-main/app.layout.component.ts index 61f0736d9..1e885a00b 100644 --- a/booklore-ui/src/app/shared/layout/component/layout-main/app.layout.component.ts +++ b/booklore-ui/src/app/shared/layout/component/layout-main/app.layout.component.ts @@ -1,4 +1,4 @@ -import {Component, OnDestroy, Renderer2, ViewChild} from '@angular/core'; +import {Component, OnDestroy, OnInit, Renderer2, ViewChild} from '@angular/core'; import {NavigationEnd, Router, RouterOutlet} from '@angular/router'; import {filter, Subscription} from 'rxjs'; import {LayoutService} from "./service/app.layout.service"; @@ -6,6 +6,7 @@ import {AppSidebarComponent} from "../layout-sidebar/app.sidebar.component"; import {AppTopBarComponent} from '../layout-topbar/app.topbar.component'; import {NgClass} from '@angular/common'; import {ToastModule} from 'primeng/toast'; +import {LocalStorageService} from '../../../service/local-storage.service'; @Component({ selector: 'app-layout', @@ -18,7 +19,7 @@ import {ToastModule} from 'primeng/toast'; ], templateUrl: './app.layout.component.html' }) -export class AppLayoutComponent implements OnDestroy { +export class AppLayoutComponent implements OnInit, OnDestroy { overlayMenuOpenSubscription: Subscription; @@ -30,7 +31,7 @@ export class AppLayoutComponent implements OnDestroy { @ViewChild(AppTopBarComponent) appTopbar!: AppTopBarComponent; - constructor(public layoutService: LayoutService, public renderer: Renderer2, public router: Router) { + constructor(public layoutService: LayoutService, public renderer: Renderer2, public router: Router, private localStorageService: LocalStorageService) { this.overlayMenuOpenSubscription = this.layoutService.overlayOpen$.subscribe(() => { if (!this.menuOutsideClickListener) { this.menuOutsideClickListener = this.renderer.listen('document', 'click', (event) => { @@ -52,6 +53,11 @@ export class AppLayoutComponent implements OnDestroy { }); } + ngOnInit(): void { + const width = this.localStorageService.get('sidebarWidth') ?? 225; + document.documentElement.style.setProperty('--sidebar-width', width + 'px'); + } + isOutsideClicked(event: MouseEvent): boolean { const sidebarEl = document.querySelector('.layout-sidebar'); const topbarEl = document.querySelector('.layout-menu-button'); diff --git a/booklore-ui/src/app/shared/layout/component/layout-menu/app.menu.component.html b/booklore-ui/src/app/shared/layout/component/layout-menu/app.menu.component.html index d189901c2..bbe216ef9 100644 --- a/booklore-ui/src/app/shared/layout/component/layout-menu/app.menu.component.html +++ b/booklore-ui/src/app/shared/layout/component/layout-menu/app.menu.component.html @@ -1,15 +1,32 @@