From 9c6d45eecd12b38f5d9624232e5fc2f276c04ab1 Mon Sep 17 00:00:00 2001
From: "aditya.chandel" <>
Date: Tue, 27 May 2025 16:19:59 -0600
Subject: [PATCH 1/5] Remove deprecated rating box from the UI
---
.../metadata-editor.component.html | 27 +++++--------------
.../metadata-picker.component.ts | 2 +-
2 files changed, 7 insertions(+), 22 deletions(-)
diff --git a/booklore-ui/src/app/book/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html b/booklore-ui/src/app/book/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html
index 4a51b08db..35efb8241 100644
--- a/booklore-ui/src/app/book/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html
+++ b/booklore-ui/src/app/book/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html
@@ -119,7 +119,7 @@
-
-
+
-
diff --git a/booklore-ui/src/app/book/metadata/book-metadata-center/metadata-picker/metadata-picker.component.ts b/booklore-ui/src/app/book/metadata/book-metadata-center/metadata-picker/metadata-picker.component.ts
index 560c3eb74..b81e94877 100644
--- a/booklore-ui/src/app/book/metadata/book-metadata-center/metadata-picker/metadata-picker.component.ts
+++ b/booklore-ui/src/app/book/metadata/book-metadata-center/metadata-picker/metadata-picker.component.ts
@@ -247,7 +247,7 @@ export class MetadataPickerComponent implements OnInit {
publishedDateLocked: this.metadataForm.get('publishedDateLocked')?.value,
isbn10Locked: this.metadataForm.get('isbn10Locked')?.value,
isbn13Locked: this.metadataForm.get('isbn13Locked')?.value,
- asinLocked: this.metadataForm.get('asin')?.value,
+ asinLocked: this.metadataForm.get('asinLocked')?.value,
descriptionLocked: this.metadataForm.get('descriptionLocked')?.value,
pageCountLocked: this.metadataForm.get('pageCountLocked')?.value,
languageLocked: this.metadataForm.get('languageLocked')?.value,
From 9acd06263449eb26cd4929fdd0adf73ab0071980 Mon Sep 17 00:00:00 2001
From: "aditya.chandel" <>
Date: Tue, 27 May 2025 22:03:28 -0600
Subject: [PATCH 2/5] Support per-library and per-shelf sorting and view
preferences
---
.../custom/BookLoreUserTransformer.java | 4 +
.../booklore/model/dto/BookLoreUser.java | 40 ++++
.../model/dto/settings/UserSettingKey.java | 3 +-
.../book-browser/book-browser.component.ts | 89 +++++----
.../book-filter/book-filter.component.ts | 4 -
.../src/app/book/service/library.service.ts | 3 -
.../reader-preferences.component.html} | 48 -----
.../reader-preferences.component.scss} | 0
.../reader-preferences.component.ts} | 33 +---
.../src/app/settings/settings.component.html | 14 +-
.../src/app/settings/settings.component.ts | 17 +-
.../settings/user-management/user.service.ts | 22 ++-
...sidebar-sorting-preferences.component.html | 46 +++++
...sidebar-sorting-preferences.component.scss | 0
.../sidebar-sorting-preferences.component.ts | 84 +++++++++
.../view-preferences-parent.component.html | 5 +
.../view-preferences-parent.component.scss | 3 +
.../view-preferences-parent.component.ts | 25 +++
.../view-preferences.component.html | 79 ++++++++
.../view-preferences.component.scss | 0
.../view-preferences.component.ts | 175 ++++++++++++++++++
21 files changed, 559 insertions(+), 135 deletions(-)
rename booklore-ui/src/app/settings/{user-preferences/user-preferences.component.html => reader-preferences/reader-preferences.component.html} (80%)
rename booklore-ui/src/app/settings/{user-preferences/user-preferences.component.scss => reader-preferences/reader-preferences.component.scss} (100%)
rename booklore-ui/src/app/settings/{user-preferences/user-preferences.component.ts => reader-preferences/reader-preferences.component.ts} (82%)
create mode 100644 booklore-ui/src/app/settings/view-preferences-parent/sidebar-sorting-preferences/sidebar-sorting-preferences.component.html
create mode 100644 booklore-ui/src/app/settings/view-preferences-parent/sidebar-sorting-preferences/sidebar-sorting-preferences.component.scss
create mode 100644 booklore-ui/src/app/settings/view-preferences-parent/sidebar-sorting-preferences/sidebar-sorting-preferences.component.ts
create mode 100644 booklore-ui/src/app/settings/view-preferences-parent/view-preferences-parent.component.html
create mode 100644 booklore-ui/src/app/settings/view-preferences-parent/view-preferences-parent.component.scss
create mode 100644 booklore-ui/src/app/settings/view-preferences-parent/view-preferences-parent.component.ts
create mode 100644 booklore-ui/src/app/settings/view-preferences-parent/view-preferences/view-preferences.component.html
create mode 100644 booklore-ui/src/app/settings/view-preferences-parent/view-preferences/view-preferences.component.scss
create mode 100644 booklore-ui/src/app/settings/view-preferences-parent/view-preferences/view-preferences.component.ts
diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/mapper/custom/BookLoreUserTransformer.java b/booklore-api/src/main/java/com/adityachandel/booklore/mapper/custom/BookLoreUserTransformer.java
index 7eecfbae8..3ed12b675 100644
--- a/booklore-api/src/main/java/com/adityachandel/booklore/mapper/custom/BookLoreUserTransformer.java
+++ b/booklore-api/src/main/java/com/adityachandel/booklore/mapper/custom/BookLoreUserTransformer.java
@@ -72,6 +72,10 @@ public class BookLoreUserTransformer {
var value = objectMapper.readValue(jsonValue, SidebarSortOption.class);
userSettings.setSidebarShelfSorting(value);
}
+ case ENTITY_VIEW_PREFERENCES -> {
+ var value = objectMapper.readValue(jsonValue, BookLoreUser.UserSettings.EntityViewPreferences.class);
+ userSettings.setEntityViewPreferences(value);
+ }
}
} catch (IllegalArgumentException e) {
diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/BookLoreUser.java b/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/BookLoreUser.java
index d30e98c08..a67d0d2cc 100644
--- a/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/BookLoreUser.java
+++ b/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/BookLoreUser.java
@@ -41,6 +41,46 @@ public class BookLoreUser {
public CbxReaderSetting cbxReaderSetting;
public SidebarSortOption sidebarLibrarySorting;
public SidebarSortOption sidebarShelfSorting;
+ public EntityViewPreferences entityViewPreferences;
+
+ @Data
+ @Builder
+ @AllArgsConstructor
+ @NoArgsConstructor
+ public static class EntityViewPreferences {
+ private GlobalPreferences global;
+ private List overrides;
+ }
+
+ @Data
+ @Builder
+ @AllArgsConstructor
+ @NoArgsConstructor
+ public static class GlobalPreferences {
+ private String sortKey;
+ private String sortDir;
+ private String view;
+ }
+
+ @Data
+ @Builder
+ @AllArgsConstructor
+ @NoArgsConstructor
+ public static class OverridePreference {
+ private String entityType;
+ private Long entityId;
+ private OverrideDetails preferences;
+ }
+
+ @Data
+ @Builder
+ @AllArgsConstructor
+ @NoArgsConstructor
+ public static class OverrideDetails {
+ private String sortKey;
+ private String sortDir;
+ private String view;
+ }
@Data
@Builder
diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/settings/UserSettingKey.java b/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/settings/UserSettingKey.java
index 14a9fef48..36b3016c4 100644
--- a/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/settings/UserSettingKey.java
+++ b/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/settings/UserSettingKey.java
@@ -9,7 +9,8 @@ public enum UserSettingKey {
EPUB_READER_SETTING("epubReaderSetting", true),
CBX_READER_SETTING("cbxReaderSetting", true),
SIDEBAR_LIBRARY_SORTING("sidebarLibrarySorting", true),
- SIDEBAR_SHELF_SORTING("sidebarShelfSorting", true);
+ SIDEBAR_SHELF_SORTING("sidebarShelfSorting", true),
+ ENTITY_VIEW_PREFERENCES("entityViewPreferences", true);
private final String dbKey;
private final boolean isJson;
diff --git a/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts b/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts
index 0cb372754..f9ad7e7f0 100644
--- a/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts
+++ b/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts
@@ -550,55 +550,70 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
const directionParam = paramMap.get(QUERY_PARAMS.DIRECTION);
const filterParam = paramMap.get(QUERY_PARAMS.FILTER);
- this.currentViewMode = viewParam === VIEW_MODES.TABLE || viewParam === VIEW_MODES.GRID ? viewParam : VIEW_MODES.GRID;
+ this.userService.getMyself().subscribe(user => {
+ const prefs = user.userSettings?.entityViewPreferences;
+ const globalPrefs = prefs?.global;
+ const currentEntityTypeStr = this.entityType ? this.entityType.toString().toUpperCase() : undefined;
- const matchingSort = this.sortOptions.find(opt => opt.field === sortParam);
- const direction = directionParam === SORT_DIRECTION.DESCENDING ? SortDirection.DESCENDING : SortDirection.ASCENDING;
- this.bookFilterComponent.showFilters = filterParam === 'true' || (filterParam === null && this.filterVisibility);
+ const override = prefs?.overrides?.find(o =>
+ o.entityType?.toUpperCase() === currentEntityTypeStr &&
+ o.entityId === this.entity?.id
+ );
- if (matchingSort) {
- this.selectedSort = {
- label: matchingSort.label,
- field: matchingSort.field,
- direction
+ const effectivePrefs = override?.preferences ?? globalPrefs ?? {
+ sortKey: 'addedOn',
+ sortDir: 'ASC',
+ view: VIEW_MODES.GRID
};
- } else {
- this.selectedSort = {
+
+ const userSortKey = effectivePrefs.sortKey;
+ const userSortDir = effectivePrefs.sortDir?.toUpperCase() === 'DESC' ? SortDirection.DESCENDING : SortDirection.ASCENDING;
+
+ const matchedSort = this.sortOptions.find(opt => opt.field === sortParam) || this.sortOptions.find(opt => opt.field === userSortKey);
+
+ this.selectedSort = matchedSort ? {
+ label: matchedSort.label,
+ field: matchedSort.field,
+ direction: directionParam ? (directionParam === SORT_DIRECTION.DESCENDING ? SortDirection.DESCENDING : SortDirection.ASCENDING) : userSortDir
+ } : {
label: 'Added On',
field: 'addedOn',
direction: SortDirection.DESCENDING
};
- }
- if (this.lastAppliedSort?.field !== this.selectedSort.field ||
- this.lastAppliedSort?.direction !== this.selectedSort.direction) {
- this.lastAppliedSort = {...this.selectedSort};
- this.applySortOption(this.selectedSort);
- }
+ this.currentViewMode = (viewParam === VIEW_MODES.TABLE || viewParam === VIEW_MODES.GRID) ? viewParam : effectivePrefs.view?.toLowerCase() ?? VIEW_MODES.GRID;
+ this.bookFilterComponent.showFilters = filterParam === 'true' || (filterParam === null && this.filterVisibility);
+ this.updateSortOptions();
- const queryParams: any = {
- [QUERY_PARAMS.VIEW]: this.currentViewMode,
- [QUERY_PARAMS.SORT]: this.selectedSort.field,
- [QUERY_PARAMS.DIRECTION]: this.selectedSort.direction === SortDirection.ASCENDING ? SORT_DIRECTION.ASCENDING : SORT_DIRECTION.DESCENDING,
- [QUERY_PARAMS.FILTER]: this.bookFilterComponent.showFilters.toString()
- };
+ if (this.lastAppliedSort?.field !== this.selectedSort.field || this.lastAppliedSort?.direction !== this.selectedSort.direction) {
+ this.lastAppliedSort = {...this.selectedSort};
+ this.applySortOption(this.selectedSort);
+ }
- const currentParams = this.activatedRoute.snapshot.queryParams;
+ const queryParams: any = {
+ [QUERY_PARAMS.VIEW]: this.currentViewMode,
+ [QUERY_PARAMS.SORT]: this.selectedSort.field,
+ [QUERY_PARAMS.DIRECTION]: this.selectedSort.direction === SortDirection.ASCENDING ? SORT_DIRECTION.ASCENDING : SORT_DIRECTION.DESCENDING,
+ [QUERY_PARAMS.FILTER]: this.bookFilterComponent.showFilters.toString()
+ };
- if (
- currentParams[QUERY_PARAMS.VIEW] !== queryParams[QUERY_PARAMS.VIEW] ||
- currentParams[QUERY_PARAMS.SORT] !== queryParams[QUERY_PARAMS.SORT] ||
- currentParams[QUERY_PARAMS.DIRECTION] !== queryParams[QUERY_PARAMS.DIRECTION] ||
- currentParams[QUERY_PARAMS.FILTER] !== queryParams[QUERY_PARAMS.FILTER]
- ) {
- this.router.navigate([], {
- queryParams,
- replaceUrl: true
- });
- }
+ const currentParams = this.activatedRoute.snapshot.queryParams;
+
+ if (
+ currentParams[QUERY_PARAMS.VIEW] !== queryParams[QUERY_PARAMS.VIEW] ||
+ currentParams[QUERY_PARAMS.SORT] !== queryParams[QUERY_PARAMS.SORT] ||
+ currentParams[QUERY_PARAMS.DIRECTION] !== queryParams[QUERY_PARAMS.DIRECTION] ||
+ currentParams[QUERY_PARAMS.FILTER] !== queryParams[QUERY_PARAMS.FILTER]
+ ) {
+ this.router.navigate([], {
+ queryParams,
+ replaceUrl: true
+ });
+ }
+
+ this.cdr.detectChanges();
+ });
});
-
- this.cdr.detectChanges();
}
lockUnlockMetadata() {
diff --git a/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.ts b/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.ts
index 89bed169d..f108a7ea7 100644
--- a/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.ts
+++ b/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.ts
@@ -98,17 +98,13 @@ export class BookFilterComponent implements OnInit {
const index = this.activeFilters[filterType].indexOf(value);
if (index > -1) {
- // Deselect
this.activeFilters[filterType].splice(index, 1);
if (this.activeFilters[filterType].length === 0) {
delete this.activeFilters[filterType];
}
} else {
- // Select
this.activeFilters[filterType].push(value);
}
-
- // Emit updated filter state
this.filterSelected.emit({ ...this.activeFilters });
}
diff --git a/booklore-ui/src/app/book/service/library.service.ts b/booklore-ui/src/app/book/service/library.service.ts
index 9f231ac0c..cc52fc94f 100644
--- a/booklore-ui/src/app/book/service/library.service.ts
+++ b/booklore-ui/src/app/book/service/library.service.ts
@@ -4,11 +4,8 @@ import {HttpClient} from '@angular/common/http';
import {catchError, map} from 'rxjs/operators';
import {Library} from '../model/library.model';
import {BookService} from './book.service';
-import {SortOption} from '../model/sort.model';
import {LibraryState} from '../model/state/library-state.model';
import {API_CONFIG} from '../../config/api-config';
-import {FetchMetadataRequest} from '../metadata/model/request/fetch-metadata-request.model';
-import {BookMetadata} from '../model/book.model';
@Injectable({
providedIn: 'root',
diff --git a/booklore-ui/src/app/settings/user-preferences/user-preferences.component.html b/booklore-ui/src/app/settings/reader-preferences/reader-preferences.component.html
similarity index 80%
rename from booklore-ui/src/app/settings/user-preferences/user-preferences.component.html
rename to booklore-ui/src/app/settings/reader-preferences/reader-preferences.component.html
index 5c3947d47..cf05a4be8 100644
--- a/booklore-ui/src/app/settings/user-preferences/user-preferences.component.html
+++ b/booklore-ui/src/app/settings/reader-preferences/reader-preferences.component.html
@@ -201,52 +201,4 @@
-
-
-
-
-
Sidebar Library and Shelf Sorting Perference
-
-
-
-
-
-
Library:
-
-
-
-
-
-
Shelf:
-
-
-
-
-
-
diff --git a/booklore-ui/src/app/settings/user-preferences/user-preferences.component.scss b/booklore-ui/src/app/settings/reader-preferences/reader-preferences.component.scss
similarity index 100%
rename from booklore-ui/src/app/settings/user-preferences/user-preferences.component.scss
rename to booklore-ui/src/app/settings/reader-preferences/reader-preferences.component.scss
diff --git a/booklore-ui/src/app/settings/user-preferences/user-preferences.component.ts b/booklore-ui/src/app/settings/reader-preferences/reader-preferences.component.ts
similarity index 82%
rename from booklore-ui/src/app/settings/user-preferences/user-preferences.component.ts
rename to booklore-ui/src/app/settings/reader-preferences/reader-preferences.component.ts
index 0753ddeee..3aefa33bf 100644
--- a/booklore-ui/src/app/settings/user-preferences/user-preferences.component.ts
+++ b/booklore-ui/src/app/settings/reader-preferences/reader-preferences.component.ts
@@ -7,19 +7,18 @@ import {RadioButton} from 'primeng/radiobutton';
import {Divider} from 'primeng/divider';
import {Button} from 'primeng/button';
import {Tooltip} from 'primeng/tooltip';
-import {SidebarLibrarySorting, SidebarShelfSorting, User, UserService, UserSettings} from '../user-management/user.service';
+import {User, UserService, UserSettings} from '../user-management/user.service';
import {MessageService} from 'primeng/api';
import {CbxPageSpread, CbxPageViewMode} from '../../book/model/book.model';
@Component({
- selector: 'app-user-preferences',
- templateUrl: './user-preferences.component.html',
+ selector: 'app-reader-preferences',
+ templateUrl: './reader-preferences.component.html',
standalone: true,
- styleUrls: ['./user-preferences.component.scss'],
+ styleUrls: ['./reader-preferences.component.scss'],
imports: [Select, FormsModule, NgForOf, RadioButton, Divider, Button, Tooltip]
})
-export class UserPreferences implements OnInit, OnDestroy {
-
+export class ReaderPreferences implements OnInit, OnDestroy {
readonly cbxSpreads = [
{name: 'Even', key: 'EVEN'},
@@ -65,16 +64,8 @@ export class UserPreferences implements OnInit, OnDestroy {
{name: 'Scrolled', key: 'scrolled'}
];
- readonly sortingOptions = [
- {label: 'Name | Ascending', value: {field: 'name', order: 'asc'}},
- {label: 'Name | Descending', value: {field: 'name', order: 'desc'}},
- {label: 'Creation Date | Ascending', value: {field: 'id', order: 'asc'}},
- {label: 'Creation Date | Descending', value: {field: 'id', order: 'desc'}},
- ];
-
readonly scopeOptions = ['Global', 'Individual'];
-
selectedCbxSpread!: CbxPageSpread;
selectedCbxViewMode!: CbxPageViewMode;
@@ -90,9 +81,6 @@ export class UserPreferences implements OnInit, OnDestroy {
selectedEpubScope!: string;
selectedCbxScope!: string;
- selectedLibrarySorting: SidebarLibrarySorting = {field: 'id', order: 'asc'};
- selectedShelfSorting: SidebarShelfSorting = {field: 'id', order: 'asc'};
-
private readonly userService = inject(UserService);
private readonly messageService = inject(MessageService);
@@ -129,9 +117,6 @@ export class UserPreferences implements OnInit, OnDestroy {
this.selectedCbxSpread = settings.cbxReaderSetting.pageSpread;
this.selectedCbxViewMode = settings.cbxReaderSetting.pageViewMode;
-
- this.selectedLibrarySorting = settings.sidebarLibrarySorting;
- this.selectedShelfSorting = settings.sidebarShelfSorting;
}
private updatePreference(path: string[], value: any): void {
@@ -197,14 +182,6 @@ export class UserPreferences implements OnInit, OnDestroy {
this.updatePreference(['perBookSetting', 'cbx'], this.selectedCbxScope);
}
- onLibrarySortingChange() {
- this.updatePreference(['sidebarLibrarySorting'], this.selectedLibrarySorting);
- }
-
- onShelfSortingChange() {
- this.updatePreference(['sidebarShelfSorting'], this.selectedShelfSorting);
- }
-
increaseFontSize() {
if (this.fontSize < 250) {
this.fontSize += 10;
diff --git a/booklore-ui/src/app/settings/settings.component.html b/booklore-ui/src/app/settings/settings.component.html
index 43306085f..67ab6189a 100644
--- a/booklore-ui/src/app/settings/settings.component.html
+++ b/booklore-ui/src/app/settings/settings.component.html
@@ -2,18 +2,22 @@
- User Preferences
+ Reader Preferences
+ View Preferences
Global Settings
User Management
- Email Setting
+ Email Setting
Authentication Settings
-
-
+
+
+
+
+
@@ -22,7 +26,7 @@
-
+
diff --git a/booklore-ui/src/app/settings/settings.component.ts b/booklore-ui/src/app/settings/settings.component.ts
index 348265f64..8f8bafb88 100644
--- a/booklore-ui/src/app/settings/settings.component.ts
+++ b/booklore-ui/src/app/settings/settings.component.ts
@@ -8,12 +8,14 @@ import {ActivatedRoute, Router} from '@angular/router';
import {Subscription} from 'rxjs';
import {UserManagementComponent} from './user-management/user-management.component';
import {AuthenticationSettingsComponent} from '../core/security/oauth2-management/authentication-settings.component';
-import {UserPreferences} from './user-preferences/user-preferences.component';
+import {ViewPreferencesParentComponent} from './view-preferences-parent/view-preferences-parent.component';
+import {ReaderPreferences} from './reader-preferences/reader-preferences.component';
export enum SettingsTab {
- BookReader = 'book-reader',
+ ReaderSettings = 'reader-settings',
+ ViewPreferences = 'view-settings',
UserManagement = 'user-management',
- Email = 'email',
+ EmailSettings = 'email-settings',
GlobalSettings = 'global-settings',
AuthenticationSettings = 'auth-settings'
}
@@ -26,13 +28,14 @@ export enum SettingsTab {
Tab,
TabPanels,
TabPanel,
- UserPreferences,
NgIf,
AsyncPipe,
EmailComponent,
GlobalPreferencesComponent,
UserManagementComponent,
- AuthenticationSettingsComponent
+ AuthenticationSettingsComponent,
+ ViewPreferencesParentComponent,
+ ReaderPreferences
],
templateUrl: './settings.component.html',
styleUrl: './settings.component.scss'
@@ -48,7 +51,7 @@ export class SettingsComponent implements OnInit, OnDestroy {
SettingsTab = SettingsTab;
private validTabs = Object.values(SettingsTab);
- private _activeTab: SettingsTab = SettingsTab.BookReader;
+ private _activeTab: SettingsTab = SettingsTab.ReaderSettings;
get activeTab(): SettingsTab {
return this._activeTab;
@@ -69,7 +72,7 @@ export class SettingsComponent implements OnInit, OnDestroy {
if (this.validTabs.includes(tabParam)) {
this._activeTab = tabParam as SettingsTab;
} else {
- this._activeTab = SettingsTab.BookReader;
+ this._activeTab = SettingsTab.ReaderSettings;
this.router.navigate([], {
relativeTo: this.route,
queryParams: { tab: this._activeTab },
diff --git a/booklore-ui/src/app/settings/user-management/user.service.ts b/booklore-ui/src/app/settings/user-management/user.service.ts
index 0e2665490..2e3f509a5 100644
--- a/booklore-ui/src/app/settings/user-management/user.service.ts
+++ b/booklore-ui/src/app/settings/user-management/user.service.ts
@@ -1,12 +1,29 @@
import {inject, Injectable, Injector} from '@angular/core';
import {HttpClient} from '@angular/common/http';
-import {BehaviorSubject, Observable, tap, throwError} from 'rxjs';
+import {BehaviorSubject, Observable, throwError} from 'rxjs';
import {API_CONFIG} from '../../config/api-config';
import {RxStompService} from '../../shared/websocket/rx-stomp.service';
import {Library} from '../../book/model/library.model';
import {catchError} from 'rxjs/operators';
import {CbxPageSpread, CbxPageViewMode} from '../../book/model/book.model';
+export interface EntityViewPreferences {
+ global: EntityViewPreference;
+ overrides: EntityViewPreferenceOverride[];
+}
+
+export interface EntityViewPreference {
+ sortKey: string;
+ sortDir: 'ASC' | 'DESC';
+ view: 'GRID' | 'TABLE';
+}
+
+export interface EntityViewPreferenceOverride {
+ entityType: 'LIBRARY' | 'SHELF';
+ entityId: number;
+ preferences: EntityViewPreference;
+}
+
export interface SidebarLibrarySorting {
field: string;
order: string;
@@ -49,7 +66,8 @@ export interface UserSettings {
epubReaderSetting: EpubReaderSetting;
cbxReaderSetting: CbxReaderSetting;
sidebarLibrarySorting: SidebarLibrarySorting;
- sidebarShelfSorting: SidebarShelfSorting
+ sidebarShelfSorting: SidebarShelfSorting;
+ entityViewPreferences: EntityViewPreferences;
}
export interface User {
diff --git a/booklore-ui/src/app/settings/view-preferences-parent/sidebar-sorting-preferences/sidebar-sorting-preferences.component.html b/booklore-ui/src/app/settings/view-preferences-parent/sidebar-sorting-preferences/sidebar-sorting-preferences.component.html
new file mode 100644
index 000000000..8ecd0ae74
--- /dev/null
+++ b/booklore-ui/src/app/settings/view-preferences-parent/sidebar-sorting-preferences/sidebar-sorting-preferences.component.html
@@ -0,0 +1,46 @@
+
+
+
Sidebar Library and Shelf Sorting Perference
+
+
+
+
+
+
Library:
+
+
+
+
+
+
Shelf:
+
+
+
+
+
+
diff --git a/booklore-ui/src/app/settings/view-preferences-parent/sidebar-sorting-preferences/sidebar-sorting-preferences.component.scss b/booklore-ui/src/app/settings/view-preferences-parent/sidebar-sorting-preferences/sidebar-sorting-preferences.component.scss
new file mode 100644
index 000000000..e69de29bb
diff --git a/booklore-ui/src/app/settings/view-preferences-parent/sidebar-sorting-preferences/sidebar-sorting-preferences.component.ts b/booklore-ui/src/app/settings/view-preferences-parent/sidebar-sorting-preferences/sidebar-sorting-preferences.component.ts
new file mode 100644
index 000000000..bb8364f12
--- /dev/null
+++ b/booklore-ui/src/app/settings/view-preferences-parent/sidebar-sorting-preferences/sidebar-sorting-preferences.component.ts
@@ -0,0 +1,84 @@
+import {Component, inject, OnDestroy, OnInit} from '@angular/core';
+import {Select} from 'primeng/select';
+import {Tooltip} from 'primeng/tooltip';
+import {SidebarLibrarySorting, SidebarShelfSorting, 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-sorting-preferences',
+ imports: [
+ Select,
+ Tooltip,
+ FormsModule
+ ],
+ templateUrl: './sidebar-sorting-preferences.component.html',
+ styleUrl: './sidebar-sorting-preferences.component.scss'
+})
+export class SidebarSortingPreferencesComponent implements OnInit, OnDestroy {
+
+ readonly sortingOptions = [
+ {label: 'Name | Ascending', value: {field: 'name', order: 'asc'}},
+ {label: 'Name | Descending', value: {field: 'name', order: 'desc'}},
+ {label: 'Creation Date | Ascending', value: {field: 'id', order: 'asc'}},
+ {label: 'Creation Date | Descending', value: {field: 'id', order: 'desc'}},
+ ];
+
+ selectedLibrarySorting: SidebarLibrarySorting = {field: 'id', order: 'asc'};
+ selectedShelfSorting: SidebarShelfSorting = {field: 'id', order: 'asc'};
+
+ private readonly userService = inject(UserService);
+ private readonly messageService = inject(MessageService);
+
+ userData$: Observable = this.userService.userData$;
+ 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.selectedLibrarySorting = settings.sidebarLibrarySorting;
+ this.selectedShelfSorting = settings.sidebarShelfSorting;
+ }
+
+
+ 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
+ });
+ }
+
+ onLibrarySortingChange() {
+ this.updatePreference(['sidebarLibrarySorting'], this.selectedLibrarySorting);
+ }
+
+ onShelfSortingChange() {
+ this.updatePreference(['sidebarShelfSorting'], this.selectedShelfSorting);
+ }
+
+}
diff --git a/booklore-ui/src/app/settings/view-preferences-parent/view-preferences-parent.component.html b/booklore-ui/src/app/settings/view-preferences-parent/view-preferences-parent.component.html
new file mode 100644
index 000000000..6446e4c2d
--- /dev/null
+++ b/booklore-ui/src/app/settings/view-preferences-parent/view-preferences-parent.component.html
@@ -0,0 +1,5 @@
+
diff --git a/booklore-ui/src/app/settings/view-preferences-parent/view-preferences-parent.component.scss b/booklore-ui/src/app/settings/view-preferences-parent/view-preferences-parent.component.scss
new file mode 100644
index 000000000..b886b1f68
--- /dev/null
+++ b/booklore-ui/src/app/settings/view-preferences-parent/view-preferences-parent.component.scss
@@ -0,0 +1,3 @@
+.enclosing-container {
+ border-color: var(--p-content-border-color);
+}
diff --git a/booklore-ui/src/app/settings/view-preferences-parent/view-preferences-parent.component.ts b/booklore-ui/src/app/settings/view-preferences-parent/view-preferences-parent.component.ts
new file mode 100644
index 000000000..070c0b677
--- /dev/null
+++ b/booklore-ui/src/app/settings/view-preferences-parent/view-preferences-parent.component.ts
@@ -0,0 +1,25 @@
+import {Component} from '@angular/core';
+import {Divider} from 'primeng/divider';
+import {FormsModule} from '@angular/forms';
+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';
+
+@Component({
+ selector: 'app-view-preferences-parent',
+ standalone: true,
+ imports: [
+ Divider,
+ FormsModule,
+ TableModule,
+ ToastModule,
+ ViewPreferencesComponent,
+ SidebarSortingPreferencesComponent
+ ],
+ templateUrl: './view-preferences-parent.component.html',
+ styleUrl: './view-preferences-parent.component.scss'
+})
+export class ViewPreferencesParentComponent {
+
+}
diff --git a/booklore-ui/src/app/settings/view-preferences-parent/view-preferences/view-preferences.component.html b/booklore-ui/src/app/settings/view-preferences-parent/view-preferences/view-preferences.component.html
new file mode 100644
index 000000000..8f40a3151
--- /dev/null
+++ b/booklore-ui/src/app/settings/view-preferences-parent/view-preferences/view-preferences.component.html
@@ -0,0 +1,79 @@
+
+
+ Library and Shelf View & Sort Preferences:
+
+
+
+
+
+
+
+
+
0" [value]="overrides" class="relative z-0" [responsiveLayout]="'scroll'">
+
+
+ | Type |
+ Name |
+ Sort By |
+ Sort Dir |
+ View |
+ |
+
+
+
+
+
+ |
+
+
+
+
+
+ |
+
+ |
+
+ |
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
diff --git a/booklore-ui/src/app/settings/view-preferences-parent/view-preferences/view-preferences.component.scss b/booklore-ui/src/app/settings/view-preferences-parent/view-preferences/view-preferences.component.scss
new file mode 100644
index 000000000..e69de29bb
diff --git a/booklore-ui/src/app/settings/view-preferences-parent/view-preferences/view-preferences.component.ts b/booklore-ui/src/app/settings/view-preferences-parent/view-preferences/view-preferences.component.ts
new file mode 100644
index 000000000..2a41279ce
--- /dev/null
+++ b/booklore-ui/src/app/settings/view-preferences-parent/view-preferences/view-preferences.component.ts
@@ -0,0 +1,175 @@
+import {Component, inject, OnInit} from '@angular/core';
+import {Button} from 'primeng/button';
+import {NgIf} from '@angular/common';
+import {MessageService} from 'primeng/api';
+import {Select} from 'primeng/select';
+import {TableModule} from 'primeng/table';
+import {Tooltip} from 'primeng/tooltip';
+import {User, UserService} from '../../user-management/user.service';
+import {LibraryService} from '../../../book/service/library.service';
+import {ShelfService} from '../../../book/service/shelf.service';
+import {combineLatest} from 'rxjs';
+import {FormsModule} from '@angular/forms';
+import {ToastModule} from 'primeng/toast';
+
+@Component({
+ selector: 'app-view-preferences',
+ standalone: true,
+ imports: [
+ Select,
+ Tooltip,
+ FormsModule,
+ Button,
+ NgIf,
+ TableModule,
+ ToastModule
+ ],
+ templateUrl: './view-preferences.component.html',
+ styleUrl: './view-preferences.component.scss'
+})
+export class ViewPreferencesComponent implements OnInit {
+ sortOptions = [
+ {label: 'Title', field: 'title'},
+ {label: 'Title + Series', field: 'titleSeries'},
+ {label: 'Author', field: 'author'},
+ {label: 'Last Read', field: 'lastReadTime'},
+ {label: 'Added On', field: 'addedOn'},
+ {label: 'File Size', field: 'fileSizeKb'},
+ {label: 'Locked', field: 'locked'},
+ {label: 'Publisher', field: 'publisher'},
+ {label: 'Published Date', field: 'publishedDate'},
+ {label: 'Amazon Rating', field: 'amazonRating'},
+ {label: 'Amazon #', field: 'amazonReviewCount'},
+ {label: 'Goodreads Rating', field: 'goodreadsRating'},
+ {label: 'Goodreads #', field: 'goodreadsReviewCount'},
+ {label: 'Pages', field: 'pageCount'}
+ ];
+
+ entityTypeOptions = [
+ {label: 'Library', value: 'LIBRARY'},
+ {label: 'Shelf', value: 'SHELF'}
+ ];
+
+ sortDirectionOptions = [
+ {label: 'Ascending', value: 'ASC'},
+ {label: 'Descending', value: 'DESC'}
+ ];
+
+ viewModeOptions = [
+ {label: 'Grid', value: 'GRID'},
+ {label: 'Table', value: 'TABLE'}
+ ];
+
+ libraryOptions: { label: string; value: number }[] = [];
+ shelfOptions: { label: string; value: number }[] = [];
+
+ selectedSort: string = 'title';
+ selectedSortDir: 'ASC' | 'DESC' = 'ASC';
+ selectedView: 'GRID' | 'TABLE' = 'GRID';
+
+ overrides: {
+ entityType: 'LIBRARY' | 'SHELF';
+ library: number;
+ sort: string;
+ sortDir: 'ASC' | 'DESC';
+ view: 'GRID' | 'TABLE';
+ }[] = [];
+
+ private user: User | null = null;
+
+ private libraryService = inject(LibraryService);
+ private shelfService = inject(ShelfService);
+ private userService = inject(UserService);
+ private messageService = inject(MessageService);
+
+ ngOnInit(): void {
+ combineLatest([
+ this.userService.getMyself(),
+ this.libraryService.getAllLibrariesFromAPI(),
+ this.shelfService.shelfState$
+ ]).subscribe(([user, libraries, shelfState]) => {
+ this.user = user;
+
+ const prefs = user.userSettings?.entityViewPreferences;
+ const global = prefs?.global;
+ this.selectedSort = global?.sortKey ?? 'title';
+ this.selectedSortDir = global?.sortDir ?? 'ASC';
+ this.selectedView = global?.view ?? 'GRID';
+
+ this.overrides = (prefs?.overrides ?? []).map(o => ({
+ entityType: o.entityType,
+ library: o.entityId,
+ sort: o.preferences.sortKey,
+ sortDir: o.preferences.sortDir ?? 'ASC',
+ view: o.preferences.view ?? 'GRID'
+ }));
+
+ this.libraryOptions = (libraries ?? []).filter(lib => lib.id !== undefined).map(lib => ({
+ label: lib.name,
+ value: lib.id!
+ }));
+
+ this.shelfOptions = (shelfState?.shelves ?? []).filter(s => s.id !== undefined).map(s => ({
+ label: s.name,
+ value: s.id!
+ }));
+ });
+ }
+
+ getAvailableEntities(index: number, type: 'LIBRARY' | 'SHELF') {
+ const selected = this.overrides.map((o, i) => i !== index ? o.library : null);
+ const source = type === 'LIBRARY' ? this.libraryOptions : this.shelfOptions;
+ return source.filter(opt => !selected.includes(opt.value) || this.overrides[index]?.library === opt.value);
+ }
+
+ get availableLibraries() {
+ const used = new Set(this.overrides.map(o => `${o.entityType}_${o.library}`));
+
+ const withEntityType = (options: { label: string; value: number }[], entityType: 'LIBRARY' | 'SHELF') =>
+ options.map(opt => ({...opt, entityType}));
+
+ return [...withEntityType(this.libraryOptions, 'LIBRARY'), ...withEntityType(this.shelfOptions, 'SHELF')]
+ .filter(opt => !used.has(`${opt.entityType}_${opt.value}`));
+ }
+
+ addOverride(): void {
+ const next = this.availableLibraries[0];
+ if (next) {
+ this.overrides.push({
+ entityType: next.entityType,
+ library: next.value,
+ sort: 'title',
+ sortDir: 'ASC',
+ view: 'GRID'
+ });
+ }
+ }
+
+ removeOverride(index: number): void {
+ this.overrides.splice(index, 1);
+ }
+
+ saveSettings(): void {
+ if (!this.user) return;
+
+ const payload = {
+ global: {
+ sortKey: this.selectedSort,
+ sortDir: this.selectedSortDir,
+ view: this.selectedView
+ },
+ overrides: this.overrides.map(o => ({
+ entityType: o.entityType,
+ entityId: o.library,
+ preferences: {
+ sortKey: o.sort,
+ sortDir: o.sortDir,
+ view: o.view
+ }
+ }))
+ };
+
+ this.userService.updateUserSetting(this.user.id, 'entityViewPreferences', payload);
+ this.messageService.add({ severity: 'success', summary: 'Preferences Saved', detail: 'Your sorting and view preferences were saved successfully.' });
+ }
+}
From b9ad85857a3e31c2e30483d5beb4747f9c8ddefb Mon Sep 17 00:00:00 2001
From: "aditya.chandel" <>
Date: Tue, 27 May 2025 22:46:08 -0600
Subject: [PATCH 3/5] Optimize Settings logic to avoid duplicate service calls
---
.../book-browser/book-browser.component.html | 4 +--
.../book-card/book-card.component.ts | 2 +-
.../book-metadata-center.component.ts | 2 +-
.../metadata-viewer.component.html | 2 +-
.../authentication-settings.component.ts | 13 +++----
.../main-dashboard.component.html | 2 +-
.../layout-menu/app.menu.component.ts | 2 +-
.../layout-menu/app.menuitem.component.ts | 2 +-
.../layout-topbar/app.topbar.component.html | 4 +--
.../user-profile-dialog.component.ts | 2 +-
.../reader-preferences.component.ts | 2 +-
.../src/app/settings/settings.component.html | 2 +-
.../user-management.component.ts | 36 +++++--------------
.../settings/user-management/user.service.ts | 10 +++---
.../sidebar-sorting-preferences.component.ts | 2 +-
.../view-preferences.component.ts | 17 ++++-----
16 files changed, 42 insertions(+), 62 deletions(-)
diff --git a/booklore-ui/src/app/book/components/book-browser/book-browser.component.html b/booklore-ui/src/app/book/components/book-browser/book-browser.component.html
index a3aac50c2..e261e0ad5 100644
--- a/booklore-ui/src/app/book/components/book-browser/book-browser.component.html
+++ b/booklore-ui/src/app/book/components/book-browser/book-browser.component.html
@@ -12,7 +12,7 @@
Unshelved Books
-
+
@@ -149,7 +149,7 @@
pTooltip="Remove from shelf"
tooltipPosition="top">
-
+
!!userData))
.subscribe((userData) => {
this.userPermissions = userData.permissions;
diff --git a/booklore-ui/src/app/book/metadata/book-metadata-center/book-metadata-center.component.ts b/booklore-ui/src/app/book/metadata/book-metadata-center/book-metadata-center.component.ts
index 7372ca6bf..f2d52e788 100644
--- a/booklore-ui/src/app/book/metadata/book-metadata-center/book-metadata-center.component.ts
+++ b/booklore-ui/src/app/book/metadata/book-metadata-center/book-metadata-center.component.ts
@@ -77,7 +77,7 @@ export class BookMetadataCenterComponent implements OnInit, OnDestroy {
this.fetchBookRecommendationsIfNeeded(book.metadata!.bookId);
});
- this.userSubscription = this.userService.userData$.subscribe(userData => {
+ this.userSubscription = this.userService.userState$.subscribe(userData => {
const userPermissions = userData?.permissions;
this.canEditMetadata = userPermissions?.canEditMetadata ?? false;
this.admin = userPermissions?.admin ?? false;
diff --git a/booklore-ui/src/app/book/metadata/book-metadata-center/metadata-viewer/metadata-viewer.component.html b/booklore-ui/src/app/book/metadata/book-metadata-center/metadata-viewer/metadata-viewer.component.html
index b23917974..72866aaf1 100644
--- a/booklore-ui/src/app/book/metadata/book-metadata-center/metadata-viewer/metadata-viewer.component.html
+++ b/booklore-ui/src/app/book/metadata/book-metadata-center/metadata-viewer/metadata-viewer.component.html
@@ -124,7 +124,7 @@
-
+
this.loadSettings(settings));
- this.libraryService.getAllLibrariesFromAPI().subscribe({
- next: (libraries) => {
- this.allLibraries = libraries;
- },
- error: () => {
- this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to load libraries'});
- },
- });
+ this.libraryService.libraryState$
+ .pipe(
+ filter(state => !!state?.loaded),
+ take(1)
+ ).subscribe(state => this.allLibraries = state.libraries ?? []);
}
loadSettings(settings: AppSettings): void {
diff --git a/booklore-ui/src/app/dashboard/components/main-dashboard/main-dashboard.component.html b/booklore-ui/src/app/dashboard/components/main-dashboard/main-dashboard.component.html
index e3d14e9e8..9fab97cc8 100644
--- a/booklore-ui/src/app/dashboard/components/main-dashboard/main-dashboard.component.html
+++ b/booklore-ui/src/app/dashboard/components/main-dashboard/main-dashboard.component.html
@@ -3,7 +3,7 @@
-
+
!!settings))
.subscribe(user => {
if (user?.userSettings.sidebarLibrarySorting) {
diff --git a/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.ts b/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.ts
index 285ff733b..72b340842 100644
--- a/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.ts
+++ b/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.ts
@@ -55,7 +55,7 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
menuResetSubscription: Subscription;
constructor(public router: Router, private menuService: MenuService, private userService: UserService) {
- this.userService.userData$.subscribe(userData => {
+ this.userService.userState$.subscribe(userData => {
if (userData) {
this.canManipulateLibrary = userData.permissions.canManipulateLibrary;
this.admin = userData.permissions.admin;
diff --git a/booklore-ui/src/app/layout/component/layout-topbar/app.topbar.component.html b/booklore-ui/src/app/layout/component/layout-topbar/app.topbar.component.html
index 19c687df6..693f103a4 100644
--- a/booklore-ui/src/app/layout/component/layout-topbar/app.topbar.component.html
+++ b/booklore-ui/src/app/layout/component/layout-topbar/app.topbar.component.html
@@ -21,13 +21,13 @@
-
-
+
-
-
-
+
-
diff --git a/booklore-ui/src/app/settings/global-preferences/user-profile-dialog/user-profile-dialog.component.ts b/booklore-ui/src/app/settings/global-preferences/user-profile-dialog/user-profile-dialog.component.ts
index d37e02a38..0a03fa2ed 100644
--- a/booklore-ui/src/app/settings/global-preferences/user-profile-dialog/user-profile-dialog.component.ts
+++ b/booklore-ui/src/app/settings/global-preferences/user-profile-dialog/user-profile-dialog.component.ts
@@ -52,7 +52,7 @@ export class UserProfileDialogComponent implements OnInit, OnDestroy {
}
ngOnInit(): void {
- this.userSubscription = this.userService.userData$.subscribe(user => {
+ this.userSubscription = this.userService.userState$.subscribe(user => {
this.currentUser = user;
this.resetEditForm();
});
diff --git a/booklore-ui/src/app/settings/reader-preferences/reader-preferences.component.ts b/booklore-ui/src/app/settings/reader-preferences/reader-preferences.component.ts
index 3aefa33bf..4677b8bc3 100644
--- a/booklore-ui/src/app/settings/reader-preferences/reader-preferences.component.ts
+++ b/booklore-ui/src/app/settings/reader-preferences/reader-preferences.component.ts
@@ -84,7 +84,7 @@ export class ReaderPreferences implements OnInit, OnDestroy {
private readonly userService = inject(UserService);
private readonly messageService = inject(MessageService);
- userData$: Observable = this.userService.userData$;
+ userData$: Observable = this.userService.userState$;
private subscription?: Subscription;
private currentUser: User | null = null;
diff --git a/booklore-ui/src/app/settings/settings.component.html b/booklore-ui/src/app/settings/settings.component.html
index 67ab6189a..09dfcd893 100644
--- a/booklore-ui/src/app/settings/settings.component.html
+++ b/booklore-ui/src/app/settings/settings.component.html
@@ -1,4 +1,4 @@
-
+
diff --git a/booklore-ui/src/app/settings/user-management/user-management.component.ts b/booklore-ui/src/app/settings/user-management/user-management.component.ts
index 0f6e408f7..2be170e9b 100644
--- a/booklore-ui/src/app/settings/user-management/user-management.component.ts
+++ b/booklore-ui/src/app/settings/user-management/user-management.component.ts
@@ -13,6 +13,7 @@ import {Library} from '../../book/model/library.model';
import {LibraryService} from '../../book/service/library.service';
import {Dialog} from 'primeng/dialog';
import {Password} from 'primeng/password';
+import {filter, take} from 'rxjs/operators';
@Component({
selector: 'app-user-management',
@@ -52,35 +53,16 @@ export class UserManagementComponent implements OnInit {
ngOnInit() {
this.loadUsers();
- this.loadMyself();
- this.libraryService.getAllLibrariesFromAPI().subscribe({
- next: (libraries) => {
- this.allLibraries = libraries;
- },
- error: () => {
- this.messageService.add({
- severity: 'error',
- summary: 'Error',
- detail: 'Failed to load libraries',
- });
- },
- });
+
+ this.userService.userState$
+ .pipe(filter(user => !!user), take(1))
+ .subscribe(user => this.currentUser = user);
+
+ this.libraryService.libraryState$
+ .pipe(filter(state => !!state?.loaded), take(1))
+ .subscribe(libraries => this.allLibraries = libraries.libraries ?? []);
}
- loadMyself() {
- this.userService.getMyself().subscribe({
- next: (user) => {
- this.currentUser = user;
- },
- error: () => {
- this.messageService.add({
- severity: 'error',
- summary: 'Error',
- detail: 'Failed to fetch current user',
- });
- }
- })
- }
loadUsers() {
this.userService.getUsers().subscribe({
diff --git a/booklore-ui/src/app/settings/user-management/user.service.ts b/booklore-ui/src/app/settings/user-management/user.service.ts
index 2e3f509a5..a61ecec76 100644
--- a/booklore-ui/src/app/settings/user-management/user.service.ts
+++ b/booklore-ui/src/app/settings/user-management/user.service.ts
@@ -100,12 +100,12 @@ export class UserService {
private rxStompService?: RxStompService;
- private userDataSubject = new BehaviorSubject(null);
- userData$ = this.userDataSubject.asObservable();
+ private userStateSubject = new BehaviorSubject(null);
+ userState$ = this.userStateSubject.asObservable();
constructor() {
this.getMyself().subscribe(user => {
- this.userDataSubject.next(user);
+ this.userStateSubject.next(user);
this.startWebSocket();
});
}
@@ -165,11 +165,11 @@ export class UserService {
headers: {'Content-Type': 'application/json'},
responseType: 'text' as 'json'
}).subscribe(() => {
- const currentUser = this.userDataSubject.getValue();
+ const currentUser = this.userStateSubject.getValue();
if (currentUser) {
const updatedSettings = {...currentUser.userSettings, [key]: value};
const updatedUser = {...currentUser, settings: updatedSettings};
- this.userDataSubject.next(updatedUser);
+ this.userStateSubject.next(updatedUser);
}
});
}
diff --git a/booklore-ui/src/app/settings/view-preferences-parent/sidebar-sorting-preferences/sidebar-sorting-preferences.component.ts b/booklore-ui/src/app/settings/view-preferences-parent/sidebar-sorting-preferences/sidebar-sorting-preferences.component.ts
index bb8364f12..0e824a157 100644
--- a/booklore-ui/src/app/settings/view-preferences-parent/sidebar-sorting-preferences/sidebar-sorting-preferences.component.ts
+++ b/booklore-ui/src/app/settings/view-preferences-parent/sidebar-sorting-preferences/sidebar-sorting-preferences.component.ts
@@ -31,7 +31,7 @@ export class SidebarSortingPreferencesComponent implements OnInit, OnDestroy {
private readonly userService = inject(UserService);
private readonly messageService = inject(MessageService);
- userData$: Observable = this.userService.userData$;
+ userData$: Observable = this.userService.userState$;
private subscription?: Subscription;
private currentUser: User | null = null;
diff --git a/booklore-ui/src/app/settings/view-preferences-parent/view-preferences/view-preferences.component.ts b/booklore-ui/src/app/settings/view-preferences-parent/view-preferences/view-preferences.component.ts
index 2a41279ce..f4c46b1a3 100644
--- a/booklore-ui/src/app/settings/view-preferences-parent/view-preferences/view-preferences.component.ts
+++ b/booklore-ui/src/app/settings/view-preferences-parent/view-preferences/view-preferences.component.ts
@@ -11,6 +11,7 @@ import {ShelfService} from '../../../book/service/shelf.service';
import {combineLatest} from 'rxjs';
import {FormsModule} from '@angular/forms';
import {ToastModule} from 'primeng/toast';
+import {filter, take} from 'rxjs/operators';
@Component({
selector: 'app-view-preferences',
@@ -84,13 +85,13 @@ export class ViewPreferencesComponent implements OnInit {
ngOnInit(): void {
combineLatest([
- this.userService.getMyself(),
- this.libraryService.getAllLibrariesFromAPI(),
- this.shelfService.shelfState$
- ]).subscribe(([user, libraries, shelfState]) => {
- this.user = user;
+ this.userService.userState$.pipe(filter(user => !!user), take(1)),
+ this.libraryService.libraryState$.pipe(filter(libraryState => !!libraryState?.libraries && libraryState.loaded), take(1)),
+ this.shelfService.shelfState$.pipe(filter(shelfState => !!shelfState?.shelves && shelfState.loaded), take(1)),
+ ]).subscribe(([userState, librariesState, shelfState]) => {
- const prefs = user.userSettings?.entityViewPreferences;
+ this.user = userState;
+ const prefs = userState?.userSettings?.entityViewPreferences;
const global = prefs?.global;
this.selectedSort = global?.sortKey ?? 'title';
this.selectedSortDir = global?.sortDir ?? 'ASC';
@@ -104,7 +105,7 @@ export class ViewPreferencesComponent implements OnInit {
view: o.preferences.view ?? 'GRID'
}));
- this.libraryOptions = (libraries ?? []).filter(lib => lib.id !== undefined).map(lib => ({
+ this.libraryOptions = (librariesState.libraries ?? []).filter(lib => lib.id !== undefined).map(lib => ({
label: lib.name,
value: lib.id!
}));
@@ -170,6 +171,6 @@ export class ViewPreferencesComponent implements OnInit {
};
this.userService.updateUserSetting(this.user.id, 'entityViewPreferences', payload);
- this.messageService.add({ severity: 'success', summary: 'Preferences Saved', detail: 'Your sorting and view preferences were saved successfully.' });
+ this.messageService.add({severity: 'success', summary: 'Preferences Saved', detail: 'Your sorting and view preferences were saved successfully.'});
}
}
From 9ec66bb296cc92a999b8dc22ca63806ddd39f965 Mon Sep 17 00:00:00 2001
From: "aditya.chandel" <>
Date: Tue, 27 May 2025 23:12:32 -0600
Subject: [PATCH 4/5] Support uploading comic book archives (CBZ, CBR, CB7)
---
.../booklore/service/FileUploadService.java | 46 ++++++++-----------
1 file changed, 20 insertions(+), 26 deletions(-)
diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/FileUploadService.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/FileUploadService.java
index 9dba212c8..9234a1e8b 100644
--- a/booklore-api/src/main/java/com/adityachandel/booklore/service/FileUploadService.java
+++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/FileUploadService.java
@@ -25,6 +25,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
import java.util.Optional;
+import java.util.Set;
@RequiredArgsConstructor
@Service
@@ -36,6 +37,11 @@ public class FileUploadService {
private static final String CBZ_MIME_TYPE = "application/x-cbz";
private static final String CBR_MIME_TYPE = "application/x-cbr";
private static final String CB7_MIME_TYPE = "application/x-cb7";
+ private static final Set SUPPORTED_MIME_TYPES = Set.of(
+ PDF_MIME_TYPE, EPUB_MIME_TYPE,
+ CBZ_MIME_TYPE, CBR_MIME_TYPE, CB7_MIME_TYPE,
+ "application/octet-stream"
+ );
private final LibraryRepository libraryRepository;
private final PdfProcessor pdfProcessor;
@@ -47,8 +53,7 @@ public class FileUploadService {
private final EpubMetadataExtractor epubMetadataExtractor;
public Book uploadFile(MultipartFile file, long libraryId, long pathId) throws IOException {
- Integer uploadSizeInMb = appSettingService.getAppSettings().getMaxFileUploadSizeInMb();
- validateFile(file, uploadSizeInMb);
+ validateFile(file);
LibraryEntity libraryEntity = libraryRepository.findById(libraryId)
.orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId));
@@ -60,12 +65,10 @@ public class FileUploadService {
.orElseThrow(() -> ApiError.INVALID_LIBRARY_PATH.createException(libraryId));
Path tempPath = Files.createTempFile("upload-", Objects.requireNonNull(file.getOriginalFilename()));
- UploadedFileMetadata metadata;
-
try {
file.transferTo(tempPath);
- metadata = extractMetadata(file, tempPath);
+ UploadedFileMetadata metadata = extractMetadata(file.getContentType(), tempPath);
String title = Optional.ofNullable(metadata.getTitle()).orElse("").trim();
String authors = metadata.getAuthors() != null ? String.join(", ", metadata.getAuthors()) : "";
@@ -97,35 +100,26 @@ public class FileUploadService {
}
}
- private UploadedFileMetadata extractMetadata(MultipartFile file, Path tempPath) throws IOException {
- String fileType = Objects.requireNonNull(file.getContentType());
- return switch (fileType.toLowerCase()) {
+ private UploadedFileMetadata extractMetadata(String contentType, Path tempPath) throws IOException {
+ if (contentType == null) {
+ throw ApiError.INVALID_FILE_FORMAT.createException("Content type is null.");
+ }
+ return switch (contentType.toLowerCase()) {
case PDF_MIME_TYPE -> pdfMetadataExtractor.extractMetadata(tempPath.toString());
case EPUB_MIME_TYPE -> epubMetadataExtractor.extractMetadata(tempPath.toString());
- case CBZ_MIME_TYPE, CBR_MIME_TYPE, CB7_MIME_TYPE -> new UploadedFileMetadata();
+ case CBZ_MIME_TYPE, CBR_MIME_TYPE, CB7_MIME_TYPE, "application/octet-stream" -> new UploadedFileMetadata();
default -> throw ApiError.INVALID_FILE_FORMAT.createException("Unsupported file type.");
};
}
- private boolean isSupportedContentType(String fileType) {
- return PDF_MIME_TYPE.equals(fileType)
- || EPUB_MIME_TYPE.equals(fileType)
- || CBZ_MIME_TYPE.equals(fileType)
- || CBR_MIME_TYPE.equals(fileType)
- || CB7_MIME_TYPE.equals(fileType);
- }
-
- private boolean isFileTooLarge(MultipartFile file, int uploadSizeInMb) {
- return file.getSize() > uploadSizeInMb * 1024L * 1024L;
- }
-
- private void validateFile(MultipartFile file, int uploadSizeInMb) {
+ private void validateFile(MultipartFile file) {
String fileType = file.getContentType();
- if (!isSupportedContentType(fileType)) {
+ if (!SUPPORTED_MIME_TYPES.contains(fileType)) {
throw ApiError.INVALID_FILE_FORMAT.createException();
}
- if (isFileTooLarge(file, uploadSizeInMb)) {
- throw ApiError.FILE_TOO_LARGE.createException(uploadSizeInMb);
+ int maxSizeMb = appSettingService.getAppSettings().getMaxFileUploadSizeInMb();
+ if (file.getSize() > maxSizeMb * 1024L * 1024L) {
+ throw ApiError.FILE_TOO_LARGE.createException(maxSizeMb);
}
}
@@ -180,7 +174,7 @@ public class FileUploadService {
return switch (fileType.toLowerCase()) {
case PDF_MIME_TYPE -> BookFileType.PDF;
case EPUB_MIME_TYPE -> BookFileType.EPUB;
- case CBZ_MIME_TYPE, CBR_MIME_TYPE, CB7_MIME_TYPE -> BookFileType.CBX;
+ case CBZ_MIME_TYPE, CBR_MIME_TYPE, CB7_MIME_TYPE, "application/octet-stream" -> BookFileType.CBX;
default -> null;
};
}
From a4d8f128431a7b261e743d800741324ced4c3548 Mon Sep 17 00:00:00 2001
From: "aditya.chandel" <>
Date: Wed, 28 May 2025 07:10:58 -0600
Subject: [PATCH 5/5] Fix LazyInitializationException error
---
.../adityachandel/booklore/model/entity/LibraryPathEntity.java | 3 ---
1 file changed, 3 deletions(-)
diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/model/entity/LibraryPathEntity.java b/booklore-api/src/main/java/com/adityachandel/booklore/model/entity/LibraryPathEntity.java
index 17e4618f2..0cedf7e27 100644
--- a/booklore-api/src/main/java/com/adityachandel/booklore/model/entity/LibraryPathEntity.java
+++ b/booklore-api/src/main/java/com/adityachandel/booklore/model/entity/LibraryPathEntity.java
@@ -22,9 +22,6 @@ public class LibraryPathEntity {
@JoinColumn(name = "library_id", nullable = false)
private LibraryEntity library;
- @OneToMany(mappedBy = "libraryPath", fetch = FetchType.LAZY)
- private List books;
-
@Column(nullable = false)
private String path;
}