diff --git a/src/app/app.config.ts b/src/app/app.config.ts index 95c08d2..2f45d0b 100644 --- a/src/app/app.config.ts +++ b/src/app/app.config.ts @@ -2,6 +2,7 @@ import { provideHttpClient } from '@angular/common/http'; import { ApplicationConfig, isDevMode, + LOCALE_ID, provideZoneChangeDetection, } from '@angular/core'; import { provideRouter } from '@angular/router'; @@ -13,6 +14,7 @@ export const appConfig: ApplicationConfig = { provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes), provideHttpClient(), + { provide: LOCALE_ID, useValue: 'fr-FR' }, provideServiceWorker('ngsw-worker.js', { enabled: !isDevMode(), registrationStrategy: 'registerWhenStable:30000', diff --git a/src/app/components/leaflet-map/leaflet-map.component.html b/src/app/components/leaflet-map/leaflet-map.component.html index 7429922..a3f5313 100644 --- a/src/app/components/leaflet-map/leaflet-map.component.html +++ b/src/app/components/leaflet-map/leaflet-map.component.html @@ -23,7 +23,7 @@ stroke-linecap="round" stroke-linejoin="round" stroke-width="2" - d="M9 5l7 7-7 7" + d="m15 19-7-7 7-7" /> @@ -56,7 +56,7 @@ + diff --git a/src/app/components/timeline/timeline.component.ts b/src/app/components/timeline/timeline.component.ts index cb54777..9f0544a 100644 --- a/src/app/components/timeline/timeline.component.ts +++ b/src/app/components/timeline/timeline.component.ts @@ -1,8 +1,12 @@ -import { CommonModule } from '@angular/common'; -import { Component, OnInit } from '@angular/core'; +import { CommonModule, ViewportScroller } from '@angular/common'; +import { Component, OnDestroy, OnInit } from '@angular/core'; import { DomSanitizer, SafeUrl } from '@angular/platform-browser'; +import { NavigationEnd, Router } from '@angular/router'; +import { Subscription } from 'rxjs'; +import { filter } from 'rxjs/operators'; import { Pin } from '../../model/Pin'; import { ImageService } from '../../services/image/image.service'; +import { ModalService } from '../../services/modal/modal.service'; import { PinService } from '../../services/pin/pin.service'; @Component({ @@ -11,7 +15,7 @@ import { PinService } from '../../services/pin/pin.service'; imports: [CommonModule], templateUrl: './timeline.component.html', }) -export class TimelineComponent implements OnInit { +export class TimelineComponent implements OnInit, OnDestroy { pins: Pin[] = []; imageUrls: SafeUrl[][] = []; loading = true; @@ -19,12 +23,52 @@ export class TimelineComponent implements OnInit { sortedYears: string[] = []; carouselIndexes: number[] = []; expandedDescriptions: { [index: number]: boolean } = {}; + private navigationSubscription: Subscription; constructor( private pinService: PinService, private imageService: ImageService, - private sanitizer: DomSanitizer - ) {} + private sanitizer: DomSanitizer, + private modalService: ModalService, + private router: Router, + private viewportScroller: ViewportScroller + ) { + // Écouter les événements de navigation + this.navigationSubscription = this.router.events + .pipe(filter((event) => event instanceof NavigationEnd)) + .subscribe(() => { + // Attendre que le contenu soit chargé + if (!this.loading) { + this.restoreScrollPosition(); + } + }); + } + + ngOnDestroy() { + // Nettoyer la souscription lors de la destruction du composant + if (this.navigationSubscription) { + this.navigationSubscription.unsubscribe(); + } + } + + private restoreScrollPosition() { + const scrollPosition = sessionStorage.getItem('timelineScrollPosition'); + if (scrollPosition) { + requestAnimationFrame(() => { + this.viewportScroller.scrollToPosition([0, parseInt(scrollPosition)]); + }); + } + } + + openPinModal() { + this.modalService.openModal('add-pin-modal'); + } + + navigateToPinOnMap(pinId: string) { + const scrollPosition = window.scrollY; + sessionStorage.setItem('timelineScrollPosition', scrollPosition.toString()); + this.router.navigate(['/map'], { queryParams: { pin: pinId } }); + } ngOnInit(): void { this.pinService.getPins().subscribe((pins: Pin[]) => { @@ -46,10 +90,11 @@ export class TimelineComponent implements OnInit { }); this.carouselIndexes = this.pins.map(() => 0); - this.loading = false; - this.groupPinsByYear(); + + // Restaurer la position de défilement après le chargement initial + this.restoreScrollPosition(); }); } @@ -69,7 +114,7 @@ export class TimelineComponent implements OnInit { this.groupedPins[year].sort((a, b) => a.date!.localeCompare(b.date!)); } - // Trie les années dans l’ordre croissant (utilisé dans le template) + // Trie les années dans l'ordre croissant (utilisé dans le template) this.sortedYears = Object.keys(this.groupedPins).sort((a, b) => +a - +b); } diff --git a/src/main.ts b/src/main.ts index 35b00f3..a5a1e49 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,11 @@ +import { registerLocaleData } from '@angular/common'; +import localeFr from '@angular/common/locales/fr'; import { bootstrapApplication } from '@angular/platform-browser'; -import { appConfig } from './app/app.config'; import { AppComponent } from './app/app.component'; +import { appConfig } from './app/app.config'; + +registerLocaleData(localeFr, 'fr'); -bootstrapApplication(AppComponent, appConfig) - .catch((err) => console.error(err)); +bootstrapApplication(AppComponent, appConfig).catch((err) => + console.error(err) +);