From 8791eebda879b95813090dac16fc51992ec7f88d Mon Sep 17 00:00:00 2001 From: Florian THIERRY Date: Tue, 3 Feb 2026 15:06:18 +0100 Subject: [PATCH] Format and organise imports. --- .../my-publications.component.ts | 18 ++----- .../my-publications.service.ts | 51 +++++++++---------- .../publication-update.component.ts | 2 +- 3 files changed, 30 insertions(+), 41 deletions(-) diff --git a/frontend/src/app/pages/my-publications/my-publications.component.ts b/frontend/src/app/pages/my-publications/my-publications.component.ts index 9d73fb5..83861b8 100644 --- a/frontend/src/app/pages/my-publications/my-publications.component.ts +++ b/frontend/src/app/pages/my-publications/my-publications.component.ts @@ -1,13 +1,11 @@ -import {Component, inject, OnInit, Signal} from "@angular/core"; +import {Component, inject, OnInit} from "@angular/core"; import {MatProgressSpinnerModule} from "@angular/material/progress-spinner"; import {MyPublicationsService} from "./my-publications.service"; import {PublicationListComponent} from "../../components/publication-list/publication-list.component"; -import {Publication} from "../../core/rest-services/publications/model/publication"; import {CommonModule} from "@angular/common"; import {RouterModule} from "@angular/router"; import {MatTooltipModule} from "@angular/material/tooltip"; import {MatRippleModule} from "@angular/material/core"; -import {toSignal} from "@angular/core/rxjs-interop"; @Component({ @@ -27,17 +25,9 @@ import {toSignal} from "@angular/core/rxjs-interop"; export class MyPublicationsComponent implements OnInit { private readonly myPublicationsService = inject(MyPublicationsService); - get publications(): Signal { - return toSignal(this.myPublicationsService.publications$, {initialValue: []}); - } - - get isLoading(): Signal { - return toSignal(this.myPublicationsService.isLoading$, {initialValue: false}); - } - - get isLoaded(): Signal { - return toSignal(this.myPublicationsService.isLoaded$, {initialValue: false}); - } + publications = this.myPublicationsService.publications; + isLoading = this.myPublicationsService.isLoading; + isLoaded = this.myPublicationsService.isLoaded; ngOnInit(): void { this.myPublicationsService.loadAuthenticatedUserPublications(); diff --git a/frontend/src/app/pages/my-publications/my-publications.service.ts b/frontend/src/app/pages/my-publications/my-publications.service.ts index bfb92b4..d25f3b0 100644 --- a/frontend/src/app/pages/my-publications/my-publications.service.ts +++ b/frontend/src/app/pages/my-publications/my-publications.service.ts @@ -1,57 +1,56 @@ -import {inject, Injectable} from "@angular/core"; +import {inject, Injectable, Signal, signal} from "@angular/core"; import {PublicationRestService} from "../../core/rest-services/publications/publication.rest-service"; import {AuthenticationService} from "../../core/service/authentication.service"; -import {BehaviorSubject, Observable} from "rxjs"; import {Publication} from "../../core/rest-services/publications/model/publication"; import {Router} from "@angular/router"; import {MatSnackBar} from "@angular/material/snack-bar"; @Injectable() export class MyPublicationsService { - private readonly authenticationService = inject(AuthenticationService); - private readonly publicationRestService = inject(PublicationRestService); - private readonly snackBar = inject(MatSnackBar); - private readonly router = inject(Router); - private publicationsSubject = new BehaviorSubject([]); - private isLoadingSubject = new BehaviorSubject(false); - private isLoadedSubject = new BehaviorSubject(false); + readonly #authenticationService = inject(AuthenticationService); + readonly #publicationRestService = inject(PublicationRestService); + readonly #snackBar = inject(MatSnackBar); + readonly #router = inject(Router); + #publications = signal([]); + #isLoading = signal(false); + #isLoaded = signal(false); - get publications$(): Observable { - return this.publicationsSubject.asObservable(); + get publications(): Signal { + return this.#publications.asReadonly(); } - get isLoading$(): Observable { - return this.isLoadingSubject.asObservable(); + get isLoading(): Signal { + return this.#isLoading.asReadonly(); } - get isLoaded$(): Observable { - return this.isLoadedSubject.asObservable(); + get isLoaded(): Signal { + return this.#isLoaded.asReadonly(); } loadAuthenticatedUserPublications(): void { - const authenticatedUser = this.authenticationService.getAuthenticatedUser(); + const authenticatedUser = this.#authenticationService.getAuthenticatedUser(); if (authenticatedUser) { - this.isLoadingSubject.next(true); - this.isLoadedSubject.next(false); + this.#isLoading.set(true); + this.#isLoaded.set(false); const query = `author_id=${authenticatedUser.id}`; - this.publicationRestService.search(query) + this.#publicationRestService.search(query) .then(publications => { - this.publicationsSubject.next(publications); + this.#publications.set(publications); }) .catch(error => { const errorMessage = $localize`An error occurred while retrieving your publications...`; - this.snackBar.open(errorMessage, $localize`Close`, {duration: 5000}); + this.#snackBar.open(errorMessage, $localize`Close`, {duration: 5000}); console.error(errorMessage, error); }) .finally(() => { - this.isLoadingSubject.next(false); - this.isLoadedSubject.next(true); + this.#isLoading.set(false); + this.#isLoaded.set(true); }); } else { - this.authenticationService.unauthenticate(); - this.snackBar.open($localize`You are unauthenticated. Please, log-in first.`, $localize`Close`, {duration: 5000}); - this.router.navigate(['/login']); + this.#authenticationService.unauthenticate(); + this.#snackBar.open($localize`You are unauthenticated. Please, log-in first.`, $localize`Close`, {duration: 5000}); + this.#router.navigate(['/login']); } } } diff --git a/frontend/src/app/pages/publication-update/publication-update.component.ts b/frontend/src/app/pages/publication-update/publication-update.component.ts index 80e6d2d..d02002b 100644 --- a/frontend/src/app/pages/publication-update/publication-update.component.ts +++ b/frontend/src/app/pages/publication-update/publication-update.component.ts @@ -43,7 +43,7 @@ export class PublicationUpdateComponent { #publicationId$ = this.#activatedRoute.params .pipe(map(queryParams => queryParams['publicationId'])); - #publicationId = toSignal(this.#publicationId$, { initialValue: undefined }); + #publicationId = toSignal(this.#publicationId$, {initialValue: undefined}); get isLoading(): Signal { return this.#isLoading.asReadonly();