Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update repo on back and forward navigation #322

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/app/core/services/view.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { BehaviorSubject, Observable, of, Subject } from 'rxjs';
import { map } from 'rxjs/operators';
import { STORAGE_KEYS } from '../constants/storage-keys.constants';
Expand Down Expand Up @@ -69,6 +69,7 @@ export class ViewService {
private githubService: GithubService,
private repoUrlCacheService: RepoUrlCacheService,
public logger: LoggingService,
private route: ActivatedRoute,
private router: Router
) {}

Expand Down Expand Up @@ -183,6 +184,17 @@ export class ViewService {
);
}

/**
* Initializes a repo based on the URL parameters and changes the repo if valid.
*/
initializeRepoFromUrlParams(): void {
const repoParams = this.route.snapshot.queryParamMap.get(ViewService.REPO_QUERY_PARAM_KEY);

const newRepo = Repo.of(repoParams);

this.changeRepositoryIfValid(newRepo);
}

getViewAndRepoFromUrl(url: string): [string, string] {
const urlObject = new URL(`${location.protocol}//${location.host}${url}`);
const pathname = urlObject.pathname;
Expand Down
1 change: 1 addition & 0 deletions src/app/issues-viewer/issues-viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class IssuesViewerComponent implements OnInit, AfterViewInit, OnDestroy {
}

if (event instanceof NavigationEnd && event.id === this.popStateNavigationId) {
this.viewService.initializeRepoFromUrlParams();
this.groupingContextService.initializeFromUrlParams();
}
});
Expand Down
4 changes: 4 additions & 0 deletions src/app/shared/layout/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export class HeaderComponent implements OnInit {
}
});

this.viewService.repoChanged$.subscribe((repo) => {
this.initializeRepoNameInTitle();
});

this.isLoading$ = this.issueService.isLoading.asObservable();
}

Expand Down
Loading