Skip to content

Commit 21d830f

Browse files
committed
fix current lesson & meta text, move logic from components to services facade
1 parent 3c89764 commit 21d830f

11 files changed

Lines changed: 71 additions & 44 deletions

File tree

projects/social_platform/src/app/api/courses/facades/lesson-info.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ActivatedRoute, NavigationEnd, Router } from "@angular/router";
55
import { filter, map, Subject, takeUntil } from "rxjs";
66
import { CourseLesson, Task } from "@domain/courses/courses.model";
77
import { LessonUIInfoService } from "./ui/lesson-ui-info.service";
8+
import { CourseDetailUIInfoService } from "./ui/course-detail-ui-info.service";
89
import { SubmitTaskAnswerUseCase } from "../use-cases/submit-task-answer.use-case";
910
import { SnackbarService } from "@ui/services/snackbar/snackbar.service";
1011
import { failure, loading, success } from "@domain/shared/async-state";
@@ -16,6 +17,7 @@ export class LessonInfoService {
1617
private readonly submitTaskAnswerUseCase = inject(SubmitTaskAnswerUseCase);
1718
private readonly snackbarService = inject(SnackbarService);
1819
private readonly lessonUIInfoService = inject(LessonUIInfoService);
20+
private readonly courseDetailUIInfoService = inject(CourseDetailUIInfoService);
1921

2022
private readonly destroy$ = new Subject<void>();
2123

@@ -25,6 +27,7 @@ export class LessonInfoService {
2527
}
2628

2729
destroy(): void {
30+
this.courseDetailUIInfoService.currentLesson.set(undefined);
2831
this.destroy$.next();
2932
this.destroy$.complete();
3033
}
@@ -127,6 +130,7 @@ export class LessonInfoService {
127130
next: lessonInfo => {
128131
this.lessonUIInfoService.loading.set(true);
129132
this.lessonUIInfoService.lesson$.set(success(lessonInfo));
133+
this.courseDetailUIInfoService.currentLesson.set(lessonInfo);
130134

131135
if (lessonInfo.progressStatus === "completed") {
132136
setTimeout(() => {

projects/social_platform/src/app/api/courses/facades/ui/course-detail-ui-info.service.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @format */
22

33
import { computed, inject, Injectable, signal } from "@angular/core";
4-
import { CourseDetail, CourseStructure } from "@domain/courses/courses.model";
4+
import { CourseDetail, CourseLesson, CourseStructure } from "@domain/courses/courses.model";
55
import { AsyncState, initial, isLoading, isSuccess } from "@domain/shared/async-state";
66
import { SeenModulesStoragePort } from "@domain/courses/ports/seen-modules-storage.port";
77

@@ -12,6 +12,20 @@ export class CourseDetailUIInfoService {
1212
readonly courseDetail$ = signal<AsyncState<CourseDetail>>(initial());
1313
readonly courseStructure$ = signal<AsyncState<CourseStructure>>(initial());
1414

15+
readonly currentLesson = signal<CourseLesson | undefined>(undefined);
16+
17+
readonly currentLessonOrder = computed<number | null>(() => {
18+
const lesson = this.currentLesson();
19+
const structure = this.courseStructure();
20+
if (!lesson || !structure) return null;
21+
22+
for (const mod of structure.modules) {
23+
const found = mod.lessons.find(l => l.id === lesson.id);
24+
if (found) return found.order;
25+
}
26+
return null;
27+
});
28+
1529
readonly loading = computed(() => {
1630
const detail = this.courseDetail$();
1731
const structure = this.courseStructure$();

projects/social_platform/src/app/api/program/facades/detail/ui/program-detail-main-ui-info.service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @format */
22

3-
import { Injectable, signal } from "@angular/core";
3+
import { computed, Injectable, signal } from "@angular/core";
44
import { ApiPagination } from "@domain/other/api-pagination.model";
55
import { Program } from "@domain/program/program.model";
66
import { FeedNews } from "@domain/project/project-news.model";
@@ -10,6 +10,14 @@ export class ProgramDetailMainUIInfoService {
1010
readonly program = signal<Program | undefined>(undefined);
1111
readonly programId = signal<number | undefined>(undefined);
1212

13+
readonly contactLinks = computed<{ label: string; url: string }[]>(() =>
14+
(this.program()?.links ?? []).map(link => ({ label: link, url: link }))
15+
);
16+
17+
readonly materialLinks = computed<{ label: string; url: string }[]>(() =>
18+
(this.program()?.materials ?? []).map(m => ({ label: m.title, url: m.url }))
19+
);
20+
1321
readonly totalNewsCount = signal(0);
1422

1523
// Сигналы для работы с модальными окнами с текстом

projects/social_platform/src/app/ui/pages/courses/detail/course-detail.component.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ <h1 class="info__title text-body-12">
3535
назад
3636
</app-button>
3737

38-
<!-- <div class="task__meta">
39-
@if (lessonInfo()) {
40-
<p class="text-body-14">модуль {{ lessonInfo()!.moduleOrder }}</p>
41-
<p class="task__lesson text-body-12">урок {{ lessonOrder() }}</p>
42-
}
43-
</div> -->
38+
@if (currentLesson()) {
39+
<div class="task__meta">
40+
<p class="text-body-14">модуль {{ currentLesson()!.moduleOrder }}</p>
41+
<p class="task__lesson text-body-12">урок {{ currentLessonOrder() }}</p>
42+
</div>
43+
}
4444

4545
<app-button
4646
size="small"

projects/social_platform/src/app/ui/pages/courses/detail/course-detail.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import { LoaderComponent } from "@ui/primitives/loader/loader.component";
99
import { CourseDetailInfoService } from "@api/courses/facades/course-detail-info.service";
1010
import { CourseDetailUIInfoService } from "@api/courses/facades/ui/course-detail-ui-info.service";
1111
import { CourseAboutComponent } from "@ui/widgets/course-about/course-about.component";
12-
import { LessonUIInfoService } from "@api/courses/facades/ui/lesson-ui-info.service";
1312
import { ModalComponent } from "@ui/primitives/modal/modal.component";
14-
import { LessonInfoService } from "@api/courses/facades/lesson-info.service";
1513

1614
@Component({
1715
selector: "app-course-detail",
@@ -38,6 +36,8 @@ export class CourseDetailComponent implements OnInit, OnDestroy {
3836
protected readonly courseModules = this.courseDetailUIInfoService.courseModules;
3937
protected readonly isDisabled = this.courseDetailUIInfoService.isDisabled;
4038
protected readonly isTaskDetail = this.courseDetailUIInfoService.isTaskDetail;
39+
protected readonly currentLesson = this.courseDetailUIInfoService.currentLesson;
40+
protected readonly currentLessonOrder = this.courseDetailUIInfoService.currentLessonOrder;
4141

4242
isAboutModalOpen = false;
4343

projects/social_platform/src/app/ui/pages/courses/lesson/lesson.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
<app-button
9393
[loader]="loader()"
9494
[disabled]="isSubmitDisabled() || isViewingCompleted()"
95+
[style.opacity]="isSubmitDisabled() || isViewingCompleted() ? 0.5 : 1"
9596
size="big"
9697
customTypographyClass="text-body-12"
9798
class="action__button"

projects/social_platform/src/app/ui/pages/program/detail/main/main.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ <h3 class="text-body-12 about__title">о программе</h3>
7373
<app-program-links
7474
title="контакты"
7575
icon="phone"
76-
[links]="contactLinks"
76+
[links]="contactLinks()"
7777
></app-program-links>
7878
</aside>
7979
} @if (program()!.isUserMember && program()!.materials?.length) {
8080
<aside class="program__aside program__section">
8181
<app-program-links
8282
title="материалы"
8383
icon="book"
84-
[links]="materialLinks"
84+
[links]="materialLinks()"
8585
></app-program-links>
8686
</aside>
8787
}

projects/social_platform/src/app/ui/pages/program/detail/main/main.component.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,8 @@ export class ProgramDetailMainComponent implements OnInit, OnDestroy {
8888
protected readonly registeredProgramModal =
8989
this.programDetailMainUIInfoService.registeredProgramModal;
9090

91-
get contactLinks(): { label: string; url: string }[] {
92-
return (this.program()?.links ?? []).map(link => ({ label: link, url: link }));
93-
}
94-
95-
get materialLinks(): { label: string; url: string }[] {
96-
return (this.program()?.materials ?? []).map(m => ({ label: m.title, url: m.url }));
97-
}
91+
protected readonly contactLinks = this.programDetailMainUIInfoService.contactLinks;
92+
protected readonly materialLinks = this.programDetailMainUIInfoService.materialLinks;
9893

9994
protected appWidth = window.innerWidth;
10095

projects/social_platform/src/app/ui/widgets/detail/detail.component.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,20 @@
101101
[disabled]="!info().links?.length"
102102
class="info__contacts"
103103
customTypographyClass="text-body-12"
104-
(click)="isContactsModalOpen = true"
104+
(click)="isContactsModalOpen.set(true)"
105105
>
106106
<i appIcon icon="phone" appSquare="12"></i>
107107
</app-button>
108108

109109
<app-modal
110-
[open]="isContactsModalOpen"
111-
(openChange)="isContactsModalOpen = !isContactsModalOpen"
110+
[open]="isContactsModalOpen()"
111+
(openChange)="isContactsModalOpen.set(!isContactsModalOpen())"
112112
bodyClass="modal__body--no-flex"
113113
>
114114
<app-program-links
115115
title="контакты"
116116
icon="phone"
117-
[links]="contactLinks"
117+
[links]="contactLinks()"
118118
></app-program-links>
119119
</app-modal>
120120
} @else {
@@ -213,7 +213,7 @@
213213
[disabled]="!info().links?.length"
214214
class="info__contacts"
215215
customTypographyClass="text-body-12"
216-
(click)="isContactsModalOpen = true"
216+
(click)="isContactsModalOpen.set(true)"
217217
>
218218
<i appIcon icon="phone" appSquare="12"></i>
219219
</app-button>
@@ -258,7 +258,7 @@
258258
class="info__materials"
259259
[class.info__materials--full]="isUserManager() || isUserExpert()"
260260
customTypographyClass="text-body-12"
261-
(click)="isMaterialsModalOpen = true"
261+
(click)="isMaterialsModalOpen.set(true)"
262262
>
263263
материалы
264264
</app-button>
@@ -330,26 +330,26 @@
330330
</app-modal>
331331

332332
<app-modal
333-
[open]="isContactsModalOpen"
334-
(openChange)="isContactsModalOpen = !isContactsModalOpen"
333+
[open]="isContactsModalOpen()"
334+
(openChange)="isContactsModalOpen.set(!isContactsModalOpen())"
335335
bodyClass="modal__body--no-flex"
336336
>
337337
<app-program-links
338338
title="контакты"
339339
icon="phone"
340-
[links]="contactLinks"
340+
[links]="contactLinks()"
341341
></app-program-links>
342342
</app-modal>
343343

344344
<app-modal
345-
[open]="isMaterialsModalOpen"
346-
(openChange)="isMaterialsModalOpen = !isMaterialsModalOpen"
345+
[open]="isMaterialsModalOpen()"
346+
(openChange)="isMaterialsModalOpen.set(!isMaterialsModalOpen())"
347347
bodyClass="modal__body--no-flex"
348348
>
349349
<app-program-links
350350
title="материалы"
351351
icon="book"
352-
[links]="materialLinks"
352+
[links]="materialLinks()"
353353
></app-program-links>
354354
</app-modal>
355355
} }

projects/social_platform/src/app/ui/widgets/detail/detail.component.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,19 +168,10 @@ export class DeatilComponent implements OnInit, OnDestroy {
168168

169169
protected readonly errorMessage = ErrorMessage;
170170

171-
isContactsModalOpen = false;
172-
isMaterialsModalOpen = false;
173-
174-
get contactLinks(): { label: string; url: string }[] {
175-
return (this.info()?.links ?? []).map((link: string) => ({ label: link, url: link }));
176-
}
177-
178-
get materialLinks(): { label: string; url: string }[] {
179-
return (this.info()?.materials ?? []).map((m: { title: string; url: string }) => ({
180-
label: m.title,
181-
url: m.url,
182-
}));
183-
}
171+
protected readonly isContactsModalOpen = this.detailInfoService.isContactsModalOpen;
172+
protected readonly isMaterialsModalOpen = this.detailInfoService.isMaterialsModalOpen;
173+
protected readonly contactLinks = this.detailInfoService.contactLinks;
174+
protected readonly materialLinks = this.detailInfoService.materialLinks;
184175

185176
protected appWidth = window.innerWidth;
186177

0 commit comments

Comments
 (0)