diff --git a/src/app/(main)/editor/page.tsx b/src/app/(main)/editor/page.tsx index 8f8cb49..3602016 100644 --- a/src/app/(main)/editor/page.tsx +++ b/src/app/(main)/editor/page.tsx @@ -29,7 +29,7 @@ export default function EditorPage() { const { account } = useAccount(); const { compileCairo, compileContract, compileLoading, runCairo, runLoading, testLoading, runTests} = useCairoWasm(); - console.log(account, 'acc') + console.log(account, active, files, 'acc') useEffect(() => { @@ -126,9 +126,10 @@ export default function EditorPage() { ...files, { content: '', - name: 'new.cairo', + name: `new_${files.length}.cairo`, } ]); + setActive(files.length); } const updateFileByIndex = (index: number, value: string) => { @@ -143,14 +144,18 @@ export default function EditorPage() { const removeFile = (index: number) => { setFiles(files?.filter((item, i) => i !== index)); if(index===active) { - setActive(index-1); + const newIndex = active === 0 ? 0 : active - 1; + console.log('new', newIndex) + setActive(newIndex); + } else if(index < active) { + setActive(active - 1); } } const handleOpenFile = (e: any) => { - var file = e.target.files[0]; + const file = e.target.files[0]; if (file) { - var reader = new FileReader(); + const reader = new FileReader(); reader.onload = function(e) { updateFileByIndex(active, e.target?.result as string); } @@ -205,10 +210,15 @@ export default function EditorPage() { { files?.map((file, i) => { return ( -