@@ -10,53 +10,54 @@ import { Alert, AlertDescription } from "@/components/ui/alert";
10
10
import { Loader2 , Plus , Trash2 , Code2 , Clock , Box , PlayCircle , Brain , Lightbulb , ExternalLink } from "lucide-react" ;
11
11
import { motion , AnimatePresence } from "framer-motion" ;
12
12
import dynamic from 'next/dynamic' ;
13
+ import VisualizationTab from '@/components/MermaidRenderer' ;
13
14
14
15
const CodeEditor = dynamic ( ( ) => import ( '../components/Editor' ) , { ssr : false } ) ;
15
- // const DEFAULT_SOLUTION_CODE = `/**
16
- // * Solution for the DSA problem
17
- // * @param {any } input - The input parameter(s) for the problem
18
- // * @returns {any } - The result of the solution
19
- // */
20
- // function solution(input) {
21
- // // Initialize variables
22
- // let result;
16
+ const DEFAULT_SOLUTION_CODE = `/**
17
+ * Solution for the DSA problem
18
+ * @param {any} input - The input parameter(s) for the problem
19
+ * @returns {any} - The result of the solution
20
+ */
21
+ function solution(input) {
22
+ // Initialize variables
23
+ let result;
23
24
24
- // // Solution implementation
25
- // try {
26
- // // Your solution logic here
25
+ // Solution implementation
26
+ try {
27
+ // Your solution logic here
27
28
28
- // // Example implementation
29
- // if (Array.isArray(input)) {
30
- // result = input.reduce((acc, curr) => acc + curr, 0);
31
- // } else {
32
- // result = input;
33
- // }
34
- // } catch (error) {
35
- // console.error('Error in solution:', error);
36
- // throw error;
37
- // }
29
+ // Example implementation
30
+ if (Array.isArray(input)) {
31
+ result = input.reduce((acc, curr) => acc + curr, 0);
32
+ } else {
33
+ result = input;
34
+ }
35
+ } catch (error) {
36
+ console.error('Error in solution:', error);
37
+ throw error;
38
+ }
38
39
39
- // return result;
40
- // }
40
+ return result;
41
+ }
41
42
42
- // // Example test cases
43
- // const testCases = [
44
- // { input: [1, 2, 3, 4, 5], expectedOutput: 15 },
45
- // { input: [], expectedOutput: 0 },
46
- // { input: [42], expectedOutput: 42 }
47
- // ];
43
+ // Example test cases
44
+ const testCases = [
45
+ { input: [1, 2, 3, 4, 5], expectedOutput: 15 },
46
+ { input: [], expectedOutput: 0 },
47
+ { input: [42], expectedOutput: 42 }
48
+ ];
48
49
49
- // // Run test cases
50
- // testCases.forEach((testCase, index) => {
51
- // const output = solution(testCase.input);
52
- // console.log(\`Test case \${index + 1}:\`);
53
- // console.log('Input:', testCase.input);
54
- // console.log('Expected:', testCase.expectedOutput);
55
- // console.log('Actual:', output);
56
- // console.log('Pass:', output === testCase.expectedOutput);
57
- // console.log('---');
58
- // });
59
- // `;
50
+ // Run test cases
51
+ testCases.forEach((testCase, index) => {
52
+ const output = solution(testCase.input);
53
+ console.log(\`Test case \${index + 1}:\`);
54
+ console.log('Input:', testCase.input);
55
+ console.log('Expected:', testCase.expectedOutput);
56
+ console.log('Actual:', output);
57
+ console.log('Pass:', output === testCase.expectedOutput);
58
+ console.log('---');
59
+ });
60
+ ` ;
60
61
61
62
62
63
const DSASolutionInterface = ( ) => {
@@ -68,7 +69,7 @@ const DSASolutionInterface = () => {
68
69
visualization ?: string ;
69
70
}
70
71
const [ showEditor , setShowEditor ] = useState ( false ) ;
71
- const [ editorCode , setEditorCode ] = useState ( '' ) ;
72
+ const [ editorCode , setEditorCode ] = useState ( DEFAULT_SOLUTION_CODE ) ;
72
73
73
74
const handleOpenEditor = ( ) => {
74
75
if ( solution ?. code ) {
@@ -90,7 +91,7 @@ const DSASolutionInterface = () => {
90
91
const steps = [
91
92
{ title : "Problem" , icon : Brain } ,
92
93
{ title : "Test Cases" , icon : PlayCircle } ,
93
- { title : "Analysis " , icon : Lightbulb } ,
94
+ { title : "Expected Complexity " , icon : Lightbulb } ,
94
95
] ;
95
96
96
97
const handleAddTestCase = ( ) => {
@@ -110,38 +111,47 @@ const DSASolutionInterface = () => {
110
111
const handleSubmit = async ( ) => {
111
112
setLoading ( true ) ;
112
113
try {
113
- // // Placeholder for API call
114
- // const response = await new Promise<{
115
- // explanation: string;
116
- // diagram: string;
117
- // code: string;
118
- // timeComplexity: string;
119
- // spaceComplexity: string;
120
- // }>(resolve =>
121
- // setTimeout(() => resolve({
122
- // explanation: "Example explanation of the solution...",
123
- // diagram : "graph TD\nA[Start] --> B[Process]\nB --> C[End] ",
124
- // code: DEFAULT_SOLUTION_CODE ,
125
- // timeComplexity: "O(n)" ,
126
- // spaceComplexity : "O(1)"
127
- // }), 1500)
128
- // );
129
- // const data = response;
130
- // setSolution(data);
131
- // setTimeComplexity(response.timeComplexity);
132
- // setSpaceComplexity(response.spaceComplexity );
133
- // setEditorCode(response.code);
134
- const response = await fetch ( '/api/copilotkit' , {
135
- method : 'POST' ,
136
- headers : { 'Content-Type' : 'application/json' } ,
137
- body : JSON . stringify ( { "question" : question , "testCases" : testCases } )
114
+ // Placeholder for API call
115
+ const response = await new Promise < {
116
+ explanation : string ;
117
+ diagram : string ;
118
+ code : string ;
119
+ timeComplexity : string ;
120
+ spaceComplexity : string ;
121
+ visualization : string ;
122
+ } > ( resolve =>
123
+ setTimeout ( ( ) => resolve ( {
124
+ explanation : "Example explanation of the solution... " ,
125
+ diagram : "graph TD\nA[Start] --> B[Process]\nB --> C[End]" ,
126
+ code : DEFAULT_SOLUTION_CODE ,
127
+ timeComplexity : "O(n)" ,
128
+ spaceComplexity : "O(1)" ,
129
+ visualization : "graph TD\nA[Start] --> B[Process]\nB --> C[End]"
130
+
131
+
132
+ } ) , 1500 )
133
+ ) ;
134
+
135
+ setSolution ( {
136
+ code : response . code ,
137
+ explanation : response . explanation ,
138
+ visualization : response . diagram
138
139
} ) ;
139
- console . log ( response ) ;
140
- const data = await response . json ( ) ;
141
- setSolution ( data ) ;
142
- setTimeComplexity ( data . timeComplexity ) ;
143
- setSpaceComplexity ( data . spaceComplexity ) ;
144
- setEditorCode ( data . code ) ;
140
+ setTimeComplexity ( response . timeComplexity ) ;
141
+ setSpaceComplexity ( response . spaceComplexity ) ;
142
+ setEditorCode ( response . code ) ;
143
+ // const response = await fetch('/copilotkit', {
144
+ // method: 'POST',
145
+ // headers: { 'Content-Type': 'application/json' },
146
+ // body: JSON.stringify({ "question": question, "testCases" :testCases })
147
+ // });
148
+
149
+
150
+ // const data = await response.json();
151
+ // setSolution(data);
152
+ // setTimeComplexity(data.timeComplexity);
153
+ // setSpaceComplexity(data.spaceComplexity);
154
+ // setEditorCode(data.code);
145
155
146
156
} catch ( error ) {
147
157
console . error ( 'Error:' , error ) ;
@@ -160,7 +170,7 @@ const DSASolutionInterface = () => {
160
170
className = "mb-8"
161
171
>
162
172
< div className = "flex justify-between items-center mb-6" >
163
- < h1 className = "text-3xl font-bold text-gray-800" > DSA Problem Solver </ h1 >
173
+ < h1 className = "text-3xl font-bold text-gray-800 mt-5" > Self Study with Copilotkit </ h1 >
164
174
< div className = "flex gap-2" >
165
175
{ steps . map ( ( step , index ) => (
166
176
< Button
@@ -295,26 +305,26 @@ const DSASolutionInterface = () => {
295
305
</ Button >
296
306
</ div >
297
307
298
- < Tabs defaultValue = "explanation " className = "space-y-4" >
308
+ < Tabs defaultValue = "code " className = "space-y-4" >
299
309
< TabsList className = "grid w-full grid-cols-4" >
310
+ < TabsTrigger value = "code" >
311
+ < Code2 className = "h-4 w-4 mr-2" /> Code
312
+ </ TabsTrigger >
300
313
< TabsTrigger value = "explanation" >
301
- < Code2 className = "h-4 w-4 mr-2" /> Solution
314
+ < Clock className = "h-4 w-4 mr-2" /> Explanation
302
315
</ TabsTrigger >
303
316
< TabsTrigger value = "complexity" >
304
- < Clock className = "h-4 w-4 mr-2" /> Complexity
317
+ < Box className = "h-4 w-4 mr-2" /> Obtained Complexity
305
318
</ TabsTrigger >
306
319
< TabsTrigger value = "visualization" >
307
- < Box className = "h-4 w-4 mr-2" /> Visualization
308
- </ TabsTrigger >
309
- < TabsTrigger value = "test" >
310
- < PlayCircle className = "h-4 w-4 mr-2" /> Test Cases
320
+ < PlayCircle className = "h-4 w-4 mr-2" /> Visualization
311
321
</ TabsTrigger >
312
322
</ TabsList >
313
323
314
- < TabsContent value = "explanation " >
324
+ < TabsContent value = "code " >
315
325
< Card >
316
326
< CardHeader >
317
- < CardTitle > Solution Explanation </ CardTitle >
327
+ < CardTitle > Code in Python [officially supported till now] </ CardTitle >
318
328
</ CardHeader >
319
329
< CardContent >
320
330
< div className = "space-y-4" >
@@ -361,16 +371,14 @@ const DSASolutionInterface = () => {
361
371
< CardContent >
362
372
< div className = "border p-4 rounded-lg bg-gray-50" >
363
373
{ solution . visualization && (
364
- < pre className = "text-sm whitespace-pre-wrap overflow-x-auto" >
365
- { solution . visualization }
366
- </ pre >
374
+ < VisualizationTab visualization = { solution . visualization } />
367
375
) }
368
376
</ div >
369
377
</ CardContent >
370
378
</ Card >
371
379
</ TabsContent >
372
380
373
- < TabsContent value = "test " >
381
+ < TabsContent value = "explanation " >
374
382
< Card >
375
383
< CardHeader >
376
384
< CardTitle > Test Cases</ CardTitle >
0 commit comments