@@ -26,7 +26,7 @@ import {
2626 Validators ,
2727} from '@angular/forms' ;
2828import { MatProgressSpinnerModule } from '@angular/material/progress-spinner' ;
29- import { Book , FunctionResponse , FunctionSearch } from '../model/functions' ;
29+ import { Book , FunctionResponse , FunctionSearch , JsonResult } from '../model/functions' ;
3030import { FunctionSearchService } from '../service/function-search.service' ;
3131import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
3232import { Subscription , interval , map , tap } from 'rxjs' ;
@@ -71,6 +71,7 @@ export class FunctionSearchComponent {
7171 ) ;
7272 protected dataSource = new MatTreeNestedDataSource < TreeNode > ( ) ;
7373 protected responseText = '' ;
74+ protected responseJson = { author : "" , books : [ ] } as JsonResult ;
7475 protected resultFormats = [ 'text' , 'json' ] ;
7576 protected resultFormatControl = new FormControl ( this . resultFormats [ 0 ] ) ;
7677
@@ -110,9 +111,9 @@ export class FunctionSearchComponent {
110111 takeUntilDestroyed ( this . destroyRef ) ,
111112 tap ( ( ) => ( this . searching = false ) )
112113 )
113- . subscribe ( value => this . responseText = value . result ?? ''
114+ . subscribe ( value => this . resultFormatControl . value === this . resultFormats [ 0 ] ?
115+ this . responseText = value . result || '' : this . responseJson = value . jsonResult || this . responseJson
114116 ) ;
115- //.subscribe((value) => (this.dataSource.data = this.mapResult(value)));
116117 }
117118
118119 private mapResult ( functionResponse : FunctionResponse ) : TreeNode [ ] {
0 commit comments