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:
parent
f0cc9bb6ce
commit
284c85b2f8
3 changed files with 19 additions and 28 deletions
|
|
@ -13,11 +13,10 @@ export const CoreEvents = {
|
||||||
VIEW_RENDERED: 'view:rendered',
|
VIEW_RENDERED: 'view:rendered',
|
||||||
WORKWEEK_CHANGED: 'workweek:changed',
|
WORKWEEK_CHANGED: 'workweek:changed',
|
||||||
|
|
||||||
// Navigation events (5)
|
// Navigation events (4)
|
||||||
NAV_BUTTON_CLICKED: 'nav:button-clicked',
|
NAV_BUTTON_CLICKED: 'nav:button-clicked',
|
||||||
DATE_CHANGED: 'nav:date-changed',
|
DATE_CHANGED: 'nav:date-changed',
|
||||||
NAVIGATION_COMPLETED: 'nav:navigation-completed',
|
NAVIGATION_COMPLETED: 'nav:navigation-completed',
|
||||||
PERIOD_INFO_UPDATE: 'nav:period-info-update',
|
|
||||||
NAVIGATE_TO_EVENT: 'nav:navigate-to-event',
|
NAVIGATE_TO_EVENT: 'nav:navigate-to-event',
|
||||||
|
|
||||||
// Data events (5)
|
// Data events (5)
|
||||||
|
|
|
||||||
|
|
@ -47,10 +47,6 @@ export class NavigationManager {
|
||||||
|
|
||||||
|
|
||||||
private setupEventListeners(): void {
|
private setupEventListeners(): void {
|
||||||
// Initial DOM update when calendar is initialized
|
|
||||||
this.eventBus.on(CoreEvents.INITIALIZED, () => {
|
|
||||||
this.updateWeekInfo();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Listen for filter changes and apply to pre-rendered grids
|
// Listen for filter changes and apply to pre-rendered grids
|
||||||
this.eventBus.on(CoreEvents.FILTER_CHANGED, (e: Event) => {
|
this.eventBus.on(CoreEvents.FILTER_CHANGED, (e: Event) => {
|
||||||
|
|
@ -239,29 +235,12 @@ export class NavigationManager {
|
||||||
this.currentWeek = new Date(this.targetWeek);
|
this.currentWeek = new Date(this.targetWeek);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update week info and notify other managers
|
// Emit navigation completed event
|
||||||
this.updateWeekInfo();
|
|
||||||
|
|
||||||
// Emit period change event for ScrollManager
|
|
||||||
this.eventBus.emit(CoreEvents.NAVIGATION_COMPLETED, {
|
this.eventBus.emit(CoreEvents.NAVIGATION_COMPLETED, {
|
||||||
direction,
|
direction,
|
||||||
currentDate: this.currentWeek
|
newDate: this.currentWeek
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateWeekInfo(): void {
|
|
||||||
const weekNumber = this.dateService.getWeekNumber(this.currentWeek);
|
|
||||||
const weekEnd = this.dateService.addDays(this.currentWeek, 6);
|
|
||||||
const dateRange = this.dateService.formatDateRange(this.currentWeek, weekEnd);
|
|
||||||
|
|
||||||
// Notify other managers about week info update - DOM manipulation should happen via events
|
|
||||||
this.eventBus.emit(CoreEvents.PERIOD_INFO_UPDATE, {
|
|
||||||
weekNumber,
|
|
||||||
dateRange,
|
|
||||||
weekStart: this.currentWeek,
|
|
||||||
weekEnd
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { IEventBus } from '../types/CalendarTypes';
|
import { IEventBus } from '../types/CalendarTypes';
|
||||||
import { CoreEvents } from '../constants/CoreEvents';
|
import { CoreEvents } from '../constants/CoreEvents';
|
||||||
import { EventRenderingService } from './EventRendererManager';
|
import { EventRenderingService } from './EventRendererManager';
|
||||||
|
import { DateService } from '../utils/DateService';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WeekInfoRenderer - Handles DOM rendering for week info display
|
* WeekInfoRenderer - Handles DOM rendering for week info display
|
||||||
|
|
@ -11,9 +12,15 @@ import { EventRenderingService } from './EventRendererManager';
|
||||||
|
|
||||||
export class WeekInfoRenderer {
|
export class WeekInfoRenderer {
|
||||||
private eventBus: IEventBus;
|
private eventBus: IEventBus;
|
||||||
|
private dateService: DateService;
|
||||||
|
|
||||||
constructor(eventBus: IEventBus, eventRenderer: EventRenderingService) {
|
constructor(
|
||||||
|
eventBus: IEventBus,
|
||||||
|
eventRenderer: EventRenderingService,
|
||||||
|
dateService: DateService
|
||||||
|
) {
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
|
this.dateService = dateService;
|
||||||
this.setupEventListeners();
|
this.setupEventListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -23,9 +30,15 @@ export class WeekInfoRenderer {
|
||||||
* Setup event listeners for DOM updates
|
* Setup event listeners for DOM updates
|
||||||
*/
|
*/
|
||||||
private setupEventListeners(): void {
|
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 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);
|
this.updateWeekInfoInDOM(weekNumber, dateRange);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue