Add submit button component and style it.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { Location } from "@angular/common";
|
||||
import { inject, Injectable, OnDestroy } from "@angular/core";
|
||||
import { MatSnackBar } from "@angular/material/snack-bar";
|
||||
import { ActivatedRoute } from "@angular/router";
|
||||
import { BehaviorSubject, Observable, Subscription } from "rxjs";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
import { BehaviorSubject, Observable, Subscription, timeout } from "rxjs";
|
||||
import { Publication } from "../../core/rest-services/publications/model/publication";
|
||||
import { PublicationRestService } from "../../core/rest-services/publications/publication.rest-service";
|
||||
import { copy } from '../../core/utils/ObjectUtils';
|
||||
@@ -32,12 +32,14 @@ export class PublicationEditionService implements OnDestroy {
|
||||
private readonly activatedRoute = inject(ActivatedRoute);
|
||||
private readonly publicationRestService = inject(PublicationRestService);
|
||||
private readonly location = inject(Location);
|
||||
private readonly router = inject(Router);
|
||||
private readonly snackBar = inject(MatSnackBar);
|
||||
private readonly dialog = inject(MatDialog);
|
||||
|
||||
private isLoadingSubject = new BehaviorSubject<boolean>(false);
|
||||
private publicationSubject = new BehaviorSubject<Publication>(copy(DEFAULT_PUBLICATION));
|
||||
private subscriptions: Subscription[] = [];
|
||||
private isSavingSubject = new BehaviorSubject<boolean>(false);
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.subscriptions.forEach(subscription => subscription.unsubscribe());
|
||||
@@ -55,6 +57,10 @@ export class PublicationEditionService implements OnDestroy {
|
||||
return this.isLoadingSubject.asObservable();
|
||||
}
|
||||
|
||||
get isSaving$(): Observable<boolean> {
|
||||
return this.isSavingSubject.asObservable();
|
||||
}
|
||||
|
||||
get publication$(): Observable<Publication> {
|
||||
return this.publicationSubject.asObservable();
|
||||
}
|
||||
@@ -117,4 +123,22 @@ export class PublicationEditionService implements OnDestroy {
|
||||
});
|
||||
this.subscriptions.push(afterDialogCloseSubscription);
|
||||
}
|
||||
|
||||
save(): void {
|
||||
const publication = this._publication;
|
||||
|
||||
this.isSavingSubject.next(true);
|
||||
setTimeout(() => this.isSavingSubject.next(false), 1500);
|
||||
// this.publicationRestService.update(publication)
|
||||
// .then(() => {
|
||||
// this.snackBar.open('Publication updated succesfully!', 'Close', { duration: 5000 });
|
||||
// this.router.navigate(['/home']);
|
||||
// })
|
||||
// .catch(error => {
|
||||
// const errorMessage = 'An error occured while saving publication modifications.';
|
||||
// console.error(errorMessage, error);
|
||||
// this.snackBar.open(errorMessage, 'Close', { duration: 5000 });
|
||||
// })
|
||||
// .finally(() => this.isSavingSubject.next(false));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user