Fixing Angular 21 by migrating all values by signals. #11

Merged
florian merged 10 commits from fixing-angular-21 into main 2026-02-03 15:07:56 +01:00
2 changed files with 14 additions and 13 deletions
Showing only changes of commit bf7e755c28 - Show all commits

View File

@@ -1,8 +1,8 @@
@if (isLoading) { @if (isLoading()) {
<h2 i18n>Publication content loading...</h2> <h2 i18n>Publication content loading...</h2>
<mat-spinner></mat-spinner> <mat-spinner></mat-spinner>
} @else { } @else {
@if (publication) { @if (publication(); as publication) {
<div class="card"> <div class="card">
<img src="/api/pictures/{{ publication.illustrationId }}" /> <img src="/api/pictures/{{ publication.illustrationId }}" />
<header> <header>
@@ -32,7 +32,7 @@
@if (isAuthorAndUserEquals) { @if (isAuthorAndUserEquals) {
<button type="button" <button type="button"
(click)="deletePublication()" (click)="deletePublication()"
matTooltip="Click to delete the publication" matTooltip="Click to delete the publication"
matTooltipPosition="left" matTooltipPosition="left"
matRipple matRipple
i18n-matTooltip> i18n-matTooltip>
@@ -47,4 +47,4 @@
<h1 i18n>Publication failed to load...</h1> <h1 i18n>Publication failed to load...</h1>
</div> </div>
} }
} }

View File

@@ -1,5 +1,5 @@
import { CommonModule, Location } from '@angular/common'; import { CommonModule, Location } from '@angular/common';
import { Component, OnDestroy, OnInit, inject } from '@angular/core'; import {Component, OnDestroy, OnInit, inject, signal} from '@angular/core';
import { MatRippleModule } from '@angular/material/core'; import { MatRippleModule } from '@angular/material/core';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { MatIcon } from '@angular/material/icon'; import { MatIcon } from '@angular/material/icon';
@@ -37,9 +37,9 @@ export class PublicationComponent implements OnInit, OnDestroy {
private readonly snackBar = inject(MatSnackBar); private readonly snackBar = inject(MatSnackBar);
private paramMapSubscription?: Subscription; private paramMapSubscription?: Subscription;
private afterDialogCloseSubscription?: Subscription; private afterDialogCloseSubscription?: Subscription;
isLoading: boolean = false; isLoading = signal(false);
isAuthorAndUserEquals: boolean = false; isAuthorAndUserEquals: boolean = false;
publication?: Publication; publication = signal<Publication | null>(null);
ngOnInit(): void { ngOnInit(): void {
this.paramMapSubscription = this.activatedRoute this.paramMapSubscription = this.activatedRoute
@@ -48,12 +48,12 @@ export class PublicationComponent implements OnInit, OnDestroy {
const publicationId = params.get('publicationId'); const publicationId = params.get('publicationId');
if (publicationId) { if (publicationId) {
this.isLoading = true; this.isLoading.set(true);
this.publicationRestService.getById(publicationId) this.publicationRestService.getById(publicationId)
.then(publication => { .then(publication => {
this.publication = publication; this.publication.set(publication);
this.isAuthorAndUserEquals = this.authenticationService.getAuthenticatedUser()?.id === this.publication.author.id; this.isAuthorAndUserEquals = this.authenticationService.getAuthenticatedUser()?.id === this.publication()?.author.id;
setTimeout(() => Prism.highlightAll(), 100); setTimeout(() => Prism.highlightAll(), 100);
}) })
.catch(error => { .catch(error => {
@@ -62,7 +62,7 @@ export class PublicationComponent implements OnInit, OnDestroy {
console.error(errorMessage, error); console.error(errorMessage, error);
}) })
.finally(() => { .finally(() => {
this.isLoading = false; this.isLoading.set(false);
}); });
} }
}); });
@@ -86,8 +86,9 @@ export class PublicationComponent implements OnInit, OnDestroy {
this.afterDialogCloseSubscription = dialogRef.afterClosed() this.afterDialogCloseSubscription = dialogRef.afterClosed()
.subscribe(response => { .subscribe(response => {
if (response && this.publication?.id) { const publication = this.publication();
this.publicationRestService.delete(this.publication.id); if (response && publication?.id) {
this.publicationRestService.delete(publication.id);
this.snackBar.open($localize`Publication deleted`, $localize`Close`, { duration: 5000 }); this.snackBar.open($localize`Publication deleted`, $localize`Close`, { duration: 5000 });
this.location.back(); this.location.back();
} }