@@ -25,14 +25,7 @@ import { SUPPORTED_LANGUAGES } from '@/constants/language';
2525import { CodeEditor } from './_components/code-editor' ;
2626import { OutputViewer } from './_components/output-viewer' ;
2727import { executeCodeAction } from './_actions/execute' ;
28- import { Language } from '@/@types' ;
29-
30- interface ExecutionResult {
31- status : 'success' | 'error' | 'running' ;
32- output : string ;
33- executionTime : number ;
34- language : string ;
35- }
28+ import { ExecutionResult , Language } from '@/@types' ;
3629
3730export default function ExecuteMePlatform ( ) {
3831 const [ selectedLanguage , setSelectedLanguage ] = useState < Language > ( 'python' ) ;
@@ -42,28 +35,6 @@ export default function ExecuteMePlatform() {
4235 useState < ExecutionResult | null > ( null ) ;
4336 const [ isExecuting , setIsExecuting ] = useState ( false ) ;
4437
45- const handleFileUpload = ( event : React . ChangeEvent < HTMLInputElement > ) => {
46- const file = event . target . files ?. [ 0 ] ;
47- if ( file ) {
48- setUploadedFile ( file ) ;
49- const reader = new FileReader ( ) ;
50- reader . onload = ( e ) => {
51- const content = e . target ?. result as string ;
52- setCode ( content ) ;
53- } ;
54- reader . readAsText ( file ) ;
55-
56- // Auto-detect language from file extension
57- const extension = file . name . split ( '.' ) . pop ( ) ;
58- const detectedLanguage = SUPPORTED_LANGUAGES . find (
59- ( lang ) => lang . extension === `.${ extension } `
60- ) ;
61- if ( detectedLanguage ) {
62- setSelectedLanguage ( detectedLanguage . value as Language ) ;
63- }
64- }
65- } ;
66-
6738 const executeCode = async ( ) => {
6839 if ( ! code . trim ( ) ) {
6940 return ;
@@ -99,26 +70,6 @@ export default function ExecuteMePlatform() {
9970 }
10071 } ;
10172
102- const copyOutput = ( ) => {
103- if ( executionResult ?. output ) {
104- navigator . clipboard . writeText ( executionResult . output ) ;
105- }
106- } ;
107-
108- const downloadOutput = ( ) => {
109- if ( executionResult ?. output ) {
110- const blob = new Blob ( [ executionResult . output ] , { type : 'text/plain' } ) ;
111- const url = URL . createObjectURL ( blob ) ;
112- const a = document . createElement ( 'a' ) ;
113- a . href = url ;
114- a . download = `output_${ Date . now ( ) } .txt` ;
115- document . body . appendChild ( a ) ;
116- a . click ( ) ;
117- document . body . removeChild ( a ) ;
118- URL . revokeObjectURL ( url ) ;
119- }
120- } ;
121-
12273 return (
12374 < div className = "min-h-screen bg-gradient-to-br from-slate-50 to-slate-100 p-4" >
12475 < div className = "max-w-7xl mx-auto" >
@@ -143,21 +94,18 @@ export default function ExecuteMePlatform() {
14394 < div className = "grid lg:grid-cols-2 gap-6" >
14495 { /* Code Input Section */ }
14596 < Card className = "h-fit" >
146- < CardHeader >
147- < CardTitle className = "flex items-center gap-2" >
148- < Code2 className = "w-5 h-5" / >
149- Code Editor
150- </ CardTitle >
151- < CardDescription >
152- Write or upload your code with full syntax highlighting
153- </ CardDescription >
154- </ CardHeader >
155- < CardContent className = "space-y-4" >
97+ < CardHeader className = "flex justify-between" >
98+ < div >
99+ < CardTitle className = "flex items-center gap-2" >
100+ < Code2 className = "w-5 h-5" />
101+ Code Editor
102+ </ CardTitle >
103+ < CardDescription >
104+ Write or upload your code with full syntax highlighting
105+ </ CardDescription >
106+ </ div >
156107 { /* Language Selection */ }
157108 < div className = "space-y-2" >
158- < label className = "text-sm font-medium" >
159- Programming Language
160- </ label >
161109 < Select
162110 value = { selectedLanguage }
163111 onValueChange = { ( e ) => setSelectedLanguage ( e as Language ) }
@@ -174,71 +122,14 @@ export default function ExecuteMePlatform() {
174122 </ SelectContent >
175123 </ Select >
176124 </ div >
177-
178- < Tabs defaultValue = "editor" className = "w-full" >
179- < TabsList className = "grid w-full grid-cols-2" >
180- < TabsTrigger value = "editor" > Code Editor</ TabsTrigger >
181- < TabsTrigger value = "upload" > Upload File</ TabsTrigger >
182- </ TabsList >
183-
184- < TabsContent value = "editor" className = "space-y-4" >
185- < CodeEditor
186- value = { code }
187- onChange = { setCode }
188- language = { selectedLanguage }
189- height = "500px"
190- />
191- </ TabsContent >
192-
193- < TabsContent value = "upload" className = "space-y-4" >
194- < div className = "border-2 border-dashed border-slate-300 rounded-lg p-8 text-center hover:border-slate-400 transition-colors" >
195- < Upload className = "w-12 h-12 text-slate-400 mx-auto mb-4" />
196- < div className = "space-y-2" >
197- < p className = "text-sm text-slate-600" >
198- Drop your code file here or click to browse
199- </ p >
200- < input
201- type = "file"
202- onChange = { handleFileUpload }
203- accept = { SUPPORTED_LANGUAGES . map (
204- ( l ) => l . extension
205- ) . join ( ',' ) }
206- className = "hidden"
207- id = "file-upload"
208- />
209- < Button
210- variant = "outline"
211- onClick = { ( ) =>
212- document . getElementById ( 'file-upload' ) ?. click ( )
213- }
214- >
215- Choose File
216- </ Button >
217- </ div >
218- </ div >
219-
220- { uploadedFile && (
221- < div className = "flex items-center gap-2 p-3 bg-slate-50 rounded-lg" >
222- < FileText className = "w-4 h-4 text-slate-500" />
223- < span className = "text-sm font-medium" >
224- { uploadedFile . name }
225- </ span >
226- < Badge variant = "secondary" className = "text-xs" >
227- { ( uploadedFile . size / 1024 ) . toFixed ( 1 ) } KB
228- </ Badge >
229- </ div >
230- ) }
231-
232- { code && (
233- < CodeEditor
234- value = { code }
235- onChange = { setCode }
236- language = { selectedLanguage }
237- height = "400px"
238- />
239- ) }
240- </ TabsContent >
241- </ Tabs >
125+ </ CardHeader >
126+ < CardContent className = "space-y-4" >
127+ < CodeEditor
128+ value = { code }
129+ onChange = { setCode }
130+ language = { selectedLanguage }
131+ height = "300px"
132+ />
242133
243134 < Button
244135 onClick = { executeCode }
0 commit comments