Skip to content

Commit

Permalink
Update repo on back and forward navigation (#322)
Browse files Browse the repository at this point in the history
IssueViewer's repository is not updated when navigating back or forward
in the URL history. This will lead to inconsistency between the URL
parameters and the application state.

Let's ensure that IssueViewer's repository is updated on back and forward
navigation.
  • Loading branch information
NereusWB922 authored Mar 29, 2024
1 parent 70bae91 commit 2eb2aba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
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

0 comments on commit 2eb2aba

Please sign in to comment.