@@ -2,9 +2,10 @@ import { TranslatePipe } from '@ngx-translate/core';
22
33import { Tab , TabList , TabPanel , TabPanels , Tabs } from 'primeng/tabs' ;
44
5- import { ChangeDetectionStrategy , Component , inject } from '@angular/core' ;
5+ import { ChangeDetectionStrategy , Component , inject , OnInit } from '@angular/core' ;
66import { toSignal } from '@angular/core/rxjs-interop' ;
77import { FormsModule , ReactiveFormsModule } from '@angular/forms' ;
8+ import { ActivatedRoute , Router } from '@angular/router' ;
89
910import { SelectComponent } from '@osf/shared/components/select/select.component' ;
1011import { SubHeaderComponent } from '@osf/shared/components/sub-header/sub-header.component' ;
@@ -36,14 +37,28 @@ import { ProfileSettingsTabOption } from './enums';
3637 styleUrl : './profile-settings.component.scss' ,
3738 changeDetection : ChangeDetectionStrategy . OnPush ,
3839} )
39- export class ProfileSettingsComponent {
40+ export class ProfileSettingsComponent implements OnInit {
4041 readonly isMedium = toSignal ( inject ( IS_MEDIUM ) ) ;
4142 readonly tabOptions = PROFILE_SETTINGS_TAB_OPTIONS ;
4243 readonly tabOption = ProfileSettingsTabOption ;
4344
45+ private router = inject ( Router ) ;
46+ private route = inject ( ActivatedRoute ) ;
4447 selectedTab = this . tabOption . Name ;
4548
49+ ngOnInit ( ) : void {
50+ const tabParam = Number ( this . route . snapshot . queryParams [ 'tab' ] ) ;
51+ const selectedTab = tabParam && Object . values ( this . tabOption ) . includes ( tabParam ) ? tabParam : this . tabOption . Name ;
52+
53+ this . selectedTab = selectedTab ;
54+ }
55+
4656 onTabChange ( index : number ) : void {
4757 this . selectedTab = index ;
58+ this . router . navigate ( [ ] , {
59+ queryParams : { tab : index } ,
60+ queryParamsHandling : 'merge' ,
61+ replaceUrl : true ,
62+ } ) ;
4863 }
4964}
0 commit comments