Simplify navigation event handling and week info rendering

Removes redundant period info update event and consolidates week information calculation

Streamlines navigation event flow by using navigation completed event for week info updates
Removes separate week info update method and moves calculation into renderer
Reduces complexity of event management and improves code efficiency
This commit is contained in:
Janus C. H. Knudsen 2025-11-13 21:33:53 +01:00
parent f0cc9bb6ce
commit 284c85b2f8
3 changed files with 19 additions and 28 deletions

View file

@ -1,6 +1,7 @@
import { IEventBus } from '../types/CalendarTypes';
import { CoreEvents } from '../constants/CoreEvents';
import { EventRenderingService } from './EventRendererManager';
import { DateService } from '../utils/DateService';
/**
* WeekInfoRenderer - Handles DOM rendering for week info display
@ -11,9 +12,15 @@ import { EventRenderingService } from './EventRendererManager';
export class WeekInfoRenderer {
private eventBus: IEventBus;
private dateService: DateService;
constructor(eventBus: IEventBus, eventRenderer: EventRenderingService) {
constructor(
eventBus: IEventBus,
eventRenderer: EventRenderingService,
dateService: DateService
) {
this.eventBus = eventBus;
this.dateService = dateService;
this.setupEventListeners();
}
@ -23,9 +30,15 @@ export class WeekInfoRenderer {
* Setup event listeners for DOM updates
*/
private setupEventListeners(): void {
this.eventBus.on(CoreEvents.PERIOD_INFO_UPDATE, (event: Event) => {
this.eventBus.on(CoreEvents.NAVIGATION_COMPLETED, (event: Event) => {
const customEvent = event as CustomEvent;
const { weekNumber, dateRange } = customEvent.detail;
const { newDate } = customEvent.detail;
// Calculate week number and date range from the new date
const weekNumber = this.dateService.getWeekNumber(newDate);
const weekEnd = this.dateService.addDays(newDate, 6);
const dateRange = this.dateService.formatDateRange(newDate, weekEnd);
this.updateWeekInfoInDOM(weekNumber, dateRange);
});
}