Fixing Angular 21 by migrating all values by signals. (#11)
Some checks failed
Build and Deploy Java Gradle Application / build-and-deploy (push) Failing after 53s

This commit was merged in pull request #11.
This commit is contained in:
2026-02-03 15:07:55 +01:00
parent 1ca2f872f7
commit 0cce8b2982
102 changed files with 4102 additions and 4852 deletions

View File

@@ -1,74 +1,53 @@
import { Component, inject, OnInit } from "@angular/core";
import { PublicationEditionComponent } from "../../components/publication-edition/publication-edition.component";
import { PublicationRestService } from "../../core/rest-services/publications/publication.rest-service";
import { ActivatedRoute, Router } from "@angular/router";
import { MatSnackBar } from "@angular/material/snack-bar";
import { BehaviorSubject, Observable, Subscription } from "rxjs";
import { Publication } from "../../core/rest-services/publications/model/publication";
import { AuthenticationService } from "../../core/service/authentication.service";
import { Author } from "../../core/rest-services/publications/model/author";
import {Component, inject, OnInit, signal} from "@angular/core";
import {PublicationEditionComponent} from "../../components/publication-edition/publication-edition.component";
import {PublicationRestService} from "../../core/rest-services/publications/publication.rest-service";
import {Router} from "@angular/router";
import {MatSnackBar} from "@angular/material/snack-bar";
import {DEFAULT_PUBLICATION, Publication} from "../../core/rest-services/publications/model/publication";
import {AuthenticationService} from "../../core/service/authentication.service";
import {Author} from "../../core/rest-services/publications/model/author";
@Component({
selector: 'app-publication-creation',
templateUrl: './publication-creation.component.html',
styleUrl: './publication-creation.component.scss',
imports: [
selector: 'app-publication-creation',
templateUrl: './publication-creation.component.html',
styleUrl: './publication-creation.component.scss',
imports: [
PublicationEditionComponent
]
]
})
export class PublicationCreationComponent implements OnInit {
private readonly authenticationService = inject(AuthenticationService);
private readonly publicationRestService = inject(PublicationRestService);
private readonly router = inject(Router);
private readonly snackBar = inject(MatSnackBar);
private isSavingSubject = new BehaviorSubject<boolean>(false);
private subscriptions: Subscription[] = [];
publication!: Publication;
readonly #authenticationService = inject(AuthenticationService);
readonly #publicationRestService = inject(PublicationRestService);
readonly #router = inject(Router);
readonly #snackBar = inject(MatSnackBar);
isSaving = signal(false);
publication = signal<Publication>(DEFAULT_PUBLICATION);
get isSaving$(): Observable<boolean> {
return this.isSavingSubject.asObservable();
ngOnInit(): void {
const authenticatedUser = this.#authenticationService.getAuthenticatedUser();
if (authenticatedUser) {
const author: Author = {
id: authenticatedUser.id,
name: authenticatedUser.pseudo,
image: authenticatedUser.photoId ?? ''
};
const newPublication: Publication = {...DEFAULT_PUBLICATION, author};
this.publication.set(newPublication);
}
}
ngOnInit(): void {
const authenticatedUser = this.authenticationService.getAuthenticatedUser();
if (authenticatedUser) {
const author: Author = {
id: authenticatedUser.id,
name: authenticatedUser.pseudo,
image: authenticatedUser.photoId ?? ''
};
this.publication = {
id: '',
key: '',
title: '',
text: '',
parsedText: '',
description: '',
creationDate: new Date(),
illustrationId: '',
categoryId: '',
author
};
}
}
ngOnDestroy(): void {
this.subscriptions.forEach(subscription => subscription?.unsubscribe());
}
onPublicationSave(publication: Publication): void {
this.isSavingSubject.next(true);
this.publicationRestService.create(publication)
.then(() => {
this.snackBar.open($localize`Publication created succesfully!`, $localize`Close`, { duration: 5000 });
this.router.navigate(['/my-publications']);
})
.catch(error => {
const errorMessage = $localize`An error occured while saving new publication.`;
console.error(errorMessage, error);
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
})
.finally(() => this.isSavingSubject.next(false));
}
}
onPublicationSave(publication: Publication): void {
this.isSaving.set(true);
this.#publicationRestService.create(publication)
.then(() => {
this.#snackBar.open($localize`Publication created succesfully!`, $localize`Close`, {duration: 5000});
this.#router.navigate(['/my-publications']);
})
.catch(error => {
const errorMessage = $localize`An error occured while saving new publication.`;
console.error(errorMessage, error);
this.#snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
})
.finally(() => this.isSaving.set(false));
}
}