This commit is contained in:
Florian THIERRY
2024-09-21 21:34:16 +02:00
parent 208b935ffa
commit f8d73c9ed0
12 changed files with 110 additions and 76 deletions

View File

@@ -1,9 +1,8 @@
import { Injectable, OnDestroy, inject } from '@angular/core';
import { CategoryService } from '../../core/service/category.service';
import { BehaviorSubject, Observable, Subscription, map } from 'rxjs';
import { Category } from '../../core/rest-services/category/model/category';
import { CategoryRestService } from '../../core/rest-services/category/category.rest-service';
import { Injectable, inject } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
import { BehaviorSubject, Observable } from 'rxjs';
import { CategoryRestService } from '../../core/rest-services/category/category.rest-service';
import { Category } from '../../core/rest-services/category/model/category';
export interface DisplayableCategory {
id: string;
@@ -20,31 +19,13 @@ export interface DisplayableSubCategory {
@Injectable({
providedIn: 'root'
})
export class SideMenuService implements OnDestroy {
export class SideMenuService {
private categoryRestService = inject(CategoryRestService);
private snackBar = inject(MatSnackBar);
private categoriesSubject = new BehaviorSubject<DisplayableCategory[]>([]);
private isLoadingSubject = new BehaviorSubject<boolean>(false);
private isLoadedSubject = new BehaviorSubject<boolean>(false);
constructor() {
// this.categoriesSubscription = this.categoryService.categories$
// .pipe(
// map(categories =>
// categories
// .filter(category => category.subCategories?.length)
// .map(category =>
// this.mapToDisplayableCategory(category)
// )
// )
// )
// .subscribe(categories => this.categoriesSubject.next(categories));
}
ngOnDestroy(): void {
// this.categoriesSubscription?.unsubscribe();
}
private mapToDisplayableCategory(category: Category): DisplayableCategory {
return {
id: category.id,
@@ -89,9 +70,9 @@ export class SideMenuService implements OnDestroy {
this.categoriesSubject.next(displayableCategories);
})
.catch(error => {
const errorMessage = "An error occured while loading categories.";
const errorMessage = $localize`An error occured while loading categories.`;
console.error(errorMessage, error);
this.snackBar.open(errorMessage, 'Close', { duration: 5000 });
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
})
.finally(() => {
this.isLoadingSubject.next(false);