11 Commits

Author SHA1 Message Date
Florian THIERRY
2d5962d7af Fix ci. 2026-02-03 15:55:15 +01:00
Florian THIERRY
8791eebda8 Format and organise imports. 2026-02-03 15:06:18 +01:00
Florian THIERRY
64aecec4af Fix publication update component. 2026-02-03 14:28:50 +01:00
Florian THIERRY
c91bb7b720 Convert observables to signals. 2026-02-03 11:00:29 +01:00
Florian THIERRY
a2de24fd93 Convert observables to signals. 2026-02-02 17:51:49 +01:00
Florian THIERRY
ebe46a0d11 Convert observables to signals. 2026-02-02 17:38:57 +01:00
Florian THIERRY
a3637faafa Rework picture selector to use signals. 2026-02-02 17:29:49 +01:00
Florian THIERRY
987d187c44 Rework search page to use signals. 2026-02-02 17:26:30 +01:00
Florian THIERRY
bf7e755c28 Fix page display after receiving data from backend. 2026-02-02 17:14:21 +01:00
Florian THIERRY
241f765648 Upgrade package-lock.json 2026-02-02 16:56:55 +01:00
Florian THIERRY
20782cd45a Upgrade frontend dependencies. 2026-02-02 16:55:32 +01:00
4 changed files with 51 additions and 40 deletions

View File

@@ -1,6 +1,6 @@
@for (category of categories(); track category.id) { @for (category of categories$ | async; track category) {
<div class="category {{category.isOpenned ? 'openned' : ''}}"> <div class="category {{category.isOpenned ? 'openned' : ''}}">
<div id="category-{{category.id}}" class="category-header" (click)="setOpened(category)"> <div id="category-{{category.id}}" class="category-header" (click)="setOpenned(category)">
{{ category.name }} {{ category.name }}
<mat-icon>chevron_right</mat-icon> <mat-icon>chevron_right</mat-icon>
</div> </div>

View File

@@ -1,7 +1,8 @@
import {CommonModule} from "@angular/common"; import {CommonModule} from "@angular/common";
import {Component, inject, OnInit, output, Signal} from "@angular/core"; import {Component, EventEmitter, inject, OnInit, Output} from "@angular/core";
import {MatIconModule} from "@angular/material/icon"; import {MatIconModule} from "@angular/material/icon";
import {DisplayableCategory, SideMenuService} from "../side-menu.service"; import {DisplayableCategory, SideMenuService} from "../side-menu.service";
import {Observable} from "rxjs";
import {RouterModule} from "@angular/router"; import {RouterModule} from "@angular/router";
@Component({ @Component({
@@ -15,44 +16,45 @@ import {RouterModule} from "@angular/router";
styleUrl: './categories-menu.component.scss' styleUrl: './categories-menu.component.scss'
}) })
export class CategoriesMenuComponent implements OnInit { export class CategoriesMenuComponent implements OnInit {
readonly #sideMenuService = inject(SideMenuService); private sideMenuService = inject(SideMenuService);
categoryClicked = output<void>(); @Output()
categoryClicked = new EventEmitter<void>();
ngOnInit(): void { ngOnInit(): void {
this.#sideMenuService.loadCategories(); this.sideMenuService.loadCategories();
} }
get categories(): Signal<DisplayableCategory[]> { get categories$(): Observable<DisplayableCategory[]> {
return this.#sideMenuService.categories; return this.sideMenuService.categories$;
} }
setOpened(category: DisplayableCategory): void { setOpenned(category: DisplayableCategory): void {
if (category.isOpenned) { if (category.isOpenned) {
const categoryDiv = document.getElementById(`category-${category.id}`); const categoryDiv = document.getElementById(`category-${category.id}`);
if (categoryDiv) { if (categoryDiv) {
this.#closeAccordion(categoryDiv); this.closeAccordion(categoryDiv);
} }
} else { } else {
const categoriesDivs = document.getElementsByClassName('category-header'); const categoriesDivs = document.getElementsByClassName('category-header');
Array.from(categoriesDivs) Array.from(categoriesDivs)
.map(category => category as HTMLElement) .map(category => category as HTMLElement)
.forEach(categoryDiv => this.#closeAccordion(categoryDiv)); .forEach(categoryDiv => this.closeAccordion(categoryDiv));
const categoryDiv = document.getElementById(`category-${category.id}`); const categoryDiv = document.getElementById(`category-${category.id}`);
if (categoryDiv) { if (categoryDiv) {
this.#openAccordion(categoryDiv); this.openAccordion(categoryDiv);
} }
} }
this.#sideMenuService.setOpened(category); this.sideMenuService.setOpenned(category);
} }
#closeAccordion(categoryDiv: HTMLElement): void { private closeAccordion(categoryDiv: HTMLElement): void {
const divContent = categoryDiv?.nextElementSibling as HTMLElement; const divContent = categoryDiv?.nextElementSibling as HTMLElement;
divContent.style.maxHeight = '0'; divContent.style.maxHeight = '0';
} }
#openAccordion(categoryDiv: HTMLElement): void { private openAccordion(categoryDiv: HTMLElement): void {
const divContent = categoryDiv?.nextElementSibling as HTMLElement; const divContent = categoryDiv?.nextElementSibling as HTMLElement;
divContent.style.maxHeight = `${divContent.scrollHeight}px`; divContent.style.maxHeight = `${divContent.scrollHeight}px`;
} }

View File

@@ -14,6 +14,6 @@
</button> </button>
</h1> </h1>
<h2 i18n>Categories</h2> <h2 i18n>Categories</h2>
<app-categories-menu (categoryClicked)="close()"/> <app-categories-menu (categoryClicked)="close()"></app-categories-menu>
</div> </div>
<div class="overlay {{ isOpened() ? 'displayed' : ''}}" (click)="close()"></div> <div class="overlay {{ isOpened() ? 'displayed' : ''}}" (click)="close()"></div>

View File

@@ -1,5 +1,6 @@
import {inject, Injectable, Signal, signal} from '@angular/core'; import {inject, Injectable} from '@angular/core';
import {MatSnackBar} from '@angular/material/snack-bar'; import {MatSnackBar} from '@angular/material/snack-bar';
import {BehaviorSubject, Observable} from 'rxjs';
import {CategoryRestService} from '../../core/rest-services/category/category.rest-service'; import {CategoryRestService} from '../../core/rest-services/category/category.rest-service';
import {Category} from '../../core/rest-services/category/model/category'; import {Category} from '../../core/rest-services/category/model/category';
@@ -19,60 +20,68 @@ export interface DisplayableSubCategory {
providedIn: 'root' providedIn: 'root'
}) })
export class SideMenuService { export class SideMenuService {
readonly #categoryRestService = inject(CategoryRestService); private categoryRestService = inject(CategoryRestService);
readonly #snackBar = inject(MatSnackBar); private snackBar = inject(MatSnackBar);
#categories = signal<DisplayableCategory[]>([]); private categoriesSubject = new BehaviorSubject<DisplayableCategory[]>([]);
#isLoading = signal(false); private isLoadingSubject = new BehaviorSubject<boolean>(false);
isLoaded = signal(false); private isLoadedSubject = new BehaviorSubject<boolean>(false);
#mapToDisplayableCategory(category: Category): DisplayableCategory { private mapToDisplayableCategory(category: Category): DisplayableCategory {
return { return {
id: category.id, id: category.id,
name: category.name, name: category.name,
subCategories: category.subCategories.map(subCategory => this.#mapToDisplayableSubCategory(subCategory)), subCategories: category.subCategories.map(subCategory => this.mapToDisplayableSubCategory(subCategory)),
isOpenned: false isOpenned: false
}; };
} }
#mapToDisplayableSubCategory(subCategory: Category): DisplayableSubCategory { private mapToDisplayableSubCategory(subCategory: Category): DisplayableSubCategory {
return { return {
id: subCategory.id, id: subCategory.id,
name: subCategory.name name: subCategory.name
} }
} }
get categories(): Signal<DisplayableCategory[]> { private get categories(): DisplayableCategory[] {
return this.#categories.asReadonly(); return this.categoriesSubject.value;
} }
get isLoading(): Signal<boolean> { private save(categories: DisplayableCategory[]): void {
return this.#isLoading.asReadonly(); this.categoriesSubject.next(categories);
}
get categories$(): Observable<DisplayableCategory[]> {
return this.categoriesSubject.asObservable();
}
get isLoading$(): Observable<boolean> {
return this.isLoadingSubject.asObservable();
} }
loadCategories(): void { loadCategories(): void {
this.#isLoading.set(true); this.isLoadingSubject.next(true);
this.isLoaded.set(false); this.isLoadedSubject.next(false);
this.#categoryRestService.getCategories() this.categoryRestService.getCategories()
.then(categories => { .then(categories => {
const displayableCategories = categories const displayableCategories = categories
.filter(category => category.subCategories?.length) .filter(category => category.subCategories?.length)
.map(category => this.#mapToDisplayableCategory(category)); .map(category => this.mapToDisplayableCategory(category));
this.#categories.set(displayableCategories); this.categoriesSubject.next(displayableCategories);
}) })
.catch(error => { .catch(error => {
const errorMessage = $localize`An error occured while loading categories.`; const errorMessage = $localize`An error occured while loading categories.`;
console.error(errorMessage, error); console.error(errorMessage, error);
this.#snackBar.open(errorMessage, $localize`Close`, {duration: 5000}); this.snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
}) })
.finally(() => { .finally(() => {
this.#isLoading.set(false); this.isLoadingSubject.next(false);
this.isLoaded.set(true); this.isLoadedSubject.next(true);
}); });
} }
setOpened(category: DisplayableCategory): void { setOpenned(category: DisplayableCategory): void {
const categories = this.#categories(); const categories = this.categories;
const matchingCategory = categories.find(categoryTemp => categoryTemp.id === category.id); const matchingCategory = categories.find(categoryTemp => categoryTemp.id === category.id);
if (matchingCategory) { if (matchingCategory) {
const actualOpennedCategory = categories.find(category => category.isOpenned); const actualOpennedCategory = categories.find(category => category.isOpenned);
@@ -82,7 +91,7 @@ export class SideMenuService {
categories.forEach(categoryTemp => categoryTemp.isOpenned = false); categories.forEach(categoryTemp => categoryTemp.isOpenned = false);
matchingCategory.isOpenned = true; matchingCategory.isOpenned = true;
} }
this.#categories.set(categories); this.save(categories);
} }
} }
} }