Skip to content

Commit

Permalink
switch tabs without navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
rrchai committed Nov 3, 2023
1 parent 5a74e88 commit 608c7ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,21 @@ <h2>
<div class="profile-nav-group">
<a
class="profile-nav-item"
routerLink="."
[queryParams]="{ tab: 'overview' }"
(click)="updateTab(tabs['overview'])"
[ngClass]="{ 'active-tab': activeTab === tabs['overview'] }"
>
Overview
</a>
<a
class="profile-nav-item"
routerLink="."
[queryParams]="{ tab: 'contributors' }"
(click)="updateTab(tabs['contributors'])"
[ngClass]="{ 'active-tab': activeTab === tabs['contributors'] }"
>
Contributors
</a>
<a
class="profile-nav-item"
routerLink="."
[queryParams]="{ tab: 'organizers' }"
(click)="updateTab(tabs['organizers'])"
[ngClass]="{ 'active-tab': activeTab === tabs['organizers'] }"
>
Organizers
Expand Down
16 changes: 14 additions & 2 deletions libs/openchallenges/challenge/src/lib/challenge.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ import { ChallengeOrganizersComponent } from './challenge-organizers/challenge-o
import { ChallengeOverviewComponent } from './challenge-overview/challenge-overview.component';
import { ChallengeStargazersComponent } from './challenge-stargazers/challenge-stargazers.component';
import { ChallengeStatsComponent } from './challenge-stats/challenge-stats.component';
import { CommonModule } from '@angular/common';
import { CommonModule, Location } from '@angular/common';
import { SeoService } from '@sagebionetworks/shared/util';
import { getSeoData } from './challenge-seo-data';
import { HttpParams } from '@angular/common/http';

@Component({
selector: 'openchallenges-challenge',
Expand Down Expand Up @@ -83,7 +84,8 @@ export class ChallengeComponent implements OnInit {
private challengeService: ChallengeService,
private readonly configService: ConfigService,
private seoService: SeoService,
private renderer2: Renderer2
private renderer2: Renderer2,
private _location: Location
) {
this.appVersion = this.configService.config.appVersion;
this.dataUpdatedOn = this.configService.config.dataUpdatedOn;
Expand Down Expand Up @@ -143,6 +145,16 @@ export class ChallengeComponent implements OnInit {
this.subscriptions.push(activeTabSub);
}

updateTab(activeTab: Tab) {
this.activeTab = activeTab;
const queryParams = { tab: activeTab.name };
const newParam = new HttpParams({
fromObject: queryParams,
});
console.log(location.pathname);
this._location.replaceState(location.pathname, newParam.toString());
}

// calcDays(startDate: string, endDate: string): number {
// const timeDiff = +new Date(endDate) - +new Date(startDate);
// return Math.round(timeDiff / (1000 * 60 * 60 * 24));
Expand Down

0 comments on commit 608c7ca

Please sign in to comment.