Relocate sidebar filter setting to Library/Shelf header

This commit is contained in:
aditya.chandel
2025-06-12 23:29:22 -06:00
committed by Aditya Chandel
parent 25e59323f3
commit 2fe7b0b5e3
12 changed files with 142 additions and 168 deletions
@@ -1,29 +0,0 @@
<div class="p-4">
<div class="flex items-center gap-2 pb-6 pt-4">
<p class="text-lg">Sidebar Filter Sorting:</p>
<i class="pi pi-info-circle text-sky-600"
pTooltip="This setting controls the order in which filter values (like authors, categories, etc.) appear in the sidebar."
tooltipPosition="right"
style="cursor: pointer;">
</i>
</div>
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
<p class="py-1">Sorting Mode:
<i class="pi pi-info-circle text-sky-600"
pTooltip="You can sort filter options alphabetically (A–Z) or by the number of books that match each filter value. For example, categories with more books can appear at the top."
tooltipPosition="right"
style="cursor: pointer;">
</i>
</p>
<div class="flex gap-4 justify-start">
<p-select
size="small"
[options]="filterSortingOptions"
[(ngModel)]="selectedFilterSorting"
(ngModelChange)="onFilterSortingChange()"
placeholder="Select Sorting">
</p-select>
</div>
</div>
</div>
@@ -1,74 +0,0 @@
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
import {Select} from 'primeng/select';
import {Tooltip} from 'primeng/tooltip';
import {User, UserService, UserSettings} from '../../user-management/user.service';
import {MessageService} from 'primeng/api';
import {Observable, Subscription} from 'rxjs';
import {FormsModule} from '@angular/forms';
@Component({
selector: 'app-sidebar-filter-sorting-prefs-component',
imports: [
Select,
Tooltip,
FormsModule
],
templateUrl: './sidebar-filter-sorting-prefs-component.html',
styleUrl: './sidebar-filter-sorting-prefs-component.scss'
})
export class SidebarFilterSortingPrefsComponent implements OnInit, OnDestroy {
readonly filterSortingOptions = [
{label: 'Alphabetical (A–Z)', value: 'alphabetical'},
{label: 'Book Count (High to Low)', value: 'count'}
];
selectedFilterSorting: 'alphabetical' | 'count' = 'count';
private readonly userService = inject(UserService);
private readonly messageService = inject(MessageService);
userData$: Observable<User | null> = this.userService.userState$;
private subscription?: Subscription;
private currentUser: User | null = null;
ngOnInit(): void {
this.subscription = this.userData$.subscribe(user => {
if (user) {
this.currentUser = user;
this.loadPreferences(user.userSettings);
}
});
}
ngOnDestroy(): void {
this.subscription?.unsubscribe();
}
private loadPreferences(settings: UserSettings): void {
this.selectedFilterSorting = settings.filterSortingMode;
}
private updatePreference(path: string[], value: any): void {
if (!this.currentUser) return;
let target: any = this.currentUser.userSettings;
for (let i = 0; i < path.length - 1; i++) {
target = target[path[i]] ||= {};
}
target[path.at(-1)!] = value;
const [rootKey] = path;
const updatedValue = this.currentUser.userSettings[rootKey as keyof UserSettings];
this.userService.updateUserSetting(this.currentUser.id, rootKey, updatedValue);
this.messageService.add({
severity: 'success',
summary: 'Preferences Updated',
detail: 'Your preferences have been saved successfully.',
life: 2000
});
}
onFilterSortingChange(): void {
this.updatePreference(['filterSortingMode'], this.selectedFilterSorting);
}
}
@@ -68,7 +68,7 @@ export class SidebarSortingPreferencesComponent implements OnInit, OnDestroy {
severity: 'success',
summary: 'Preferences Updated',
detail: 'Your preferences have been saved successfully.',
life: 2000
life: 1500
});
}
@@ -2,6 +2,4 @@
<app-view-preferences></app-view-preferences>
<p-divider></p-divider>
<app-sidebar-sorting-preferences></app-sidebar-sorting-preferences>
<p-divider></p-divider>
<app-sidebar-filter-sorting-prefs-component></app-sidebar-filter-sorting-prefs-component>
</div>
@@ -5,7 +5,6 @@ import {TableModule} from 'primeng/table';
import {ToastModule} from 'primeng/toast';
import {ViewPreferencesComponent} from './view-preferences/view-preferences.component';
import {SidebarSortingPreferencesComponent} from './sidebar-sorting-preferences/sidebar-sorting-preferences.component';
import {SidebarFilterSortingPrefsComponent} from './sidebar-filter-sorting-prefs-component/sidebar-filter-sorting-prefs-component';
@Component({
selector: 'app-view-preferences-parent',
@@ -16,8 +15,7 @@ import {SidebarFilterSortingPrefsComponent} from './sidebar-filter-sorting-prefs
TableModule,
ToastModule,
ViewPreferencesComponent,
SidebarSortingPreferencesComponent,
SidebarFilterSortingPrefsComponent
SidebarSortingPreferencesComponent
],
templateUrl: './view-preferences-parent.component.html',
styleUrl: './view-preferences-parent.component.scss'