diff --git a/booklore-ui/package-lock.json b/booklore-ui/package-lock.json index 09ac82d7d..af5ec58c1 100644 --- a/booklore-ui/package-lock.json +++ b/booklore-ui/package-lock.json @@ -23,6 +23,7 @@ "@primeuix/themes": "^2.0.3", "@stomp/rx-stomp": "^2.3.0", "@stomp/stompjs": "^7.3.0", + "@tanstack/angular-query-experimental": "5.90.26", "@tweenjs/tween.js": "^25.0.0", "chart.js": "^4.5.1", "chartjs-chart-matrix": "^3.0.0", @@ -298,6 +299,7 @@ "integrity": "sha512-3zbx2Pu/PyP0cw5EMgpdVMerYwYOtZvV1pFXxoViGZAxFzQ8TGHCuJm4ECg3jcs7iBdt1O9ZejMuwebVCXeD3A==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "tinyglobby": "^0.2.14", "ts-morph": "^21.0.0" @@ -348,6 +350,7 @@ "integrity": "sha512-kYFwTNzToG2SJMxj2f41w3QRtdqlrFuF+bpZrtIaHOP078Ktld8EPIp9KqB0Y46Vvs69ifby5Q1/wPD9wA3iaw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@angular-devkit/core": "21.2.0", "rxjs": "7.8.2" @@ -395,6 +398,7 @@ "integrity": "sha512-3kn3FI5v7BQ7Zct6raek+WgvyDwOJ8wElbyC903GxMQCDBRGGcevhHvTAIHhknihEsrgplzPhTlWeMbk1JfdFg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@angular-devkit/core": "21.2.0", "jsonc-parser": "3.3.1", @@ -492,6 +496,7 @@ "integrity": "sha512-TCb3qYOC/uXKZCo56cJ6N9sHeWdFhyVqrbbYfFjTi09081T6jllgHDZL5Ms7gOMNY8KywWGGbhxwvzeA0RwTgA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@angular-eslint/bundled-angular-compiler": "21.2.0", "eslint-scope": "^9.0.0" @@ -506,6 +511,7 @@ "resolved": "https://registry.npmjs.org/@angular/animations/-/animations-21.2.4.tgz", "integrity": "sha512-hO1P7ks9n7lW3D31bzHohSuoAaj05xJUlK8rZgX8IkH5DLx4qhvfNh0t4bbLuBJLP2r1TaLsQ8KFcemCkFRO2w==", "license": "MIT", + "peer": true, "dependencies": { "tslib": "^2.3.0" }, @@ -522,6 +528,7 @@ "integrity": "sha512-K0EqiHz2y7TSyD4adWD0+C/P9khKlrsSWavXWxGRvoSJC/H3I3SK5Z6BWwftBibXR1Fis7njwvl5IGAlQrDchA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@ampproject/remapping": "2.3.0", "@angular-devkit/architect": "0.2102.0", @@ -634,6 +641,7 @@ "resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-21.2.0.tgz", "integrity": "sha512-1P0TNL1F51NC7JAaXabaAHY7Y1zBloLSZXfml1POa4a116V+y/QZfPGsxM0LwD1qSSXhSb2LNl7duTtJAP39bA==", "license": "MIT", + "peer": true, "dependencies": { "parse5": "^8.0.0", "tslib": "^2.3.0" @@ -651,6 +659,7 @@ "integrity": "sha512-yaGEpckqgOemcHkoWeH92i9eNrcbr9iE/dnxL+Du6s9spTAXJ2jjtYfszhmowuQZkCK5rjecMb8ctNtHlaGCjg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@angular-devkit/architect": "0.2102.0", "@angular-devkit/core": "21.2.0", @@ -698,6 +707,7 @@ "resolved": "https://registry.npmjs.org/@angular/common/-/common-21.2.4.tgz", "integrity": "sha512-NrP6qOuUpo3fqq14UJ1b2bIRtWsfvxh1qLqOyFV4gfBrHhXd0XffU1LUlUw1qp4w1uBSgPJ0/N5bSPUWrAguVg==", "license": "MIT", + "peer": true, "dependencies": { "tslib": "^2.3.0" }, @@ -714,6 +724,7 @@ "resolved": "https://registry.npmjs.org/@angular/compiler/-/compiler-21.2.4.tgz", "integrity": "sha512-9+ulVK3idIo/Tu4X2ic7/V0+Uj7pqrOAbOuIirYe6Ymm3AjexuFRiGBbfcH0VJhQ5cf8TvIJ1fuh+MI4JiRIxA==", "license": "MIT", + "peer": true, "dependencies": { "tslib": "^2.3.0" }, @@ -727,6 +738,7 @@ "integrity": "sha512-vGjd7DZo/Ox50pQCm5EycmBu91JclimPtZoyNXu/2hSxz3oAkzwiHCwlHwk2g58eheSSp+lYtYRLmHAqSVZLjg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@babel/core": "7.29.0", "@jridgewell/sourcemap-codec": "^1.4.14", @@ -759,6 +771,7 @@ "resolved": "https://registry.npmjs.org/@angular/core/-/core-21.2.4.tgz", "integrity": "sha512-2+gd67ZuXHpGOqeb2o7XZPueEWEP81eJza2tSHkT5QMV8lnYllDEmaNnkPxnIjSLGP1O3PmiXxo4z8ibHkLZwg==", "license": "MIT", + "peer": true, "dependencies": { "tslib": "^2.3.0" }, @@ -784,6 +797,7 @@ "resolved": "https://registry.npmjs.org/@angular/forms/-/forms-21.2.4.tgz", "integrity": "sha512-1fOhctA9ADEBYjI3nPQUR5dHsK2+UWAjup37Ksldk/k0w8UpD5YsN7JVNvsDMZRFMucKYcGykPblU7pABtsqnQ==", "license": "MIT", + "peer": true, "dependencies": { "@standard-schema/spec": "^1.0.0", "tslib": "^2.3.0" @@ -803,6 +817,7 @@ "resolved": "https://registry.npmjs.org/@angular/platform-browser/-/platform-browser-21.2.4.tgz", "integrity": "sha512-1A9e/cQVu+3BkRCktLcO3RZGuw8NOTHw1frUUrpAz+iMyvIT4sDRFbL+U1g8qmOCZqRNC1Pi1HZfZ1kl6kvrcQ==", "license": "MIT", + "peer": true, "dependencies": { "tslib": "^2.3.0" }, @@ -843,6 +858,7 @@ "resolved": "https://registry.npmjs.org/@angular/router/-/router-21.2.4.tgz", "integrity": "sha512-OjWze4XT8i2MThcBXMv7ru1k6/5L6QYZbcXuseqimFCHm2avEJ+mXPovY066fMBZJhqbXdjB82OhHAWkIHjglQ==", "license": "MIT", + "peer": true, "dependencies": { "tslib": "^2.3.0" }, @@ -861,6 +877,7 @@ "resolved": "https://registry.npmjs.org/@angular/service-worker/-/service-worker-21.2.4.tgz", "integrity": "sha512-YcPMb0co2hEDwzOG5S27b6f8rotXEUDx88nQuhHDl/ztuzXaxKklJ21qVDVZ0R433YBCRQJl2D6ZrpJojsnBFw==", "license": "MIT", + "peer": true, "dependencies": { "tslib": "^2.3.0" }, @@ -960,6 +977,7 @@ "integrity": "sha512-CGOfOJqWjg2qW/Mb6zNsDm+u5vFQ8DxXfbM09z69p5Z6+mE1ikP2jUXw+j42Pf1XTYED2Rni5f95npYeuwMDQA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@babel/code-frame": "^7.29.0", "@babel/generator": "^7.29.0", @@ -1332,6 +1350,7 @@ } ], "license": "MIT", + "peer": true, "engines": { "node": ">=20.19.0" }, @@ -1372,6 +1391,7 @@ } ], "license": "MIT", + "peer": true, "engines": { "node": ">=20.19.0" } @@ -2369,6 +2389,7 @@ "integrity": "sha512-Dx/y9bCQcXLI5ooQ5KyvA4FTgeo2jYj/7plWfV5Ak5wDPKQZgudKez2ixyfz7tKXzcJciTxqLeK7R9HItwiByg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@inquirer/checkbox": "^4.3.2", "@inquirer/confirm": "^5.1.21", @@ -4497,7 +4518,49 @@ "version": "7.3.0", "resolved": "https://registry.npmjs.org/@stomp/stompjs/-/stompjs-7.3.0.tgz", "integrity": "sha512-nKMLoFfJhrQAqkvvKd1vLq/cVBGCMwPRCD0LqW7UT1fecRx9C3GoKEIR2CYwVuErGeZu8w0kFkl2rlhPlqHVgQ==", - "license": "Apache-2.0" + "license": "Apache-2.0", + "peer": true + }, + "node_modules/@tanstack/angular-query-experimental": { + "version": "5.90.26", + "resolved": "https://registry.npmjs.org/@tanstack/angular-query-experimental/-/angular-query-experimental-5.90.26.tgz", + "integrity": "sha512-VsQhC82xNZjEpnAIdDTWy3hbkHVgTLobMOMFii2vtiJV2rx+a61q06OMxAns3JNU+8yw1YGDnD2Vna5PHA9+yg==", + "license": "MIT", + "dependencies": { + "@tanstack/query-core": "5.91.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + }, + "optionalDependencies": { + "@tanstack/query-devtools": "5.93.0" + }, + "peerDependencies": { + "@angular/common": ">=16.0.0", + "@angular/core": ">=16.0.0" + } + }, + "node_modules/@tanstack/query-core": { + "version": "5.91.0", + "resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.91.0.tgz", + "integrity": "sha512-FYXN8Kk9Q5VKuV6AIVaNwMThSi0nvAtR4X7HQoigf6ePOtFcavJYVIzgFhOVdtbBQtCJE3KimDIMMJM2DR1hjw==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + } + }, + "node_modules/@tanstack/query-devtools": { + "version": "5.93.0", + "resolved": "https://registry.npmjs.org/@tanstack/query-devtools/-/query-devtools-5.93.0.tgz", + "integrity": "sha512-+kpsx1NQnOFTZsw6HAFCW3HkKg0+2cepGtAWXjiiSOJJ1CtQpt72EE2nyZb+AjAbLRPoeRmPJ8MtQd8r8gsPdg==", + "license": "MIT", + "optional": true, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + } }, "node_modules/@ts-morph/common": { "version": "0.22.0", @@ -4540,7 +4603,8 @@ "version": "25.0.0", "resolved": "https://registry.npmjs.org/@tweenjs/tween.js/-/tween.js-25.0.0.tgz", "integrity": "sha512-XKLA6syeBUaPzx4j3qwMqzzq+V4uo72BnlbOjmuljLrRqdsd3qnzvZZoxvMHZ23ndsRS4aufU6JOZYpCbU6T1A==", - "license": "MIT" + "license": "MIT", + "peer": true }, "node_modules/@tybys/wasm-util": { "version": "0.10.1", @@ -4609,6 +4673,7 @@ "integrity": "sha512-RpV6r/ij22zRRdyBPcxDeKAzH43phWVKEjL2iksqo1Vz3CuBUrgmPpPhALKiRfU7OMCmeeO9vECBMsV0hMTG8Q==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "undici-types": "~7.18.0" } @@ -4662,6 +4727,7 @@ "integrity": "sha512-klQbnPAAiGYFyI02+znpBRLyjL4/BrBd0nyWkdC0s/6xFLkXYQ8OoRrSkqacS1ddVxf/LDyODIKbQ5TgKAf/Fg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "8.56.1", "@typescript-eslint/types": "8.56.1", @@ -4769,6 +4835,7 @@ "integrity": "sha512-dbMkdIUkIkchgGDIv7KLUpa0Mda4IYjo4IAMJUZ+3xNoUXxMsk9YtKpTHSChRS85o+H9ftm51gsK1dZReY9CVw==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, @@ -4811,6 +4878,7 @@ "integrity": "sha512-HPAVNIME3tABJ61siYlHzSWCGtOoeP2RTIaHXFMPqjrQKCGB9OgUVdiNgH7TJS2JNIQ5qQ4RsAUDuGaGme/KOA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.9.1", "@typescript-eslint/scope-manager": "8.56.1", @@ -5052,6 +5120,7 @@ "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==", "dev": true, "license": "MIT", + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -5473,6 +5542,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "baseline-browser-mapping": "^2.9.0", "caniuse-lite": "^1.0.30001759", @@ -5633,6 +5703,7 @@ "resolved": "https://registry.npmjs.org/chart.js/-/chart.js-4.5.1.tgz", "integrity": "sha512-GIjfiT9dbmHRiYi6Nl2yFCq7kkwdkp1W/lp2J99rX0yo9tgJGn3lKQATztIjb5tVtevcBtIdICNWqlq5+E8/Pw==", "license": "MIT", + "peer": true, "dependencies": { "@kurkle/color": "^0.3.0" }, @@ -6378,6 +6449,7 @@ "integrity": "sha512-VmQ+sifHUbI/IcSopBCF/HO3YiHQx/AVd3UVyYL6weuwW+HvON9VYn5l6Zl1WZzPWXPNZrSQpxwkkZ/VuvJZzg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", @@ -6711,6 +6783,7 @@ "integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "accepts": "^2.0.0", "body-parser": "^2.2.1", @@ -7193,6 +7266,7 @@ "integrity": "sha512-jq9l1DM0zVIvsm3lv9Nw9nlJnMNPOcAtsbsgiUhWcFzPE99Gvo6yRTlszSLLYacMeQ6quHD6hMfId8crVHvexw==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=16.9.0" } @@ -7631,6 +7705,7 @@ "integrity": "sha512-0+MoQNYyr2rBHqO1xilltfDjV9G7ymYGlAUazgcDLQaUf8JDHbuGwsxN6U9qWaElZ4w1B2r7yEGIL3GdeW3Rug==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@acemir/cssom": "^0.9.31", "@asamuzakjp/dom-selector": "^6.8.1", @@ -7792,6 +7867,7 @@ "integrity": "sha512-ME4Fb83LgEgwNw96RKNvKV4VTLuXfoKudAmm2lP8Kk87KaMK0/Xrx/aAkMWmT8mDb+3MlFDspfbCs7adjRxA2g==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "cli-truncate": "^5.0.0", "colorette": "^2.0.20", @@ -9158,6 +9234,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "nanoid": "^3.3.11", "picocolors": "^1.1.1", @@ -9568,6 +9645,7 @@ "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.2.tgz", "integrity": "sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA==", "license": "Apache-2.0", + "peer": true, "dependencies": { "tslib": "^2.1.0" } @@ -10271,7 +10349,8 @@ "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", - "license": "0BSD" + "license": "0BSD", + "peer": true }, "node_modules/tuf-js": { "version": "4.1.0", @@ -10322,6 +10401,7 @@ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "devOptional": true, "license": "Apache-2.0", + "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -10336,6 +10416,7 @@ "integrity": "sha512-U4lM6pjmBX7J5wk4szltF7I1cGBHXZopnAXCMXb3+fZ3B/0Z3hq3wS/CCUB2NZBNAExK92mCU2tEohWuwVMsDQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@typescript-eslint/eslint-plugin": "8.56.1", "@typescript-eslint/parser": "8.56.1", @@ -10457,6 +10538,7 @@ "https://github.com/sponsors/ctavan" ], "license": "MIT", + "peer": true, "bin": { "uuid": "dist/esm/bin/uuid" } @@ -10487,6 +10569,7 @@ "integrity": "sha512-w+N7Hifpc3gRjZ63vYBXA56dvvRlNWRczTdmCBBa+CotUzAPf5b7YMdMR/8CQoeYE5LX3W4wj6RYTgonm1b9DA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "esbuild": "^0.27.0", "fdir": "^6.5.0", @@ -10562,6 +10645,7 @@ "integrity": "sha512-hOQuK7h0FGKgBAas7v0mSAsnvrIgAvWmRFjmzpJ7SwFHH3g1k2u37JtYwOwmEKhK6ZO3v9ggDBBm0La1LCK4uQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@vitest/expect": "4.0.18", "@vitest/mocker": "4.0.18", @@ -10986,6 +11070,7 @@ "integrity": "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg==", "dev": true, "license": "MIT", + "peer": true, "funding": { "url": "https://github.com/sponsors/colinhacks" } @@ -11004,7 +11089,8 @@ "version": "0.16.1", "resolved": "https://registry.npmjs.org/zone.js/-/zone.js-0.16.1.tgz", "integrity": "sha512-dpvY17vxYIW3+bNrP0ClUlaiY0CiIRK3tnoLaGoQsQcY9/I/NpzIWQ7tQNhbV7LacQMpCII6wVzuL3tuWOyfuA==", - "license": "MIT" + "license": "MIT", + "peer": true } } } diff --git a/booklore-ui/package.json b/booklore-ui/package.json index dedd33f35..a3f4c3c08 100644 --- a/booklore-ui/package.json +++ b/booklore-ui/package.json @@ -27,6 +27,7 @@ "@primeuix/themes": "^2.0.3", "@stomp/rx-stomp": "^2.3.0", "@stomp/stompjs": "^7.3.0", + "@tanstack/angular-query-experimental": "5.90.26", "@tweenjs/tween.js": "^25.0.0", "chart.js": "^4.5.1", "chartjs-chart-matrix": "^3.0.0", diff --git a/booklore-ui/src/app/app.component.spec.ts b/booklore-ui/src/app/app.component.spec.ts index bb4e26344..c9482fcad 100644 --- a/booklore-ui/src/app/app.component.spec.ts +++ b/booklore-ui/src/app/app.component.spec.ts @@ -1,8 +1,9 @@ import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest'; import {ComponentFixture, TestBed} from '@angular/core/testing'; +import {signal} from '@angular/core'; import {AppComponent} from './app.component'; import {AuthInitializationService} from './core/security/auth-initialization-service'; -import {BehaviorSubject, of} from 'rxjs'; +import {of} from 'rxjs'; import {RxStompService} from './shared/websocket/rx-stomp.service'; import {BookService} from './features/book/service/book.service'; import {NotificationEventService} from './shared/websocket/notification-event.service'; @@ -18,15 +19,12 @@ import {TranslocoTestingModule} from '@jsverse/transloco'; describe('AppComponent offline detection', () => { let fixture: ComponentFixture; let component: AppComponent; - let authInitSubject: BehaviorSubject; beforeEach(() => { - authInitSubject = new BehaviorSubject(false); - TestBed.configureTestingModule({ imports: [TranslocoTestingModule.forRoot({langs: {}})], providers: [ - {provide: AuthInitializationService, useValue: {initialized$: authInitSubject.asObservable()}}, + {provide: AuthInitializationService, useValue: {initialized: signal(false)}}, {provide: RxStompService, useValue: {watch: vi.fn(() => of())}}, {provide: BookService, useValue: {}}, {provide: NotificationEventService, useValue: {}}, @@ -34,7 +32,7 @@ describe('AppComponent offline detection', () => { {provide: MetadataProgressService, useValue: {}}, {provide: BookdropFileService, useValue: {}}, {provide: TaskService, useValue: {}}, - {provide: LibraryService, useValue: {largeLibraryLoading$: of({isLoading: false, expectedCount: 0})}}, + {provide: LibraryService, useValue: {largeLibraryLoading: signal({isLoading: false, expectedCount: 0})}}, {provide: LibraryHealthService, useValue: {initialize: vi.fn()}}, {provide: LibraryLoadingService, useValue: {hide: vi.fn()}}, ] diff --git a/booklore-ui/src/app/app.component.ts b/booklore-ui/src/app/app.component.ts index d2b40a3c3..f5f65d9e5 100644 --- a/booklore-ui/src/app/app.component.ts +++ b/booklore-ui/src/app/app.component.ts @@ -1,4 +1,4 @@ -import {Component, inject, OnDestroy, OnInit} from '@angular/core'; +import {Component, effect, inject, OnDestroy, OnInit} from '@angular/core'; import {RxStompService} from './shared/websocket/rx-stomp.service'; import {BookService} from './features/book/service/book.service'; import {NotificationEventService} from './shared/websocket/notification-event.service'; @@ -17,7 +17,7 @@ import {TaskProgressPayload, TaskService} from './features/settings/task-managem import {LibraryService} from './features/book/service/library.service'; import {LibraryHealthService} from './features/book/service/library-health.service'; import {LibraryLoadingService} from './features/library-creator/library-loading.service'; -import {scan, withLatestFrom} from 'rxjs/operators'; +import {scan} from 'rxjs/operators'; import {AuthService} from './shared/service/auth.service'; @Component({ @@ -46,19 +46,20 @@ export class AppComponent implements OnInit, OnDestroy { private libraryHealthService = inject(LibraryHealthService); private libraryLoadingService = inject(LibraryLoadingService); private authService = inject(AuthService); + private readonly syncAuthInitializationEffect = effect(() => { + const ready = this.authInit.initialized(); + this.loading = !ready; + + if (ready && !this.subscriptionsInitialized) { + this.setupWebSocketSubscriptions(); + this.libraryHealthService.initialize(); + this.subscriptionsInitialized = true; + } + }); ngOnInit(): void { window.addEventListener('online', this.onOnline); window.addEventListener('offline', this.onOffline); - - this.authInit.initialized$.subscribe(ready => { - this.loading = !ready; - if (ready && !this.subscriptionsInitialized) { - this.setupWebSocketSubscriptions(); - this.libraryHealthService.initialize(); - this.subscriptionsInitialized = true; - } - }); } private onOnline = () => { @@ -84,8 +85,8 @@ export class AppComponent implements OnInit, OnDestroy { private setupWebSocketSubscriptions(): void { this.subscriptions.push( this.rxStompService.watch('/user/queue/book-add').pipe( - withLatestFrom(this.libraryService.largeLibraryLoading$), - scan((acc, [msg, loadingState]) => { + scan((acc, msg) => { + const loadingState = this.libraryService.largeLibraryLoading(); const book = JSON.parse(msg.body); if (loadingState.isLoading) { const newCount = acc.count + 1; diff --git a/booklore-ui/src/app/core/security/auth-initialization-service.ts b/booklore-ui/src/app/core/security/auth-initialization-service.ts index 10d175d16..398728deb 100644 --- a/booklore-ui/src/app/core/security/auth-initialization-service.ts +++ b/booklore-ui/src/app/core/security/auth-initialization-service.ts @@ -1,12 +1,11 @@ -import {Injectable} from '@angular/core'; -import {BehaviorSubject} from 'rxjs'; +import {Injectable, signal} from '@angular/core'; @Injectable({providedIn: 'root'}) export class AuthInitializationService { - private initialized = new BehaviorSubject(false); - initialized$ = this.initialized.asObservable(); + private readonly _initialized = signal(false); + readonly initialized = this._initialized.asReadonly(); - markAsInitialized() { - this.initialized.next(true); + markAsInitialized(): void { + this._initialized.set(true); } } diff --git a/booklore-ui/src/app/core/security/auth-initializer.spec.ts b/booklore-ui/src/app/core/security/auth-initializer.spec.ts index 9add5ef42..abd4a5586 100644 --- a/booklore-ui/src/app/core/security/auth-initializer.spec.ts +++ b/booklore-ui/src/app/core/security/auth-initializer.spec.ts @@ -1,22 +1,39 @@ import {beforeEach, describe, expect, it, vi} from 'vitest'; +import {signal} from '@angular/core'; import {TestBed} from '@angular/core/testing'; import {initializeAuthFactory} from './auth-initializer'; import {AuthInitializationService} from './auth-initialization-service'; import {AuthService} from '../../shared/service/auth.service'; import {AppSettingsService, PublicAppSettings} from '../../shared/service/app-settings.service'; -import {BehaviorSubject} from 'rxjs'; +import {QueryClient, queryOptions} from '@tanstack/angular-query-experimental'; describe('initializeAuthFactory', () => { let authInitService: AuthInitializationService; - let publicSettingsSubject: BehaviorSubject; + let mockQueryClient: { fetchQuery: ReturnType }; + + const defaultPublicSettings: PublicAppSettings = { + oidcEnabled: false, + remoteAuthEnabled: false, + oidcProviderDetails: null!, + oidcForceOnlyMode: false, + }; beforeEach(() => { - publicSettingsSubject = new BehaviorSubject(null); + mockQueryClient = { + fetchQuery: vi.fn().mockResolvedValue(defaultPublicSettings), + }; TestBed.configureTestingModule({ providers: [ - {provide: AuthService, useValue: {tokenSubject: {next: vi.fn()}, getInternalAccessToken: vi.fn()}}, - {provide: AppSettingsService, useValue: {publicAppSettings$: publicSettingsSubject.asObservable()}}, + {provide: AuthService, useValue: {token: signal(null), getInternalAccessToken: vi.fn()}}, + { + provide: AppSettingsService, + useValue: { + publicAppSettings: signal(null), + getPublicSettingsQueryOptions: () => queryOptions({queryKey: ['public-settings'], queryFn: async () => defaultPublicSettings}), + }, + }, + {provide: QueryClient, useValue: mockQueryClient}, AuthInitializationService, ] }); @@ -32,8 +49,6 @@ describe('initializeAuthFactory', () => { const factory = TestBed.runInInjectionContext(() => initializeAuthFactory()); const initPromise = TestBed.runInInjectionContext(() => factory()); - publicSettingsSubject.next({oidcEnabled: false, remoteAuthEnabled: false, oidcProviderDetails: null!, oidcForceOnlyMode: false}); - await initPromise; expect(markSpy).toHaveBeenCalled(); @@ -49,8 +64,6 @@ describe('initializeAuthFactory', () => { const factory = TestBed.runInInjectionContext(() => initializeAuthFactory()); const initPromise = TestBed.runInInjectionContext(() => factory()); - publicSettingsSubject.next({oidcEnabled: false, remoteAuthEnabled: false, oidcProviderDetails: null!, oidcForceOnlyMode: false}); - await initPromise; expect(markSpy).toHaveBeenCalled(); diff --git a/booklore-ui/src/app/core/security/auth-initializer.ts b/booklore-ui/src/app/core/security/auth-initializer.ts index 9f9a2f65c..bba48fbba 100644 --- a/booklore-ui/src/app/core/security/auth-initializer.ts +++ b/booklore-ui/src/app/core/security/auth-initializer.ts @@ -2,6 +2,7 @@ import {inject} from '@angular/core'; import {AuthService, websocketInitializer} from '../../shared/service/auth.service'; import {AppSettingsService} from '../../shared/service/app-settings.service'; import {AuthInitializationService} from './auth-initialization-service'; +import {QueryClient} from '@tanstack/angular-query-experimental'; const SETTINGS_TIMEOUT_MS = 10000; @@ -10,42 +11,41 @@ export function initializeAuthFactory() { const appSettingsService = inject(AppSettingsService); const authService = inject(AuthService); const authInitService = inject(AuthInitializationService); + const queryClient = inject(QueryClient); - return new Promise((resolve) => { + const settingsPromise = queryClient.fetchQuery(appSettingsService.getPublicSettingsQueryOptions()); + const timeoutPromise = new Promise(resolve => + setTimeout(() => resolve(null), SETTINGS_TIMEOUT_MS) + ); - const settingsTimeout = setTimeout(() => { + return Promise.race([settingsPromise, timeoutPromise]).then(publicSettings => { + if (!publicSettings) { console.warn('[Auth] Public settings fetch timed out, falling back to local auth'); - sub.unsubscribe(); authInitService.markAsInitialized(); - resolve(); - }, SETTINGS_TIMEOUT_MS); + return; + } - const sub = appSettingsService.publicAppSettings$.subscribe(publicSettings => { - if (publicSettings) { - clearTimeout(settingsTimeout); - - if (publicSettings.remoteAuthEnabled) { - authService.remoteLogin().subscribe({ - next: () => { - authInitService.markAsInitialized(); - resolve(); - }, - error: err => { - console.error('[Remote Login] failed:', err); - authInitService.markAsInitialized(); - resolve(); - } - }); - } else { - if (authService.getInternalAccessToken()) { - websocketInitializer(authService)(); + if (publicSettings.remoteAuthEnabled) { + return new Promise(resolve => { + authService.remoteLogin().subscribe({ + next: () => { + authInitService.markAsInitialized(); + resolve(); + }, + error: err => { + console.error('[Remote Login] failed:', err); + authInitService.markAsInitialized(); + resolve(); } - authInitService.markAsInitialized(); - resolve(); - } - sub.unsubscribe(); + }); + }); + } else { + if (authService.getInternalAccessToken()) { + websocketInitializer(authService)(); } - }); + authInitService.markAsInitialized(); + return; + } }); }; } diff --git a/booklore-ui/src/app/core/security/guards/bookdrop.guard.ts b/booklore-ui/src/app/core/security/guards/bookdrop.guard.ts index fd6b00db4..13c2ee428 100644 --- a/booklore-ui/src/app/core/security/guards/bookdrop.guard.ts +++ b/booklore-ui/src/app/core/security/guards/bookdrop.guard.ts @@ -1,20 +1,15 @@ import {inject} from '@angular/core'; import {CanActivateFn, Router} from '@angular/router'; import {UserService} from '../../../features/settings/user-management/user.service'; -import {map} from 'rxjs/operators'; export const BookdropGuard: CanActivateFn = () => { const userService = inject(UserService); const router = inject(Router); + const user = userService.currentUser(); - return userService.userState$.pipe( - map(state => { - const user = state.user; - if (user && (user.permissions.admin || user.permissions.canAccessBookdrop)) { - return true; - } - router.navigate(['/dashboard']); - return false; - }) - ); + if (user && (user.permissions.admin || user.permissions.canAccessBookdrop)) { + return true; + } + router.navigate(['/dashboard']); + return false; }; diff --git a/booklore-ui/src/app/core/security/guards/edit-metdata.guard.ts b/booklore-ui/src/app/core/security/guards/edit-metdata.guard.ts index 6866e942e..f81ed7c41 100644 --- a/booklore-ui/src/app/core/security/guards/edit-metdata.guard.ts +++ b/booklore-ui/src/app/core/security/guards/edit-metdata.guard.ts @@ -1,20 +1,15 @@ import {inject} from '@angular/core'; import {CanActivateFn, Router} from '@angular/router'; import {UserService} from '../../../features/settings/user-management/user.service'; -import {map} from 'rxjs/operators'; export const EditMetadataGuard: CanActivateFn = () => { const userService = inject(UserService); const router = inject(Router); + const user = userService.currentUser(); - return userService.userState$.pipe( - map(state => { - const user = state.user; - if (user && (user.permissions.admin || user.permissions.canEditMetadata)) { - return true; - } - router.navigate(['/dashboard']); - return false; - }) - ); + if (user && (user.permissions.admin || user.permissions.canEditMetadata)) { + return true; + } + router.navigate(['/dashboard']); + return false; }; diff --git a/booklore-ui/src/app/core/security/guards/library-stats.guard.ts b/booklore-ui/src/app/core/security/guards/library-stats.guard.ts index 6e8361b40..9521d4352 100644 --- a/booklore-ui/src/app/core/security/guards/library-stats.guard.ts +++ b/booklore-ui/src/app/core/security/guards/library-stats.guard.ts @@ -1,20 +1,15 @@ import {inject} from '@angular/core'; import {CanActivateFn, Router} from '@angular/router'; import {UserService} from '../../../features/settings/user-management/user.service'; -import {map} from 'rxjs/operators'; export const LibraryStatsGuard: CanActivateFn = () => { const userService = inject(UserService); const router = inject(Router); + const user = userService.currentUser(); - return userService.userState$.pipe( - map(state => { - const user = state.user; - if (user && (user.permissions.admin || user.permissions.canAccessLibraryStats)) { - return true; - } - router.navigate(['/dashboard']); - return false; - }) - ); + if (user && (user.permissions.admin || user.permissions.canAccessLibraryStats)) { + return true; + } + router.navigate(['/dashboard']); + return false; }; diff --git a/booklore-ui/src/app/core/security/guards/manage-library.guard.ts b/booklore-ui/src/app/core/security/guards/manage-library.guard.ts index ef72bd27f..659921d5c 100644 --- a/booklore-ui/src/app/core/security/guards/manage-library.guard.ts +++ b/booklore-ui/src/app/core/security/guards/manage-library.guard.ts @@ -1,20 +1,15 @@ import {inject} from '@angular/core'; import {CanActivateFn, Router} from '@angular/router'; import {UserService} from '../../../features/settings/user-management/user.service'; -import {map} from 'rxjs/operators'; export const ManageLibraryGuard: CanActivateFn = () => { const userService = inject(UserService); const router = inject(Router); + const user = userService.currentUser(); - return userService.userState$.pipe( - map(state => { - const user = state.user; - if (user && (user.permissions.admin || user.permissions.canManageLibrary)) { - return true; - } - router.navigate(['/dashboard']); - return false; - }) - ); + if (user && (user.permissions.admin || user.permissions.canManageLibrary)) { + return true; + } + router.navigate(['/dashboard']); + return false; }; diff --git a/booklore-ui/src/app/core/security/guards/user-stats.guard.ts b/booklore-ui/src/app/core/security/guards/user-stats.guard.ts index 7fc3d4dcf..165a1f549 100644 --- a/booklore-ui/src/app/core/security/guards/user-stats.guard.ts +++ b/booklore-ui/src/app/core/security/guards/user-stats.guard.ts @@ -1,20 +1,15 @@ import {inject} from '@angular/core'; import {CanActivateFn, Router} from '@angular/router'; import {UserService} from '../../../features/settings/user-management/user.service'; -import {map} from 'rxjs/operators'; export const UserStatsGuard: CanActivateFn = () => { const userService = inject(UserService); const router = inject(Router); + const user = userService.currentUser(); - return userService.userState$.pipe( - map(state => { - const user = state.user; - if (user && (user.permissions.admin || user.permissions.canAccessUserStats)) { - return true; - } - router.navigate(['/dashboard']); - return false; - }) - ); + if (user && (user.permissions.admin || user.permissions.canAccessUserStats)) { + return true; + } + router.navigate(['/dashboard']); + return false; }; diff --git a/booklore-ui/src/app/core/security/oauth2-management/authentication-settings.component.ts b/booklore-ui/src/app/core/security/oauth2-management/authentication-settings.component.ts index 49fe93832..21de35982 100644 --- a/booklore-ui/src/app/core/security/oauth2-management/authentication-settings.component.ts +++ b/booklore-ui/src/app/core/security/oauth2-management/authentication-settings.component.ts @@ -1,4 +1,4 @@ -import {Component, inject, OnInit} from '@angular/core'; +import {Component, effect, inject} from '@angular/core'; import {FormsModule, ReactiveFormsModule} from '@angular/forms'; import {InputText} from 'primeng/inputtext'; import {Button} from 'primeng/button'; @@ -8,9 +8,7 @@ import {ToggleSwitch} from 'primeng/toggleswitch'; import {InputNumber} from 'primeng/inputnumber'; import {MessageService} from 'primeng/api'; import {AppSettingsService} from '../../../shared/service/app-settings.service'; -import {Observable} from 'rxjs'; import {AppSettingKey, AppSettings, OidcProviderDetails, OidcTestResult} from '../../../shared/model/app-settings.model'; -import {filter, take} from 'rxjs/operators'; import {MultiSelect} from 'primeng/multiselect'; import {Library} from '../../../features/book/model/library.model'; import {LibraryService} from '../../../features/book/service/library.service'; @@ -46,7 +44,7 @@ import {TagComponent} from '../../../shared/components/tag/tag.component'; ], styleUrls: ['./authentication-settings.component.scss'] }) -export class AuthenticationSettingsComponent implements OnInit { +export class AuthenticationSettingsComponent { availablePermissions = [ {label: 'Upload Books', value: 'permissionUpload', selected: false, translationKey: 'perms.uploadBooks'}, {label: 'Download Books', value: 'permissionDownload', selected: false, translationKey: 'perms.downloadBooks'}, @@ -64,7 +62,7 @@ export class AuthenticationSettingsComponent implements OnInit { allowLocalAccountLinking = true; selectedPermissions: string[] = []; oidcEnabled = false; - allLibraries: Library[] = []; + editingLibraryIds: number[] = []; sessionDurationHours: number | null = null; backchannelLogoutUri = `${window.location.origin}/api/v1/auth/oidc/backchannel-logout`; @@ -116,21 +114,14 @@ export class AuthenticationSettingsComponent implements OnInit { private libraryService = inject(LibraryService); private groupMappingService = inject(OidcGroupMappingService); private t = inject(TranslocoService); + get allLibraries() { return this.libraryService.libraries(); } - appSettings$: Observable = this.appSettingsService.appSettings$; - - ngOnInit(): void { - this.appSettings$.pipe( - filter((settings): settings is AppSettings => settings != null), - take(1) - ).subscribe(settings => this.loadSettings(settings)); - - this.libraryService.libraryState$ - .pipe( - filter(state => !!state?.loaded), - take(1) - ).subscribe(state => this.allLibraries = state.libraries ?? []); - } + private readonly loadSettingsEffect = effect(() => { + const settings = this.appSettingsService.appSettings(); + if (settings) { + this.loadSettings(settings); + } + }); loadSettings(settings: AppSettings): void { this.oidcEnabled = settings.oidcEnabled; diff --git a/booklore-ui/src/app/features/author-browser/components/author-browser/author-browser.component.html b/booklore-ui/src/app/features/author-browser/components/author-browser/author-browser.component.html index ebf18bf05..f6898e374 100644 --- a/booklore-ui/src/app/features/author-browser/components/author-browser/author-browser.component.html +++ b/booklore-ui/src/app/features/author-browser/components/author-browser/author-browser.component.html @@ -1,5 +1,5 @@ - @if (loading) { + @if (loading()) {
} - @if (!loading) { + @if (!loading()) {

{{ t('browseAllAuthors') }}

@@ -21,7 +21,7 @@ pInputText type="text" [placeholder]="t('searchPlaceholder')" - [ngModel]="searchTerm$ | async" + [ngModel]="searchTerm()" (ngModelChange)="onSearchChange($event)" class="search-input"/>
@@ -29,7 +29,7 @@
@@ -55,15 +55,15 @@
+ [style]="{ width: '100%' }">
- {{ authorScaleService.scaleFactor.toFixed(2) }}x + {{ authorScaleService.scaleFactor().toFixed(2) }}x
@@ -79,7 +79,7 @@ {label: t('filters.matched'), value: 'matched'}, {label: t('filters.unmatched'), value: 'unmatched'} ]" - [ngModel]="(filters$ | async)?.matchStatus" + [ngModel]="filters().matchStatus" (ngModelChange)="onFilterChange('matchStatus', $event)" optionLabel="label" optionValue="value" @@ -95,7 +95,7 @@ {label: t('filters.hasPhoto'), value: 'has-photo'}, {label: t('filters.noPhoto'), value: 'no-photo'} ]" - [ngModel]="(filters$ | async)?.photoStatus" + [ngModel]="filters().photoStatus" (ngModelChange)="onFilterChange('photoStatus', $event)" optionLabel="label" optionValue="value" @@ -113,7 +113,7 @@ {label: t('filters.inProgress'), value: 'in-progress'}, {label: t('filters.unread'), value: 'unread'} ]" - [ngModel]="(filters$ | async)?.readStatus" + [ngModel]="filters().readStatus" (ngModelChange)="onFilterChange('readStatus', $event)" optionLabel="label" optionValue="value" @@ -137,7 +137,7 @@ {label: '21-35', value: '21-35'}, {label: '36+', value: '36+'} ]" - [ngModel]="(filters$ | async)?.bookCount" + [ngModel]="filters().bookCount" (ngModelChange)="onFilterChange('bookCount', $event)" optionLabel="label" optionValue="value" @@ -148,8 +148,8 @@
- @if (activeFilterCount > 0) { + @if (activeFilterCount() > 0) {
- @if (filteredAuthors$ | async; as authorList) { + @if (filteredAuthors(); as authorList) { @if (authorList.length === 0) {
@@ -203,7 +203,7 @@ @for (author of scroll.viewPortItems; track author.id; let i = $index) {
+ [style.--card-scale]="authorScaleService.scaleFactor()"> + @if (currentUser(); as user) { + - @if (authorBooks$ | async; as books) { + @if (authorBooks(); as books) {

{{ t('booksBy', {name: author.name}) }} ({{ books.length }})

@if (books.length === 0) { diff --git a/booklore-ui/src/app/features/author-browser/components/author-detail/author-detail.component.ts b/booklore-ui/src/app/features/author-browser/components/author-detail/author-detail.component.ts index 76296d27d..302baeea1 100644 --- a/booklore-ui/src/app/features/author-browser/components/author-detail/author-detail.component.ts +++ b/booklore-ui/src/app/features/author-browser/components/author-detail/author-detail.component.ts @@ -1,8 +1,6 @@ -import {AfterViewChecked, Component, ElementRef, inject, OnInit, ViewChild} from '@angular/core'; +import {AfterViewChecked, Component, computed, ElementRef, inject, OnInit, signal, ViewChild} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; -import {AsyncPipe, NgClass, NgStyle} from '@angular/common'; -import {combineLatest, Observable} from 'rxjs'; -import {filter, map} from 'rxjs/operators'; +import {NgClass, NgStyle} from '@angular/common'; import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs'; import {ProgressSpinner} from 'primeng/progressspinner'; import {Button} from 'primeng/button'; @@ -14,7 +12,6 @@ import {Tooltip} from 'primeng/tooltip'; import {AuthorService} from '../../service/author.service'; import {AuthorDetails} from '../../model/author.model'; import {BookService} from '../../../book/service/book.service'; -import {Book} from '../../../book/model/book.model'; import {BookCardComponent} from '../../../book/components/book-browser/book-card/book-card.component'; import {CoverScalePreferenceService} from '../../../book/components/book-browser/cover-scale-preference.service'; import {BookCardOverlayPreferenceService} from '../../../book/components/book-browser/book-card-overlay-preference.service'; @@ -29,7 +26,6 @@ import {PageTitleService} from '../../../../shared/service/page-title.service'; templateUrl: './author-detail.component.html', styleUrls: ['./author-detail.component.scss'], imports: [ - AsyncPipe, NgClass, NgStyle, Tabs, @@ -63,7 +59,6 @@ export class AuthorDetailComponent implements OnInit, AfterViewChecked { @ViewChild('descriptionContent') descriptionContentRef?: ElementRef; - author: AuthorDetails | null = null; loading = true; tab = 'books'; isExpanded = false; @@ -71,20 +66,31 @@ export class AuthorDetailComponent implements OnInit, AfterViewChecked { hasPhoto = true; photoTimestamp = Date.now(); quickMatching = false; + private authorState = signal(null); + author = this.authorState.asReadonly(); + authorBooks = computed(() => { + const authorName = this.author()?.name?.toLowerCase(); + if (!authorName) { + return []; + } - authorBooks$!: Observable; + return this.bookService.books().filter(book => + book.metadata?.authors?.some(author => author.toLowerCase() === authorName) + ); + }); get currentCardSize() { - return this.coverScalePreferenceService.currentCardSize; + return this.coverScalePreferenceService.currentCardSize(); } get gridColumnMinWidth(): string { - return this.coverScalePreferenceService.gridColumnMinWidth; + return this.coverScalePreferenceService.gridColumnMinWidth(); } get photoUrl(): string { - if (!this.author) return ''; - return this.authorService.getAuthorPhotoUrl(this.author.id) + '&t=' + this.photoTimestamp; + const author = this.author(); + if (!author) return ''; + return this.authorService.getAuthorPhotoUrl(author.id) + '&t=' + this.photoTimestamp; } get canEditMetadata(): boolean { @@ -99,18 +105,6 @@ export class AuthorDetailComponent implements OnInit, AfterViewChecked { this.tab = tabParam; } this.loadAuthor(authorId); - - this.authorBooks$ = this.bookService.bookState$.pipe( - filter(state => state.loaded && !!state.books), - map(state => { - const books = state.books || []; - const authorName = this.author?.name?.toLowerCase(); - if (!authorName) return []; - return books.filter(b => - b.metadata?.authors?.some(a => a.toLowerCase() === authorName) - ); - }) - ); } ngAfterViewChecked(): void { @@ -129,15 +123,21 @@ export class AuthorDetailComponent implements OnInit, AfterViewChecked { } onAuthorUpdated(updatedAuthor: AuthorDetails): void { - this.author = updatedAuthor; + this.authorState.set(updatedAuthor); this.hasPhoto = true; this.photoTimestamp = Date.now(); + this.authorService.patchAuthorInCache(updatedAuthor.id, { + name: updatedAuthor.name, + asin: updatedAuthor.asin, + hasPhoto: true, + }); } quickMatch(): void { - if (!this.author || this.quickMatching) return; + const author = this.author(); + if (!author || this.quickMatching) return; this.quickMatching = true; - this.authorService.quickMatchAuthor(this.author.id).subscribe({ + this.authorService.quickMatchAuthor(author.id).subscribe({ next: (matched) => { this.onAuthorUpdated(matched); this.quickMatching = false; @@ -161,20 +161,9 @@ export class AuthorDetailComponent implements OnInit, AfterViewChecked { private loadAuthor(authorId: number): void { this.authorService.getAuthorDetails(authorId).subscribe({ next: (author) => { - this.author = author; + this.authorState.set(author); this.loading = false; this.pageTitle.setPageTitle(author.name); - - this.authorBooks$ = this.bookService.bookState$.pipe( - filter(state => state.loaded && !!state.books), - map(state => { - const books = state.books || []; - const name = author.name.toLowerCase(); - return books.filter(b => - b.metadata?.authors?.some(a => a.toLowerCase() === name) - ); - }) - ); }, error: () => { this.loading = false; diff --git a/booklore-ui/src/app/features/author-browser/service/author-query-cache.ts b/booklore-ui/src/app/features/author-browser/service/author-query-cache.ts new file mode 100644 index 000000000..7e5b15171 --- /dev/null +++ b/booklore-ui/src/app/features/author-browser/service/author-query-cache.ts @@ -0,0 +1,10 @@ +import {QueryClient} from '@tanstack/angular-query-experimental'; + +import {AuthorSummary} from '../model/author.model'; +import {AUTHORS_QUERY_KEY} from './author-query-keys'; + +export function patchAuthorInCache(queryClient: QueryClient, authorId: number, fields: Partial): void { + queryClient.setQueryData(AUTHORS_QUERY_KEY, current => + (current ?? []).map(author => author.id === authorId ? {...author, ...fields} : author) + ); +} diff --git a/booklore-ui/src/app/features/author-browser/service/author-query-keys.ts b/booklore-ui/src/app/features/author-browser/service/author-query-keys.ts new file mode 100644 index 000000000..07ebb42a2 --- /dev/null +++ b/booklore-ui/src/app/features/author-browser/service/author-query-keys.ts @@ -0,0 +1 @@ +export const AUTHORS_QUERY_KEY = ['authors'] as const; diff --git a/booklore-ui/src/app/features/author-browser/service/author-scale-preference.service.ts b/booklore-ui/src/app/features/author-browser/service/author-scale-preference.service.ts index 75c816a5a..65586443b 100644 --- a/booklore-ui/src/app/features/author-browser/service/author-scale-preference.service.ts +++ b/booklore-ui/src/app/features/author-browser/service/author-scale-preference.service.ts @@ -1,6 +1,4 @@ -import {inject, Injectable} from '@angular/core'; -import {Subject} from 'rxjs'; -import {debounceTime} from 'rxjs/operators'; +import {inject, Injectable, signal} from '@angular/core'; import {LocalStorageService} from '../../../shared/service/local-storage.service'; @Injectable({ @@ -13,31 +11,46 @@ export class AuthorScalePreferenceService { private readonly localStorageService = inject(LocalStorageService); - private readonly scaleChangeSubject = new Subject(); + private readonly _scaleFactor = signal(1.0); + readonly scaleFactor = this._scaleFactor.asReadonly(); - scaleFactor = 1.0; + private saveTimeout: ReturnType | null = null; + private lastPersistedScale = 1.0; constructor() { - this.loadScaleFromStorage(); - - this.scaleChangeSubject - .pipe(debounceTime(this.DEBOUNCE_MS)) - .subscribe(scale => this.saveScalePreference(scale)); + const initialScale = this.loadScaleFromStorage(); + this._scaleFactor.set(initialScale); + this.lastPersistedScale = initialScale; } setScale(scale: number): void { - this.scaleFactor = scale; - this.scaleChangeSubject.next(scale); + this._scaleFactor.set(scale); + if (scale === this.lastPersistedScale) { + return; + } + this.scheduleSave(scale); + } + + private scheduleSave(scale: number): void { + if (this.saveTimeout) { + clearTimeout(this.saveTimeout); + } + + this.saveTimeout = setTimeout(() => { + this.saveScalePreference(scale); + }, this.DEBOUNCE_MS); } private saveScalePreference(scale: number): void { this.localStorageService.set(this.STORAGE_KEY, scale); + this.lastPersistedScale = scale; } - private loadScaleFromStorage(): void { + private loadScaleFromStorage(): number { const saved = this.localStorageService.get(this.STORAGE_KEY); if (saved !== null && !isNaN(saved)) { - this.scaleFactor = saved; + return saved; } + return 1.0; } } diff --git a/booklore-ui/src/app/features/author-browser/service/author-selection.service.ts b/booklore-ui/src/app/features/author-browser/service/author-selection.service.ts index 00faf6c15..0a08b2b32 100644 --- a/booklore-ui/src/app/features/author-browser/service/author-selection.service.ts +++ b/booklore-ui/src/app/features/author-browser/service/author-selection.service.ts @@ -1,5 +1,4 @@ -import {Injectable} from '@angular/core'; -import {BehaviorSubject, Observable} from 'rxjs'; +import {computed, Injectable, signal} from '@angular/core'; import {AuthorSummary} from '../model/author.model'; export interface AuthorCheckboxClickEvent { @@ -11,20 +10,13 @@ export interface AuthorCheckboxClickEvent { @Injectable({providedIn: 'root'}) export class AuthorSelectionService { - private selectedAuthorsSubject = new BehaviorSubject>(new Set()); + private readonly _selectedAuthors = signal>(new Set()); + readonly selectedAuthors = this._selectedAuthors.asReadonly(); + readonly selectedCount = computed(() => this._selectedAuthors().size); + private currentAuthors: AuthorSummary[] = []; private lastSelectedIndex: number | null = null; - selectedAuthors$: Observable> = this.selectedAuthorsSubject.asObservable(); - - get selectedAuthors(): Set { - return this.selectedAuthorsSubject.value; - } - - get selectedCount(): number { - return this.selectedAuthorsSubject.value.size; - } - setCurrentAuthors(authors: AuthorSummary[]): void { this.currentAuthors = authors; } @@ -55,31 +47,37 @@ export class AuthorSelectionService { } selectAll(): void { - const current = new Set(this.selectedAuthorsSubject.value); - for (const author of this.currentAuthors) { - current.add(author.id); - } - this.selectedAuthorsSubject.next(current); + this._selectedAuthors.update(current => { + const next = new Set(current); + for (const author of this.currentAuthors) { + next.add(author.id); + } + return next; + }); } deselectAll(): void { - this.selectedAuthorsSubject.next(new Set()); + this._selectedAuthors.set(new Set()); this.lastSelectedIndex = null; } getSelectedIds(): number[] { - return Array.from(this.selectedAuthorsSubject.value); + return Array.from(this.selectedAuthors()); } private select(id: number): void { - const current = new Set(this.selectedAuthorsSubject.value); - current.add(id); - this.selectedAuthorsSubject.next(current); + this._selectedAuthors.update(current => { + const next = new Set(current); + next.add(id); + return next; + }); } private deselect(id: number): void { - const current = new Set(this.selectedAuthorsSubject.value); - current.delete(id); - this.selectedAuthorsSubject.next(current); + this._selectedAuthors.update(current => { + const next = new Set(current); + next.delete(id); + return next; + }); } } diff --git a/booklore-ui/src/app/features/author-browser/service/author.service.ts b/booklore-ui/src/app/features/author-browser/service/author.service.ts index fc5849ce8..093638556 100644 --- a/booklore-ui/src/app/features/author-browser/service/author.service.ts +++ b/booklore-ui/src/app/features/author-browser/service/author.service.ts @@ -1,11 +1,14 @@ -import {inject, Injectable} from '@angular/core'; +import {computed, effect, inject, Injectable} from '@angular/core'; import {HttpClient, HttpHeaders} from '@angular/common/http'; -import {BehaviorSubject, Observable} from 'rxjs'; -import {map, tap} from 'rxjs/operators'; +import {lastValueFrom, Observable} from 'rxjs'; +import {map} from 'rxjs/operators'; import {SseClient} from 'ngx-sse-client'; import {API_CONFIG} from '../../../core/config/api-config'; import {AuthorSummary, AuthorDetails, AuthorSearchResult, AuthorMatchRequest, AuthorUpdateRequest, AuthorPhotoResult} from '../model/author.model'; import {AuthService} from '../../../shared/service/auth.service'; +import {injectQuery, queryOptions, QueryClient} from '@tanstack/angular-query-experimental'; +import {AUTHORS_QUERY_KEY} from './author-query-keys'; +import {patchAuthorInCache} from './author-query-cache'; @Injectable({ providedIn: 'root' @@ -15,16 +18,41 @@ export class AuthorService { private http = inject(HttpClient); private authService = inject(AuthService); private sseClient = inject(SseClient); + private queryClient = inject(QueryClient); private readonly baseUrl = `${API_CONFIG.BASE_URL}/api/v1/authors`; private readonly mediaBaseUrl = `${API_CONFIG.BASE_URL}/api/v1/media`; + private readonly token = this.authService.token; - private allAuthorsSubject = new BehaviorSubject(null); - allAuthors$ = this.allAuthorsSubject.asObservable(); + private authorsQuery = injectQuery(() => ({ + ...this.getAuthorsQueryOptions(), + enabled: !!this.token(), + })); - getAllAuthors(): Observable { - return this.http.get(this.baseUrl).pipe( - tap(authors => this.allAuthorsSubject.next(authors)) - ); + allAuthors = computed(() => this.authorsQuery.data() ?? null); + isAuthorsLoading = computed(() => !!this.token() && this.authorsQuery.isPending()); + + constructor() { + effect(() => { + const token = this.token(); + if (token === null) { + this.queryClient.removeQueries({queryKey: AUTHORS_QUERY_KEY}); + } + }); + } + + private getAuthorsQueryOptions() { + return queryOptions({ + queryKey: AUTHORS_QUERY_KEY, + queryFn: () => lastValueFrom(this.http.get(this.baseUrl)) + }); + } + + invalidateAuthors(): void { + void this.queryClient.invalidateQueries({queryKey: AUTHORS_QUERY_KEY, exact: true}); + } + + patchAuthorInCache(authorId: number, fields: Partial): void { + patchAuthorInCache(this.queryClient, authorId, fields); } getAuthorDetails(authorId: number): Observable { diff --git a/booklore-ui/src/app/features/book/components/add-physical-book-dialog/add-physical-book-dialog.component.ts b/booklore-ui/src/app/features/book/components/add-physical-book-dialog/add-physical-book-dialog.component.ts index 18171986b..b895e8d59 100644 --- a/booklore-ui/src/app/features/book/components/add-physical-book-dialog/add-physical-book-dialog.component.ts +++ b/booklore-ui/src/app/features/book/components/add-physical-book-dialog/add-physical-book-dialog.component.ts @@ -1,4 +1,4 @@ -import {Component, DestroyRef, inject, OnInit} from '@angular/core'; +import {Component, computed, effect, inject} from '@angular/core'; import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog'; import {FormsModule} from '@angular/forms'; import {Button} from 'primeng/button'; @@ -13,8 +13,6 @@ import {BookMetadataService} from '../../service/book-metadata.service'; import {LibraryService} from '../../service/library.service'; import {Library} from '../../model/library.model'; import {CreatePhysicalBookRequest} from '../../model/book.model'; -import {filter, take} from 'rxjs/operators'; -import {takeUntilDestroyed} from '@angular/core/rxjs-interop'; import {TranslocoDirective} from '@jsverse/transloco'; @Component({ @@ -34,15 +32,13 @@ import {TranslocoDirective} from '@jsverse/transloco'; ], styleUrl: './add-physical-book-dialog.component.scss', }) -export class AddPhysicalBookDialogComponent implements OnInit { +export class AddPhysicalBookDialogComponent { private dynamicDialogRef = inject(DynamicDialogRef); private dialogConfig = inject(DynamicDialogConfig); private bookService = inject(BookService); private bookMetadataService = inject(BookMetadataService); private libraryService = inject(LibraryService); - private destroyRef = inject(DestroyRef); - libraries: Library[] = []; selectedLibraryId: number | null = null; title: string = ''; isbn: string = ''; @@ -54,49 +50,33 @@ export class AddPhysicalBookDialogComponent implements OnInit { pageCount: number | null = null; categories: string[] = []; - allAuthors: string[] = []; - allCategories: string[] = []; + private readonly metadata = computed(() => this.bookService.uniqueMetadata()); + get allAuthors(): string[] { return this.metadata().authors; } + get allCategories(): string[] { return this.metadata().categories; } filteredAuthors: string[] = []; filteredCategories: string[] = []; coverUrl: string | null = null; isLoading: boolean = false; isFetchingMetadata: boolean = false; + private readonly initializeSelectedLibraryEffect = effect(() => { + const libraries = this.libraries; + if (libraries.length === 0) { + return; + } - ngOnInit(): void { - this.libraryService.libraryState$ - .pipe(takeUntilDestroyed(this.destroyRef)) - .subscribe(state => { - if (state.loaded && state.libraries) { - this.libraries = state.libraries; - if (this.dialogConfig.data?.libraryId) { - this.selectedLibraryId = this.dialogConfig.data.libraryId; - } else if (this.libraries.length > 0 && this.libraries[0].id !== undefined) { - this.selectedLibraryId = this.libraries[0].id; - } - } - }); - this.prepareAutoComplete(); - } + if (this.dialogConfig.data?.libraryId) { + this.selectedLibraryId = this.dialogConfig.data.libraryId; + return; + } - private prepareAutoComplete(): void { - this.bookService.bookState$ - .pipe( - filter((bookState) => bookState.loaded), - take(1) - ) - .subscribe((bookState) => { - const authors = new Set(); - const categories = new Set(); + if (this.selectedLibraryId == null && this.libraries[0].id !== undefined) { + this.selectedLibraryId = this.libraries[0].id; + } + }); - (bookState.books ?? []).forEach((book) => { - book.metadata?.authors?.forEach((author) => authors.add(author)); - book.metadata?.categories?.forEach((category) => categories.add(category)); - }); - - this.allAuthors = Array.from(authors); - this.allCategories = Array.from(categories); - }); + get libraries(): Library[] { + return this.libraryService.libraries(); } filterAuthors(event: AutoCompleteCompleteEvent): void { diff --git a/booklore-ui/src/app/features/book/components/additional-file-uploader/additional-file-uploader.component.ts b/booklore-ui/src/app/features/book/components/additional-file-uploader/additional-file-uploader.component.ts index f0069c822..7d7a6b657 100644 --- a/booklore-ui/src/app/features/book/components/additional-file-uploader/additional-file-uploader.component.ts +++ b/booklore-ui/src/app/features/book/components/additional-file-uploader/additional-file-uploader.component.ts @@ -1,4 +1,4 @@ -import {ChangeDetectorRef, Component, inject, OnDestroy, OnInit, ViewChild} from '@angular/core'; +import {ChangeDetectorRef, Component, effect, inject, OnDestroy, OnInit, ViewChild} from '@angular/core'; import {FormsModule} from '@angular/forms'; import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog'; @@ -12,7 +12,6 @@ import {BookFileService} from '../../service/book-file.service'; import {AppSettingsService} from '../../../../shared/service/app-settings.service'; import {AdditionalFileType, Book} from '../../model/book.model'; import {MessageService} from 'primeng/api'; -import {filter, take} from 'rxjs/operators'; import {TranslocoDirective, TranslocoService} from '@jsverse/transloco'; interface FileTypeOption { @@ -73,18 +72,12 @@ export class AdditionalFileUploaderComponent implements OnInit, OnDestroy { { label: this.t.translate('book.fileUploader.typeAlternativeFormat'), value: AdditionalFileType.ALTERNATIVE_FORMAT }, { label: this.t.translate('book.fileUploader.typeSupplementary'), value: AdditionalFileType.SUPPLEMENTARY } ]; - this.appSettingsService.appSettings$ - .pipe( - filter(settings => settings != null), - take(1) - ) - .subscribe(settings => { - if (settings) { - const maxSizeMb = settings.maxFileUploadSizeInMb || 100; - this.maxFileSizeBytes = maxSizeMb * 1024 * 1024; - this.maxFileSizeDisplay = `${maxSizeMb} MB`; - } - }); + const settings = this.appSettingsService.appSettings(); + if (settings) { + const maxSizeMb = settings.maxFileUploadSizeInMb || 100; + this.maxFileSizeBytes = maxSizeMb * 1024 * 1024; + this.maxFileSizeDisplay = `${maxSizeMb} MB`; + } } ngOnDestroy(): void { diff --git a/booklore-ui/src/app/features/book/components/book-browser/book-browser-entity.service.ts b/booklore-ui/src/app/features/book/components/book-browser/book-browser-entity.service.ts index 795d996c5..a202c7b61 100644 --- a/booklore-ui/src/app/features/book/components/book-browser/book-browser-entity.service.ts +++ b/booklore-ui/src/app/features/book/components/book-browser/book-browser-entity.service.ts @@ -1,16 +1,10 @@ import {Injectable, inject} from '@angular/core'; -import {ActivatedRoute} from '@angular/router'; -import {Observable, of, combineLatest} from 'rxjs'; -import {map, switchMap, take, catchError} from 'rxjs/operators'; +import {ParamMap} from '@angular/router'; import {Library} from '../../model/library.model'; import {Shelf} from '../../model/shelf.model'; import {Book} from '../../model/book.model'; -import {BookState} from '../../model/state/book-state.model'; -import {SortOption} from '../../model/sort.model'; import {LibraryService} from '../../service/library.service'; -import {BookService} from '../../service/book.service'; import {ShelfService} from '../../service/shelf.service'; -import {SortService} from '../../service/sort.service'; import {MagicShelf, MagicShelfService} from '../../../magic-shelf/service/magic-shelf.service'; import {BookRuleEvaluatorService} from '../../../magic-shelf/service/book-rule-evaluator.service'; import {GroupRule} from '../../../magic-shelf/component/magic-shelf-component'; @@ -24,79 +18,61 @@ export interface EntityInfo { @Injectable({providedIn: 'root'}) export class BookBrowserEntityService { private libraryService = inject(LibraryService); - private bookService = inject(BookService); private shelfService = inject(ShelfService); - private sortService = inject(SortService); private magicShelfService = inject(MagicShelfService); private bookRuleEvaluatorService = inject(BookRuleEvaluatorService); - getEntityInfoFromRoute(activatedRoute: ActivatedRoute): Observable { - return activatedRoute.paramMap.pipe( - map(params => { - const libraryId = Number(params.get('libraryId') || NaN); - const shelfId = Number(params.get('shelfId') || NaN); - const magicShelfId = Number(params.get('magicShelfId') || NaN); + getEntityInfo(paramMap: ParamMap): EntityInfo { + const libraryId = Number(paramMap.get('libraryId') || NaN); + const shelfId = Number(paramMap.get('shelfId') || NaN); + const magicShelfId = Number(paramMap.get('magicShelfId') || NaN); - if (!isNaN(libraryId)) { - return {entityId: libraryId, entityType: EntityType.LIBRARY}; - } else if (!isNaN(shelfId)) { - return {entityId: shelfId, entityType: EntityType.SHELF}; - } else if (!isNaN(magicShelfId)) { - return {entityId: magicShelfId, entityType: EntityType.MAGIC_SHELF}; - } else { - return {entityId: NaN, entityType: EntityType.ALL_BOOKS}; - } - }) - ); + if (!Number.isNaN(libraryId)) { + return {entityId: libraryId, entityType: EntityType.LIBRARY}; + } + + if (!Number.isNaN(shelfId)) { + return {entityId: shelfId, entityType: EntityType.SHELF}; + } + + if (!Number.isNaN(magicShelfId)) { + return {entityId: magicShelfId, entityType: EntityType.MAGIC_SHELF}; + } + + return {entityId: NaN, entityType: EntityType.ALL_BOOKS}; } - fetchEntity(entityId: number, entityType: EntityType): Observable { + getEntity(entityId: number, entityType: EntityType): Library | Shelf | MagicShelf | null { switch (entityType) { case EntityType.LIBRARY: - return this.fetchLibrary(entityId); + return this.libraryService.libraries().find(lib => lib.id === entityId) ?? null; case EntityType.SHELF: - return this.fetchShelf(entityId); + return this.shelfService.shelves().find(shelf => shelf.id === entityId) ?? null; case EntityType.MAGIC_SHELF: - return this.fetchMagicShelf(entityId); + return this.magicShelfService.findShelfById(entityId) ?? null; default: - return of(null); + return null; } } - fetchBooksByEntity( - entityId: number, - entityType: EntityType, - sortOption: SortOption - ): Observable { + getBooksByEntity(books: Book[], entityId: number, entityType: EntityType): Book[] { switch (entityType) { case EntityType.LIBRARY: - return this.fetchBooks(book => book.libraryId === entityId, sortOption); + return books.filter(book => book.libraryId === entityId); case EntityType.SHELF: - return this.fetchShelfBooks(entityId, sortOption); - case EntityType.MAGIC_SHELF: - return this.fetchMagicShelfBooks(entityId, sortOption); + return books.filter(book => book.shelves?.some(shelf => shelf.id === entityId) ?? false); + case EntityType.MAGIC_SHELF: { + const magicShelf = this.getEntity(entityId, entityType); + return this.isMagicShelf(magicShelf) ? this.filterByMagicShelf(books, magicShelf) : []; + } + case EntityType.UNSHELVED: + return books.filter(book => !book.shelves || book.shelves.length === 0); case EntityType.ALL_BOOKS: default: - return this.fetchAllBooks(sortOption); + return books; } } - fetchAllBooks(sortOption: SortOption): Observable { - return this.bookService.bookState$.pipe( - map(bookState => this.processBookState(bookState, sortOption)) - ); - } - - fetchUnshelvedBooks(sortOption: SortOption): Observable { - return this.bookService.bookState$.pipe( - map(bookState => ({ - ...bookState, - books: (bookState.books || []).filter(book => !book.shelves || book.shelves.length === 0) - })), - map(bookState => this.processBookState(bookState, sortOption)) - ); - } - isLibrary(entity: Library | Shelf | MagicShelf): entity is Library { return (entity as Library).paths !== undefined; } @@ -105,85 +81,17 @@ export class BookBrowserEntityService { return !!entity && 'filterJson' in entity; } - private fetchLibrary(libraryId: number): Observable { - return this.libraryService.libraryState$.pipe( - map(libraryState => { - if (libraryState.libraries) { - return libraryState.libraries.find(lib => lib.id === libraryId) || null; - } - return null; - }) - ); - } - - private fetchShelf(shelfId: number): Observable { - return this.shelfService.shelfState$.pipe( - map(shelfState => { - if (shelfState.shelves) { - return shelfState.shelves.find(shelf => shelf.id === shelfId) || null; - } - return null; - }) - ); - } - - private fetchMagicShelf(magicShelfId: number): Observable { - return this.magicShelfService.shelvesState$.pipe( - take(1), - switchMap((state) => { - const cached = state.shelves?.find(s => s.id === magicShelfId) ?? null; - if (cached) { - return of(cached); - } - return this.magicShelfService.getShelf(magicShelfId).pipe( - map(shelf => shelf ?? null), - catchError(() => of(null)) - ); - }) - ); - } - - private fetchShelfBooks(shelfId: number, sortOption: SortOption): Observable { - return this.fetchBooks(book => book.shelves?.some(s => s.id === shelfId) ?? false, sortOption); - } - - private fetchMagicShelfBooks(magicShelfId: number, sortOption: SortOption): Observable { - return combineLatest([ - this.bookService.bookState$, - this.magicShelfService.getShelf(magicShelfId) - ]).pipe( - map(([bookState, magicShelf]) => { - if (!bookState.loaded || bookState.error || !magicShelf?.filterJson) { - return bookState; - } - const allBooks = bookState.books ?? []; - const filteredBooks = allBooks.filter(book => - this.bookRuleEvaluatorService.evaluateGroup(book, JSON.parse(magicShelf.filterJson!) as GroupRule, allBooks) - ); - const sortedBooks = this.sortService.applySort(filteredBooks ?? [], sortOption); - return {...bookState, books: sortedBooks}; - }) - ); - } - - private fetchBooks(bookFilter: (book: Book) => boolean, sortOption: SortOption): Observable { - return this.bookService.bookState$.pipe( - map(bookState => { - if (bookState.loaded && !bookState.error) { - const filteredBooks = bookState.books?.filter(bookFilter) || []; - const sortedBooks = this.sortService.applySort(filteredBooks, sortOption); - return {...bookState, books: sortedBooks}; - } - return bookState; - }) - ); - } - - private processBookState(bookState: BookState, sortOption: SortOption): BookState { - if (bookState.loaded && !bookState.error) { - const sortedBooks = this.sortService.applySort(bookState.books || [], sortOption); - return {...bookState, books: sortedBooks}; + private filterByMagicShelf(books: Book[], magicShelf: MagicShelf): Book[] { + if (!magicShelf.filterJson) { + return []; + } + + try { + const groupRule = JSON.parse(magicShelf.filterJson) as GroupRule; + return books.filter(book => this.bookRuleEvaluatorService.evaluateGroup(book, groupRule, books)); + } catch { + console.warn('Invalid filterJson for MagicShelf'); + return []; } - return bookState; } } diff --git a/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.html b/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.html index bc5fceec7..f5b170733 100644 --- a/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.html +++ b/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.html @@ -4,7 +4,7 @@
- @if (entityType$ | async; as entityType) { + @if (entityType(); as entityType) {

@if (entityType === EntityType.ALL_BOOKS) { @@ -18,19 +18,19 @@ } @else if (entityType === EntityType.UNSHELVED) { {{ (isFilterActive || hasSearchTerm) ? t('labels.unshelvedBooksFiltered') : t('labels.unshelvedBooks') }} } @else { - {{ entityType }}: {{ (entity$ | async)?.name }}{{ (isFilterActive || hasSearchTerm) ? ' ' + t('labels.filteredSuffix') : '' }} + {{ entityType }}: {{ entity()?.name }}{{ (isFilterActive || hasSearchTerm) ? ' ' + t('labels.filteredSuffix') : '' }} }

- @if (seriesCollapseFilter.isSeriesCollapsed && (bookState$ | async)?.books; as books) { + @if (seriesCollapseFilter.seriesCollapsed() && books(); as books) {

{{ t('labels.seriesCollapsedInfo', { count: books.length, itemWord: books.length === 1 ? t('labels.item') : t('labels.items') }) }}

}
- @if (userService.userState$ | async; as userState) { + @if (userService.currentUser(); as currentUser) { @if (entityType !== EntityType.ALL_BOOKS && entityType !== EntityType.UNSHELVED && - (userState.user?.permissions?.admin || userState.user?.permissions?.canManageLibrary)) { + (currentUser.permissions.admin || currentUser.permissions.canManageLibrary)) {
- +
} } @@ -106,7 +106,7 @@ @@ -137,15 +137,15 @@
+ [style]="{ width: '100%' }">
- {{ coverScalePreferenceService.scaleFactor.toFixed(2) }}x + {{ coverScalePreferenceService.scaleFactor().toFixed(2) }}x
} @@ -154,7 +154,7 @@ @@ -253,7 +253,7 @@ @@ -261,78 +261,75 @@
- @if (bookState$ | async; as bookState) { + @if (books(); as books) {
- @if (!bookState?.loaded && !bookState?.error) { + @if (isBooksLoading()) {
}
- @if (bookState?.error) { + @if (booksError()) {

- {{ entityType === EntityType.LIBRARY ? t('labels.failedLibrary') : t('labels.failedShelf') }} + {{ entityType() === EntityType.LIBRARY ? t('labels.failedLibrary') : t('labels.failedShelf') }}

- } - @if (!bookState?.error && bookState?.loaded && bookState?.books?.length === 0) { + } @else if (!isBooksLoading() && books.length === 0) {

{{ t('labels.noBooks') }}

} - @if (bookState?.books; as books) { - @if (currentViewMode === 'table' && books.length > 0) { - - } - @if (currentViewMode === 'grid') { - -
- @for (book of scroll.viewPortItems; let i = $index; track book.id) { -
- - -
- } -
-
- } + @if (currentViewMode === 'table' && books.length > 0) { + } - @if (userService.userState$ | async; as userState) { -