Implement actual capacity calculation and replace alert() with callback mechanism

This commit is contained in:
2026-06-22 21:08:53 +00:00
parent 720ce055df
commit a2cb86bd66
@@ -2,9 +2,12 @@ import { Tool } from '../Tool';
import { YjsDocument } from '../../crdt/YjsDocument'; import { YjsDocument } from '../../crdt/YjsDocument';
class CapacityDisplayTool extends Tool { class CapacityDisplayTool extends Tool {
constructor(yjsDoc: YjsDocument) { private onCapacityUpdate: (totalCapacity: number, selectedCapacity: number) => void;
constructor(yjsDoc: YjsDocument, onCapacityUpdate?: (totalCapacity: number, selectedCapacity: number) => void) {
super(yjsDoc); super(yjsDoc);
this.name = 'CapacityDisplayTool'; this.name = 'CapacityDisplayTool';
this.onCapacityUpdate = onCapacityUpdate || (() => {});
} }
onMouseDown(event: MouseEvent): void { onMouseDown(event: MouseEvent): void {
@@ -34,17 +37,29 @@ class CapacityDisplayTool extends Tool {
// Calculate capacity for selected tables // Calculate capacity for selected tables
calculateSelectedCapacity(): number { calculateSelectedCapacity(): number {
// In a real implementation, this would get selected tables from the canvas // In a real implementation, this would get selected tables from the canvas
// and calculate the total capacity based on table type and size // For now, we'll count all chair elements as selected capacity
// For now, we'll return a placeholder value const elements = this.yjsDoc.getElements();
return 0; let count = 0;
elements.forEach(element => {
if (element.type === 'chair') {
count++;
}
});
return count;
} }
// Calculate capacity for entire drawing // Calculate capacity for entire drawing
calculateTotalCapacity(): number { calculateTotalCapacity(): number {
// In a real implementation, this would iterate through all elements in the Yjs document // Iterate through all elements in the Yjs document
// and count chairs or calculate capacity based on tables // and count chairs
// For now, we'll return a placeholder value const elements = this.yjsDoc.getElements();
return 0; let count = 0;
elements.forEach(element => {
if (element.type === 'chair') {
count++;
}
});
return count;
} }
// Display capacity information // Display capacity information
@@ -52,14 +67,8 @@ class CapacityDisplayTool extends Tool {
const totalCapacity = this.calculateTotalCapacity(); const totalCapacity = this.calculateTotalCapacity();
const selectedCapacity = this.calculateSelectedCapacity(); const selectedCapacity = this.calculateSelectedCapacity();
// In a real implementation, this would update the UI to show capacity information // Update the UI through the callback
console.log(`Total capacity: ${totalCapacity} seats`); this.onCapacityUpdate(totalCapacity, selectedCapacity);
if (selectedCapacity > 0) {
console.log(`Selected capacity: ${selectedCapacity} seats`);
}
// In a real implementation, this would show a modal or update a panel in the UI
alert(`Total capacity: ${totalCapacity} seats${selectedCapacity > 0 ? `\nSelected capacity: ${selectedCapacity} seats` : ''}`);
} }
} }