11/** @format */
22
3- import { Component , OnInit , signal } from "@angular/core" ;
3+ import { Component , inject , OnInit , signal } from "@angular/core" ;
44import { ActivatedRoute , RouterLink , RouterOutlet } from "@angular/router" ;
5- import { map , Observable } from "rxjs" ;
5+ import { filter , map , Observable , take } from "rxjs" ;
66import { User } from "@auth/models/user.model" ;
77import { NavService } from "@services/nav.service" ;
88import { AuthService } from "@auth/services" ;
@@ -16,6 +16,7 @@ import { ModalComponent } from "@ui/components/modal/modal.component";
1616import { calculateProfileProgress } from "@utils/calculateProgress" ;
1717import { ProfileService as SkillsProfileService } from "projects/skills/src/app/profile/services/profile.service" ;
1818import { TooltipComponent } from "@ui/components/tooltip/tooltip.component" ;
19+ import { ProfileDataService } from "./services/profile-date.service" ;
1920
2021/**
2122 * Компонент детального просмотра профиля пользователя
@@ -52,23 +53,46 @@ import { TooltipComponent } from "@ui/components/tooltip/tooltip.component";
5253 YearsFromBirthdayPipe ,
5354 BarComponent ,
5455 ModalComponent ,
55- TooltipComponent ,
5656 ] ,
5757} )
5858export class ProfileDetailComponent implements OnInit {
59- constructor (
60- private readonly route : ActivatedRoute ,
61- private readonly navService : NavService ,
62- public readonly authService : AuthService ,
63- public readonly chatService : ChatService ,
64- public readonly skillsProfileService : SkillsProfileService ,
65- public readonly breakpointObserver : BreakpointObserver
66- ) { }
59+ private readonly route = inject ( ActivatedRoute ) ;
60+ private readonly navService = inject ( NavService ) ;
61+ private readonly profileDataService = inject ( ProfileDataService ) ;
62+ public readonly authService = inject ( AuthService ) ;
63+ public readonly chatService = inject ( ChatService ) ;
64+ public readonly skillsProfileService = inject ( SkillsProfileService ) ;
65+ public readonly breakpointObserver = inject ( BreakpointObserver ) ;
6766
68- user$ : Observable < User > = this . route . data . pipe (
69- map ( r => r [ "data" ] [ 0 ] ) ,
70- map ( user => ( { ...user , progress : calculateProfileProgress ( user ) } ) )
71- ) ;
67+ /**
68+ * Инициализация компонента
69+ * Настраивает заголовок навигации, проверяет статус подписки,
70+ * определяет необходимость заполнения профиля
71+ */
72+ ngOnInit ( ) : void {
73+ this . navService . setNavTitle ( "Профиль" ) ;
74+
75+ this . profileDataService
76+ . getProfile ( )
77+ . pipe (
78+ map ( user => ( { ...user , progress : calculateProfileProgress ( user ! ) } ) ) ,
79+ filter ( user => ! ! user ) ,
80+ take ( 1 )
81+ )
82+ . subscribe ( {
83+ next : user => {
84+ this . user = user as User ;
85+ this . isProfileFill =
86+ user . progress ! < 100 ? ( this . isProfileFill = true ) : ( this . isProfileFill = false ) ;
87+ } ,
88+ } ) ;
89+
90+ this . skillsProfileService . getSubscriptionData ( ) . subscribe ( r => {
91+ this . isSubscriptionActive . set ( r . isSubscribed ) ;
92+ } ) ;
93+ }
94+
95+ user ?: User ;
7296
7397 loggedUserId$ : Observable < number > = this . authService . profile . pipe ( map ( user => user . id ) ) ;
7498
@@ -81,6 +105,11 @@ export class ProfileDetailComponent implements OnInit {
81105 tooltipText = "Заполни до конца — и открой весь функционал платформы!" ;
82106 isHintVisible = false ;
83107
108+ errorMessageModal = signal ( "" ) ;
109+ desktopMode$ : Observable < boolean > = this . breakpointObserver
110+ . observe ( "(min-width: 920px)" )
111+ . pipe ( map ( result => result . matches ) ) ;
112+
84113 /**
85114 * Показать подсказку для незаполненного профиля
86115 */
@@ -95,29 +124,6 @@ export class ProfileDetailComponent implements OnInit {
95124 this . isHintVisible = false ;
96125 }
97126
98- errorMessageModal = signal ( "" ) ;
99- desktopMode$ : Observable < boolean > = this . breakpointObserver
100- . observe ( "(min-width: 920px)" )
101- . pipe ( map ( result => result . matches ) ) ;
102-
103- /**
104- * Инициализация компонента
105- * Настраивает заголовок навигации, проверяет статус подписки,
106- * определяет необходимость заполнения профиля
107- */
108- ngOnInit ( ) : void {
109- this . navService . setNavTitle ( "Профиль" ) ;
110-
111- this . skillsProfileService . getSubscriptionData ( ) . subscribe ( r => {
112- this . isSubscriptionActive . set ( r . isSubscribed ) ;
113- } ) ;
114-
115- this . user$ . subscribe ( r => {
116- this . isProfileFill =
117- r . progress ! < 100 ? ( this . isProfileFill = true ) : ( this . isProfileFill = false ) ;
118- } ) ;
119- }
120-
121127 /**
122128 * Отправка CV пользователя на email
123129 * Проверяет ограничения по времени и отправляет CV на почту пользователя
0 commit comments