44 type AfterViewInit ,
55 ChangeDetectorRef ,
66 Component ,
7+ computed ,
78 inject ,
89 type OnDestroy ,
910 type OnInit ,
@@ -37,6 +38,7 @@ export class TrajectoriesListComponent implements OnInit, AfterViewInit, OnDestr
3738
3839 totalItemsCount = signal ( 0 ) ;
3940 trajectoriesList = signal < Trajectory [ ] > ( [ ] ) ;
41+ userTrajectory = signal < Trajectory | undefined > ( undefined ) ;
4042 trajectoriesPage = signal ( 1 ) ;
4143 perFetchTake = signal ( 20 ) ;
4244
@@ -49,20 +51,17 @@ export class TrajectoriesListComponent implements OnInit, AfterViewInit, OnDestr
4951 * Определяет тип списка (all/my) и загружает начальные данные
5052 */
5153 ngOnInit ( ) : void {
52- this . type . set ( this . router . url . split ( "/" ) . slice ( - 1 ) [ 0 ] as "all" | "my" ) ;
54+ const currentType = this . router . url . split ( "/" ) . pop ( ) as "all" | "my" ;
55+ this . type . set ( currentType ) ;
5356
54- const routeData$ = this . route . data . pipe ( map ( r => r [ "data" ] ) ) ;
55-
56- const subscription = routeData$ . subscribe ( ( trajectories : Trajectory [ ] ) => {
57- if ( this . type ( ) === "all" ) {
58- this . trajectoriesList . set ( trajectories ) ;
59- this . totalItemsCount . set ( trajectories . length ) ;
57+ this . route . data . pipe ( map ( r => r [ "data" ] ) ) . subscribe ( data => {
58+ if ( currentType === "all" ) {
59+ this . trajectoriesList . set ( data as Trajectory [ ] ) ;
60+ this . totalItemsCount . set ( ( data as Trajectory [ ] ) . length ) ;
6061 } else {
61- this . trajectoriesList . set ( trajectories ) ;
62+ this . userTrajectory . set ( data as Trajectory ) ;
6263 }
6364 } ) ;
64-
65- this . subscriptions$ ( ) . push ( subscription ) ;
6665 }
6766
6867 /**
@@ -130,4 +129,8 @@ export class TrajectoriesListComponent implements OnInit, AfterViewInit, OnDestr
130129 map ( res => res )
131130 ) ;
132131 }
132+
133+ hasItems = computed ( ( ) => {
134+ return this . type ( ) === "all" ? this . trajectoriesList ( ) . length > 0 : ! ! this . userTrajectory ( ) ;
135+ } ) ;
133136}
0 commit comments