@@ -72,32 +72,28 @@ export class CategoriesFilterComponent implements OnInit, OnDestroy {
7272 console . log ( 'selected categories' )
7373 console . log ( this . selected )
7474 if ( this . catalogId != undefined ) {
75- this . api . getCatalog ( this . catalogId ) . then ( data => {
76- if ( data . category ) {
77- for ( let i = 0 ; i < data . category . length ; i ++ ) {
78- this . api . getCategoryById ( data . category [ i ] . id ) . then ( categoryInfo => {
79- this . findChildrenByParent ( categoryInfo ) ;
80- } )
75+ let data = await this . api . getCatalog ( this . catalogId ) ;
76+ if ( data . category ) {
77+ for ( let i = 0 ; i < data . category . length ; i ++ ) {
78+ let categoryInfo = await this . api . getCategoryById ( data . category [ i ] . id )
79+ await this . findChildrenByParent ( categoryInfo ) ;
80+ }
81+ initFlowbite ( ) ;
82+ } else {
83+ let launched = await this . api . getLaunchedCategories ( )
84+ for ( let i = 0 ; i < launched . length ; i ++ ) {
85+ this . findChildren ( launched [ i ] , launched )
8186 }
87+ this . cdr . detectChanges ( ) ;
8288 initFlowbite ( ) ;
83- } else {
84- this . api . getLaunchedCategories ( ) . then ( data => {
85- for ( let i = 0 ; i < data . length ; i ++ ) {
86- this . findChildren ( data [ i ] , data )
87- }
88- this . cdr . detectChanges ( ) ;
89- initFlowbite ( ) ;
90- } )
91- }
92- } )
89+ }
9390 } else {
94- await this . api . getLaunchedCategories ( ) . then ( data => {
95- for ( let i = 0 ; i < data . length ; i ++ ) {
96- this . findChildren ( data [ i ] , data )
97- }
98- this . cdr . detectChanges ( ) ;
99- initFlowbite ( ) ;
100- } )
91+ let data = await this . api . getLaunchedCategories ( )
92+ for ( let i = 0 ; i < data . length ; i ++ ) {
93+ this . findChildren ( data [ i ] , data )
94+ }
95+ this . cdr . detectChanges ( ) ;
96+ initFlowbite ( ) ;
10197 }
10298 }
10399
@@ -125,9 +121,9 @@ export class CategoriesFilterComponent implements OnInit, OnDestroy {
125121 }
126122 }
127123
128- findChildrenByParent ( parent :any ) {
124+ async findChildrenByParent ( parent :any ) {
129125 let childs : any [ ] = [ ]
130- this . api . getCategoriesByParentId ( parent . id ) . then ( c => {
126+ let c = await this . api . getCategoriesByParentId ( parent . id )
131127 childs = c ;
132128 parent [ "children" ] = childs ;
133129 if ( parent . isRoot == true ) {
@@ -137,11 +133,10 @@ export class CategoriesFilterComponent implements OnInit, OnDestroy {
137133 }
138134 if ( childs . length != 0 ) {
139135 for ( let i = 0 ; i < childs . length ; i ++ ) {
140- this . findChildrenByParent ( childs [ i ] )
136+ await this . findChildrenByParent ( childs [ i ] )
141137 }
142138 }
143139 initFlowbite ( ) ;
144- } )
145140
146141 }
147142
0 commit comments