@@ -24,9 +24,19 @@ function parseStoredString(responseString: string): string | any[] | object {
2424export function Evaluate ( ) {
2525 const [ response , updateResponse ] = useState < string > ( "" ) ;
2626 const [ args , updateArgs , resetArgs ] = useArgs ( ) ;
27+
2728 async function evaluate ( url : string , params : JSON ) {
28- const answer = parseStoredString ( JSON . stringify ( JSON . parse ( localStorage . getItem ( "wizard.input" ) ) . answer ) ) ;
29- const response = parseStoredString ( localStorage . getItem ( "student.input" ) ) ;
29+ // Check if sessionStorage items exist before parsing
30+ const wizardInput = sessionStorage . getItem ( "wizard.input" ) ;
31+ const studentInput = sessionStorage . getItem ( "student.input" ) ;
32+
33+ // Safely parse the wizard input if it exists, otherwise use a fallback value
34+ const answer = wizardInput
35+ ? parseStoredString ( JSON . stringify ( JSON . parse ( wizardInput ) . answer ) )
36+ : { defaultAnswer : '' } ; // Fallback value if wizard.input is null
37+
38+ // Safely parse the student input if it exists, otherwise use a fallback value
39+ const response = studentInput ? parseStoredString ( studentInput ) : { defaultResponse : '' } ; // Fallback value if student.input is null
3040
3141 console . log ( "remote eval" ) ;
3242 console . log ( "url" , url ) ;
@@ -44,14 +54,18 @@ export function Evaluate() {
4454 const res = await axios . post ( "http://localhost:3070" , request ) ;
4555 console . log ( res ) ;
4656 updateResponse ( JSON . stringify ( res . data ) ) ;
47- const feedback = { isCorrect : res . data . result . is_correct ,
48- isError : res . data . result . is_error ?? false ,
49- feedback : res . data . result . feedback
50- ?? ( res . data . result . is_correct ? "Correct" : "Incorrect" ) ,
51- color : res . data . result . is_correct ? 'green' :'red' } ;
52- updateArgs ( { feedback : feedback } ) ;
53- // {homes.map(home => <div>{home.name}</div>) }
57+
58+ const feedback = {
59+ isCorrect : res . data . result . is_correct ,
60+ isError : res . data . result . is_error ?? false ,
61+ feedback :
62+ res . data . result . feedback ??
63+ ( res . data . result . is_correct ? "Correct" : "Incorrect" ) ,
64+ color : res . data . result . is_correct ? "green" : "red" ,
65+ } ;
66+ updateArgs ( { feedback : feedback } ) ;
5467 }
68+
5569 return (
5670 < div style = { evaluateStyles . mainDiv } >
5771 < div style = { { width : "100%" , display : "table" } } >
0 commit comments