@@ -2,7 +2,7 @@ import * as React from "react";
22import "./CelComponent.css" ;
33
44import init , { cel_eval , cel_details , CelFloat } from "rscel" ;
5- import { useState } from "react" ;
5+ import { useState , useEffect } from "react" ;
66
77export default function CelComponent ( ) {
88 const [ isInit , setIsInit ] = useState < boolean > ( false ) ;
@@ -11,9 +11,11 @@ export default function CelComponent() {
1111 const [ params , setParams ] = useState < string [ ] > ( [ ] ) ;
1212 const [ paramVals , setParamVals ] = useState < any > ( { } ) ;
1313
14- init ( ) . then ( ( _res : any ) => {
15- setIsInit ( true ) ;
16- } ) ;
14+ useEffect ( ( ) => {
15+ init ( ) . then ( ( _res : any ) => {
16+ setIsInit ( true ) ;
17+ } ) ;
18+ } , [ ] ) ;
1719
1820 if ( ! isInit ) {
1921 return < div > Loading...</ div > ;
@@ -30,7 +32,9 @@ export default function CelComponent() {
3032 setParamVals ( ( old : any ) => {
3133 try {
3234 let newObj = { ...old } ;
33- newObj [ val ] = Number ( event . target . value ) ;
35+ const floatval = new CelFloat ( Number ( event . target . value ) ) ;
36+
37+ newObj [ val ] = floatval ;
3438 setErrorMessage ( "" ) ;
3539 return newObj ;
3640 } catch ( e ) {
@@ -58,21 +62,25 @@ export default function CelComponent() {
5862 < div style = { { display : "flex" , rowGap : "10px" , justifyContent : "right" } } >
5963 < button
6064 onClick = { ( ) => {
61- const details = cel_details ( prog ) ;
65+ const res = cel_details ( prog ) ;
6266
63- if ( details . success ) {
64- setParams ( details . result . get ( "params" ) ) ;
67+ if ( res . success ) {
68+ console . log ( res ) ;
69+ const details = res . result . get ( "details" ) ;
70+ setParams ( details . get ( "params" ) ) ;
6571 setErrorMessage ( "" ) ;
6672 } else {
67- setErrorMessage ( `${ details . error . kind } : ${ details . error . msg } ` ) ;
73+ setErrorMessage ( `${ res . error . kind } : ${ res . error . msg } ` ) ;
6874 }
6975 } }
7076 >
7177 Analyze
7278 </ button >
7379 < button
7480 onClick = { ( ) => {
81+ console . log ( paramVals ) ;
7582 const result = cel_eval ( prog , paramVals ) ;
83+ console . log ( result ) ;
7684
7785 if ( result . success ) {
7886 setErrorMessage ( `Result: ${ result . result . toString ( ) } ` ) ;
0 commit comments