Skip to content

Commit b12890d

Browse files
committed
fix my trajectory page
1 parent c0c15f0 commit b12890d

3 files changed

Lines changed: 18 additions & 13 deletions

File tree

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<!-- @format -->
22

33
<div class="list">
4-
@if (trajectoriesList().length) { @for(trajectory of trajectoriesList().slice(1, 3); track
5-
$index){
4+
@if (hasItems()) { @if (type() === 'all') { @for (trajectory of trajectoriesList().slice(1, 3);
5+
track $index) {
66
<app-trajectory [trajectory]="trajectory"></app-trajectory>
7+
} } @else if (type() === 'my') {
8+
<app-trajectory [trajectory]="userTrajectory()!"></app-trajectory>
79
} }
810
</div>

projects/skills/src/app/trajectories/track-career/list/list.component.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
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
}

projects/skills/src/app/trajectories/trajectories.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class TrajectoriesService {
5151
return this.apiService.get<Trajectory[]>(this.TRAJECTORY_URL).pipe(
5252
map(track => {
5353
const choosedTrajctory = track.find(trajectory => trajectory.isActiveForUser === true);
54-
return [choosedTrajctory];
54+
return choosedTrajctory;
5555
})
5656
);
5757
}

0 commit comments

Comments
 (0)