@@ -20,12 +20,12 @@ import {
2020import {
2121 VisualLogState ,
2222 LogLineState ,
23- Example ,
2423 HoveredLineHint ,
2524 LoadStatus ,
2625 MainContent ,
2726 SelectedLineHint ,
2827 ToolTip ,
28+ Examples ,
2929} from "./components" ;
3030import { ParsedLineType } from "./parser" ;
3131
@@ -39,6 +39,14 @@ function getEmptyVisualLogState(): VisualLogState {
3939 } ;
4040}
4141
42+ function getEmptyLogLineState ( ) : LogLineState {
43+ return {
44+ memSlotId : "" ,
45+ line : 0 ,
46+ cLine : "" ,
47+ } ;
48+ }
49+
4250function getVisualLogState (
4351 verifierLogState : VerifierLogState ,
4452 fullLogView : boolean ,
@@ -118,18 +126,15 @@ function App() {
118126 const [ visualLogState , setVisualLogState ] = useState < VisualLogState > (
119127 getEmptyVisualLogState ( ) ,
120128 ) ;
121- const [ hoveredState , setHoveredState ] = useState < LogLineState > ( {
122- memSlotId : "" ,
123- line : - 1 ,
124- cLine : "" , // unused
125- } ) ;
126- const [ selectedState , setSelectedState ] = useState < LogLineState > ( {
127- memSlotId : "" ,
128- line : 0 ,
129- cLine : "" ,
130- } ) ;
129+ const [ hoveredState , setHoveredState ] = useState < LogLineState > (
130+ getEmptyLogLineState ( ) ,
131+ ) ;
132+ const [ selectedState , setSelectedState ] = useState < LogLineState > (
133+ getEmptyLogLineState ( ) ,
134+ ) ;
131135 const [ loadError , setLoadError ] = useState < string | null > ( null ) ;
132136 const [ fullLogView , setfullLogView ] = useState < boolean > ( false ) ;
137+ const [ isLoading , setIsLoading ] = useState < boolean > ( false ) ;
133138
134139 const fileInputRef = useRef < HTMLInputElement > ( null ) ;
135140
@@ -345,16 +350,40 @@ function App() {
345350 ( text : string ) => {
346351 const newVerifierLogState = processRawLines ( text . split ( "\n" ) ) ;
347352 setVisualLogState ( getVisualLogState ( newVerifierLogState , fullLogView ) ) ;
353+ setIsLoading ( false ) ;
348354 } ,
349355 [ fullLogView ] ,
350356 ) ;
351357
358+ const prepareNewLog = useCallback ( ( ) => {
359+ setSelectedState ( getEmptyLogLineState ( ) ) ;
360+ setIsLoading ( true ) ;
361+ } , [ ] ) ;
362+
352363 const handlePaste = useCallback (
353364 ( event : React . ClipboardEvent ) => {
365+ prepareNewLog ( ) ;
354366 const pastedText = event . clipboardData . getData ( "text" ) ;
355367 loadInputText ( pastedText ) ;
356368 } ,
357- [ loadInputText ] ,
369+ [ loadInputText , prepareNewLog ] ,
370+ ) ;
371+
372+ const handleLoadExample = useCallback (
373+ async ( exampleLink : string ) => {
374+ prepareNewLog ( ) ;
375+ try {
376+ const response = await fetch ( exampleLink ) ;
377+ if ( ! response . ok ) {
378+ throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
379+ }
380+ const result = await response . text ( ) ;
381+ loadInputText ( result ) ;
382+ } catch ( error ) {
383+ console . error ( "Error fetching data:" , error ) ;
384+ }
385+ } ,
386+ [ loadInputText , prepareNewLog ] ,
358387 ) ;
359388
360389 function getServerInjectedInputLink ( ) : string | null {
@@ -539,6 +568,7 @@ function App() {
539568
540569 const onFileInputChange = useCallback (
541570 async ( e : React . ChangeEvent < HTMLInputElement > ) => {
571+ prepareNewLog ( ) ;
542572 const files = ( e . target as HTMLInputElement ) . files ;
543573 if ( files ?. [ 0 ] ) {
544574 const fileBlob = files [ 0 ] ;
@@ -565,6 +595,7 @@ function App() {
565595 }
566596 const newVerifierLogState = processRawLines ( rawLines ) ;
567597 setVisualLogState ( getVisualLogState ( newVerifierLogState , fullLogView ) ) ;
598+ setIsLoading ( false ) ;
568599 }
569600 } ,
570601 [ ] ,
@@ -606,7 +637,7 @@ function App() {
606637 ref = { fileInputRef }
607638 />
608639 </ div >
609- < Example />
640+ < Examples handleLoadExample = { handleLoadExample } />
610641 < a
611642 href = "https://github.com/theihor/bpfvv/blob/master/HOWTO.md"
612643 className = "howto-link"
@@ -652,6 +683,13 @@ function App() {
652683 hoveredMemSlotId = { hoveredState . memSlotId }
653684 />
654685 ) }
686+ { isLoading && (
687+ < div className = "loader-container" >
688+ < div className = "loader-content" >
689+ < div className = "loader" > </ div >
690+ </ div >
691+ </ div >
692+ ) }
655693 </ div >
656694 ) ;
657695}
0 commit comments