Use signals ont publication creation and update pages.
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
<app-publication-edition
|
@if (publicationIsNotNull()) {
|
||||||
title="Creation of a new publication"
|
<app-publication-edition
|
||||||
[publication]="publication"
|
title="Creation of a new publication"
|
||||||
[isSaving$]="isSaving$"
|
[publication]="publication()!!"
|
||||||
(publicationSave)="onPublicationSave($event)"
|
[isSaving$]="isSaving$"
|
||||||
i18n-title>
|
(publicationSave)="onPublicationSave($event)"
|
||||||
</app-publication-edition>
|
i18n-title>
|
||||||
|
</app-publication-edition>
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Component, inject, OnInit } from "@angular/core";
|
import { Component, computed, inject, OnInit, signal } from "@angular/core";
|
||||||
import { PublicationEditionComponent } from "../../components/publication-edition/publication-edition.component";
|
import { PublicationEditionComponent } from "../../components/publication-edition/publication-edition.component";
|
||||||
import { PublicationRestService } from "../../core/rest-services/publications/publication.rest-service";
|
import { PublicationRestService } from "../../core/rest-services/publications/publication.rest-service";
|
||||||
import { ActivatedRoute, Router } from "@angular/router";
|
import { ActivatedRoute, Router } from "@angular/router";
|
||||||
@@ -26,7 +26,8 @@ export class PublicationCreationComponent implements OnInit {
|
|||||||
private readonly snackBar = inject(MatSnackBar);
|
private readonly snackBar = inject(MatSnackBar);
|
||||||
private isSavingSubject = new BehaviorSubject<boolean>(false);
|
private isSavingSubject = new BehaviorSubject<boolean>(false);
|
||||||
private subscriptions: Subscription[] = [];
|
private subscriptions: Subscription[] = [];
|
||||||
publication!: Publication;
|
publication = signal<Publication | undefined>(undefined);
|
||||||
|
publicationIsNotNull = computed(() => !!this.publication());
|
||||||
|
|
||||||
get isSaving$(): Observable<boolean> {
|
get isSaving$(): Observable<boolean> {
|
||||||
return this.isSavingSubject.asObservable();
|
return this.isSavingSubject.asObservable();
|
||||||
@@ -40,7 +41,7 @@ export class PublicationCreationComponent implements OnInit {
|
|||||||
name: authenticatedUser.pseudo,
|
name: authenticatedUser.pseudo,
|
||||||
image: authenticatedUser.photoId ?? ''
|
image: authenticatedUser.photoId ?? ''
|
||||||
};
|
};
|
||||||
this.publication = {
|
const newPublication: Publication = {
|
||||||
id: '',
|
id: '',
|
||||||
key: '',
|
key: '',
|
||||||
title: '',
|
title: '',
|
||||||
@@ -52,6 +53,7 @@ export class PublicationCreationComponent implements OnInit {
|
|||||||
categoryId: '',
|
categoryId: '',
|
||||||
author
|
author
|
||||||
};
|
};
|
||||||
|
this.publication.set(newPublication);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
@if ((isLoading$ | async) == true) {
|
@if (isLoading()) {
|
||||||
<h2 i18n>Loading publication to edit...</h2>
|
<h2 i18n>Loading publication to edit...</h2>
|
||||||
<mat-spinner></mat-spinner>
|
<mat-spinner></mat-spinner>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { CommonModule, Location } from '@angular/common';
|
import { CommonModule, Location } from '@angular/common';
|
||||||
import { Component, inject, OnDestroy, OnInit } from '@angular/core';
|
import { Component, inject, OnDestroy, OnInit, signal } from '@angular/core';
|
||||||
import { ReactiveFormsModule } from '@angular/forms';
|
import { ReactiveFormsModule } from '@angular/forms';
|
||||||
import { MatDialogModule } from '@angular/material/dialog';
|
import { MatDialogModule } from '@angular/material/dialog';
|
||||||
import { MatIconModule } from '@angular/material/icon';
|
import { MatIconModule } from '@angular/material/icon';
|
||||||
@@ -41,21 +41,17 @@ export class PublicationUpdateComponent implements OnInit, OnDestroy {
|
|||||||
private readonly location = inject(Location);
|
private readonly location = inject(Location);
|
||||||
private readonly router = inject(Router);
|
private readonly router = inject(Router);
|
||||||
private readonly snackBar = inject(MatSnackBar);
|
private readonly snackBar = inject(MatSnackBar);
|
||||||
private isLoadingSubject = new BehaviorSubject<boolean>(false);
|
|
||||||
private isSavingSubject = new BehaviorSubject<boolean>(false);
|
private isSavingSubject = new BehaviorSubject<boolean>(false);
|
||||||
private subscriptions: Subscription[] = [];
|
private subscriptions: Subscription[] = [];
|
||||||
|
isLoading = signal(false);
|
||||||
publication: Publication | undefined;
|
publication: Publication | undefined;
|
||||||
|
|
||||||
get isLoading$(): Observable<boolean> {
|
|
||||||
return this.isLoadingSubject.asObservable();
|
|
||||||
}
|
|
||||||
|
|
||||||
get isSaving$(): Observable<boolean> {
|
get isSaving$(): Observable<boolean> {
|
||||||
return this.isSavingSubject.asObservable();
|
return this.isSavingSubject.asObservable();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.isLoadingSubject.next(true);
|
this.isLoading.set(true);
|
||||||
this.activatedRoute.paramMap.subscribe(params => {
|
this.activatedRoute.paramMap.subscribe(params => {
|
||||||
const publicationId = params.get('publicationId');
|
const publicationId = params.get('publicationId');
|
||||||
if (publicationId == undefined) {
|
if (publicationId == undefined) {
|
||||||
@@ -71,7 +67,7 @@ export class PublicationUpdateComponent implements OnInit, OnDestroy {
|
|||||||
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
|
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
|
||||||
console.error(errorMessage, error)
|
console.error(errorMessage, error)
|
||||||
})
|
})
|
||||||
.finally(() => this.isLoadingSubject.next(false));
|
.finally(() => this.isLoading.set(false));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user