Adds logic to handle event overlaps in the calendar view. It introduces two patterns: column sharing for events with the same start time (rendered using flexbox) and stacking for events with a >30 min difference (rendered with reduced width and z-index). It also introduces deep linking to specific events via URL parameters.
86 lines
No EOL
2.6 KiB
TypeScript
86 lines
No EOL
2.6 KiB
TypeScript
import { EventBus } from '../core/EventBus';
|
|
import { IEventBus } from '../types/CalendarTypes';
|
|
|
|
/**
|
|
* URLManager handles URL query parameter parsing and deep linking functionality
|
|
* Follows event-driven architecture with no global state
|
|
*/
|
|
export class URLManager {
|
|
private eventBus: IEventBus;
|
|
|
|
constructor(eventBus: IEventBus) {
|
|
this.eventBus = eventBus;
|
|
}
|
|
|
|
/**
|
|
* Parse eventId from URL query parameters
|
|
* @returns eventId string or null if not found
|
|
*/
|
|
public parseEventIdFromURL(): string | null {
|
|
try {
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const eventId = urlParams.get('eventId');
|
|
|
|
if (eventId && eventId.trim() !== '') {
|
|
return eventId.trim();
|
|
}
|
|
|
|
return null;
|
|
} catch (error) {
|
|
console.warn('URLManager: Failed to parse URL parameters:', error);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get all query parameters as an object
|
|
* @returns object with all query parameters
|
|
*/
|
|
public getAllQueryParams(): Record<string, string> {
|
|
try {
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const params: Record<string, string> = {};
|
|
|
|
for (const [key, value] of urlParams.entries()) {
|
|
params[key] = value;
|
|
}
|
|
|
|
return params;
|
|
} catch (error) {
|
|
console.warn('URLManager: Failed to parse URL parameters:', error);
|
|
return {};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update URL without page reload (for future use)
|
|
* @param params object with parameters to update
|
|
*/
|
|
public updateURL(params: Record<string, string | null>): void {
|
|
try {
|
|
const url = new URL(window.location.href);
|
|
|
|
// Update or remove parameters
|
|
Object.entries(params).forEach(([key, value]) => {
|
|
if (value === null) {
|
|
url.searchParams.delete(key);
|
|
} else {
|
|
url.searchParams.set(key, value);
|
|
}
|
|
});
|
|
|
|
// Update URL without page reload
|
|
window.history.replaceState({}, '', url.toString());
|
|
} catch (error) {
|
|
console.warn('URLManager: Failed to update URL:', error);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if current URL has any query parameters
|
|
* @returns true if URL has query parameters
|
|
*/
|
|
public hasQueryParams(): boolean {
|
|
return window.location.search.length > 0;
|
|
}
|
|
} |