Image Upload, spinner aktivirt, listings & details überarbeitet

This commit is contained in:
2024-03-18 18:17:04 +01:00
parent 2b27ab8ba5
commit fd91adda57
31 changed files with 582 additions and 263 deletions

View File

@@ -1,21 +1,39 @@
import { HttpInterceptorFn } from '@angular/common/http';
import { inject } from '@angular/core';
import { tap } from 'rxjs';
import { HttpEvent, HttpHandler, HttpInterceptor, HttpInterceptorFn, HttpRequest } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';
import { Observable, tap } from 'rxjs';
import { v4 } from 'uuid';
import { LoadingService } from '../services/loading.service';
export const loadingInterceptor: HttpInterceptorFn = (req, next) => {
const loadingService = inject(LoadingService);
// export const loadingInterceptor: HttpInterceptorFn = (req, next) => {
// const loadingService = inject(LoadingService);
const requestId = `HTTP-${v4()}`;
// const requestId = `HTTP-${v4()}`;
loadingService.startLoading(requestId);
// loadingService.startLoading(requestId);
return next(req).pipe(
tap({
finalize: () => loadingService.stopLoading(requestId),
error: () => loadingService.stopLoading(requestId),
complete: () => loadingService.stopLoading(requestId),
})
);
};
// return next(req).pipe(
// tap({
// finalize: () => loadingService.stopLoading(requestId),
// error: () => loadingService.stopLoading(requestId),
// complete: () => loadingService.stopLoading(requestId),
// })
// );
// };
@Injectable()
export class LoadingInterceptor implements HttpInterceptor {
constructor(private loadingService:LoadingService) { }
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
console.log("Intercepting Requests")
const requestId = `HTTP-${v4()}`;
this.loadingService.startLoading(requestId,request.url);
// return next.handle(request);
return next.handle(request).pipe(
tap({
finalize: () => this.loadingService.stopLoading(requestId), // Stoppt den Ladevorgang, wenn die Anfrage abgeschlossen ist
// Beachte, dass 'error' und 'complete' hier entfernt wurden, da 'finalize' in allen Fällen aufgerufen wird,
// egal ob die Anfrage erfolgreich war, einen Fehler geworfen hat oder abgeschlossen wurde.
})
);
}
}