From 8ab6eb6ec882d19fcb53d4ba5fc7945fbcd9ab44 Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Fri, 1 Jun 2018 12:06:21 +0200 Subject: [PATCH] item page reload fix --- .../+item-page/simple/item-page.component.html | 8 ++++---- src/app/+item-page/simple/item-page.component.ts | 16 +++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/app/+item-page/simple/item-page.component.html b/src/app/+item-page/simple/item-page.component.html index 17d271f368..58dbbe3aa1 100644 --- a/src/app/+item-page/simple/item-page.component.html +++ b/src/app/+item-page/simple/item-page.component.html @@ -1,9 +1,9 @@
-
+
- +
- - + +
diff --git a/src/app/+item-page/simple/item-page.component.ts b/src/app/+item-page/simple/item-page.component.ts index 55dfe8a7b0..1dfa93f52d 100644 --- a/src/app/+item-page/simple/item-page.component.ts +++ b/src/app/+item-page/simple/item-page.component.ts @@ -14,6 +14,7 @@ import { fadeInOut } from '../../shared/animations/fade'; import { hasValue } from '../../shared/empty.util'; import * as viewMode from '../../shared/view-mode'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; +import { Subscription } from 'rxjs/Subscription'; /** * This component renders a simple item page. @@ -31,11 +32,11 @@ export class ItemPageComponent implements OnInit { id: number; - private sub: any; - + private sub: Subscription; + private itemSub: Subscription; thumbnailObs: Observable; - itemRDObs?: BehaviorSubject> = new BehaviorSubject(new RemoteData(true, true, false, null, null)); + itemRDObs: BehaviorSubject> = new BehaviorSubject(new RemoteData(true, true, undefined, null, null)); ElementViewMode = viewMode.ElementViewMode; @@ -43,9 +44,7 @@ export class ItemPageComponent implements OnInit { private route: ActivatedRoute, private items: ItemDataService, private metadataService: MetadataService, - ) { - - } + ) { } ngOnInit(): void { this.sub = this.route.params.subscribe((params) => { @@ -56,7 +55,10 @@ export class ItemPageComponent implements OnInit { initialize(params) { this.id = +params.id; - this.items.findById(params.id).filter((rd) => hasValue(rd.payload)).first().subscribe((item) => this.itemRDObs.next(item)); + if (hasValue(this.itemSub)) { + this.itemSub.unsubscribe(); + } + this.itemSub = this.items.findById(params.id).subscribe((item) => this.itemRDObs.next(item)); this.metadataService.processRemoteData(this.itemRDObs); this.thumbnailObs = this.itemRDObs .map((rd: RemoteData) => rd.payload)