import React, { useState } from 'react'; import { useAppDispatch, useAppState } from '../state'; export function EventsPanel() { const dispatch = useAppDispatch(); const { design, selectedWidgetId, vscode } = useAppState(); const [eventType, setEventType] = useState('command'); const [eventName, setEventName] = useState('onClick'); const [eventCode, setEventCode] = useState('print("clicked")'); const w = design.widgets.find((x) => x.id === selectedWidgetId); const widgetEvents = (id: string | undefined) => (design.events || []).filter((e) => e.widget === id); const add = () => { if (!w) { vscode.postMessage({ type: 'showError', text: 'Select a widget to add events to', }); return; } if (!eventType || !eventName || !eventCode) { vscode.postMessage({ type: 'showError', text: 'Please fill in all fields: event type, name, and code', }); return; } dispatch({ type: 'addEvent', payload: { widget: w.id, type: eventType, name: eventName, code: eventCode, }, }); vscode.postMessage({ type: 'showInfo', text: `Event added: ${eventType} -> ${eventName}`, }); }; const remove = (type: string) => { if (!w) return; dispatch({ type: 'removeEvent', payload: { widget: w.id, type } }); vscode.postMessage({ type: 'showInfo', text: 'Event removed' }); }; return (

Events & Commands

{!w ? (

Select a widget to configure events

) : (
setEventType(e.target.value)} /> setEventName(e.target.value)} />