diff --git a/frontend/src/components/Editor/EditorComponents/Editor.tsx b/frontend/src/components/Editor/EditorComponents/Editor.tsx index 64fec42d..79fa2a76 100644 --- a/frontend/src/components/Editor/EditorComponents/Editor.tsx +++ b/frontend/src/components/Editor/EditorComponents/Editor.tsx @@ -144,13 +144,13 @@ const Editor: React.FC = (): ReactElement => { const fetchData = async () => { try { const response = await fetchWizardData(''); - const { wizardContractFilter, wizardMethods } = response; + const { wizardContractFilter, wizardMethods, wizardEvents } = response; if (wizardContractFilter === 'noFilter') { return; } - const codeResponse = await generateCode(wizardContractFilter, wizardMethods); + const codeResponse = await generateCode(wizardContractFilter, wizardMethods, wizardEvents); setIndexingCode(codeResponse.jsCode); setSchema(codeResponse.sqlCode); } catch (error: unknown) { diff --git a/frontend/src/components/Editor/EditorComponents/GenerateCode.tsx b/frontend/src/components/Editor/EditorComponents/GenerateCode.tsx deleted file mode 100644 index bf41fedb..00000000 --- a/frontend/src/components/Editor/EditorComponents/GenerateCode.tsx +++ /dev/null @@ -1,164 +0,0 @@ -//Dummy component -import { useState } from 'react'; - -type Schema = { - type: string; - properties?: Record; - required?: string[]; -}; - -type Method = { - method_name: string; - schema: Schema; -}; - -type Event = { - event_name: string; - schema: Schema; -}; - -const GenerateCode = () => { - const [contractFilter, setContractFilter] = useState(''); - const [selectedMethods, setSelectedMethods] = useState([]); - const [selectedEvents, setSelectedEvents] = useState([]); - const [generatedCode, setGeneratedCode] = useState<{ jsCode: string; sqlCode: string }>({ jsCode: '', sqlCode: '' }); - - const handleGenerateCode = async () => { - const response = await fetch('/api/generateCode', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ contractFilter, selectedMethods, selectedEvents }), - }); - const data = await response.json(); - setGeneratedCode(data); - }; - - const handleMethodChange = (index: number, field: keyof Method, value: string) => { - const updatedMethods = [...selectedMethods]; - if (field === 'schema') { - try { - updatedMethods[index] = { ...updatedMethods[index], schema: JSON.parse(value) }; - } catch (e) { - console.error('Invalid JSON format'); - } - } else { - updatedMethods[index] = { ...updatedMethods[index], [field]: value }; - } - setSelectedMethods(updatedMethods); - }; - - const handleEventChange = (index: number, field: keyof Event, value: string) => { - const updatedEvents = [...selectedEvents]; - if (field === 'schema') { - try { - updatedEvents[index] = { ...updatedEvents[index], schema: JSON.parse(value) }; - } catch (e) { - console.error('Invalid JSON format'); - } - } else { - updatedEvents[index] = { ...updatedEvents[index], [field]: value }; - } - setSelectedEvents(updatedEvents); - }; - - const addMethod = () => { - setSelectedMethods([...selectedMethods, { method_name: '', schema: { type: 'object' } }]); - }; - - const addEvent = () => { - setSelectedEvents([...selectedEvents, { event_name: '', schema: { type: 'object' } }]); - }; - - return ( -
-
-

Generate Code

- -
- setContractFilter(e.target.value)} - className="w-full p-3 border border-gray-300 rounded-md" - /> -
- -
-

Selected Methods

- {selectedMethods.map((method, index) => ( -
- handleMethodChange(index, 'method_name', e.target.value)} - className="w-full p-3 border border-gray-300 rounded-md mb-2" - /> -