From e0b7e616b3929ba73157c3ffc0c4616deba0e1fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thea=20Sch=C3=B6bl?= Date: Wed, 20 Sep 2023 10:16:30 +0200 Subject: [PATCH] fix: live update distance in list items --- .changeset/loud-buttons-repeat.md | 5 ++++ .../types/place/place-list-item.component.ts | 27 +++++-------------- .../data/types/place/place-list-item.html | 26 +++++++++--------- 3 files changed, 25 insertions(+), 33 deletions(-) create mode 100644 .changeset/loud-buttons-repeat.md diff --git a/.changeset/loud-buttons-repeat.md b/.changeset/loud-buttons-repeat.md new file mode 100644 index 00000000..a5a71666 --- /dev/null +++ b/.changeset/loud-buttons-repeat.md @@ -0,0 +1,5 @@ +--- +'@openstapps/app': patch +--- + +Fixed distance not updating in list items diff --git a/frontend/app/src/app/modules/data/types/place/place-list-item.component.ts b/frontend/app/src/app/modules/data/types/place/place-list-item.component.ts index 54f004d3..81c6b5bc 100644 --- a/frontend/app/src/app/modules/data/types/place/place-list-item.component.ts +++ b/frontend/app/src/app/modules/data/types/place/place-list-item.component.ts @@ -12,10 +12,11 @@ * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ -import {Component, Input} from '@angular/core'; +import {ChangeDetectionStrategy, Component, Input} from '@angular/core'; import {PositionService} from '../../../map/position.service'; -import {interval, Subscription} from 'rxjs'; +import {Observable, timer} from 'rxjs'; import {hasValidLocation, isSCFloor, PlaceTypes, PlaceTypesWithDistance} from './place-types'; +import {map} from 'rxjs/operators'; /** * Shows a place as a list item @@ -24,14 +25,10 @@ import {hasValidLocation, isSCFloor, PlaceTypes, PlaceTypesWithDistance} from '. selector: 'stapps-place-list-item', templateUrl: 'place-list-item.html', styleUrls: ['place-list-item.scss'], + changeDetection: ChangeDetectionStrategy.OnPush, }) export class PlaceListItemComponent { - /** - * Item getter - */ - get item(): PlaceTypesWithDistance { - return this._item; - } + _item: PlaceTypesWithDistance; /** * An item to show (setter is used as there were issues assigning the distance to the right place in a list) @@ -39,24 +36,14 @@ export class PlaceListItemComponent { @Input() set item(item: PlaceTypes) { this._item = item; if (!isSCFloor(item) && hasValidLocation(item)) { - this.distance = this.positionService.getDistance(item.geo.point); - this.distanceSubscription = interval(10_000).subscribe(_ => { - this.distance = this.positionService.getDistance(item.geo.point); - }); + this.distance = timer(0, 10_000).pipe(map(() => this.positionService.getDistance(item.geo.point))); } } - /** - * An item to show - */ - private _item: PlaceTypesWithDistance; - /** * Distance in meters */ - distance?: number; - - distanceSubscription?: Subscription; + distance?: Observable; constructor(private positionService: PositionService) {} } diff --git a/frontend/app/src/app/modules/data/types/place/place-list-item.html b/frontend/app/src/app/modules/data/types/place/place-list-item.html index cf530c13..56492e83 100644 --- a/frontend/app/src/app/modules/data/types/place/place-list-item.html +++ b/frontend/app/src/app/modules/data/types/place/place-list-item.html @@ -17,17 +17,17 @@
- {{ 'name' | thingTranslate: item }} - -

+ {{ 'name' | thingTranslate: _item }} + +

- +

- - {{ 'categories' | thingTranslate: item | join: ', ' | titlecase }} - + + {{ 'categories' | thingTranslate: _item | join: ', ' | titlecase }} + {{ distance | metersLocalized }} @@ -35,21 +35,21 @@

- {{ 'type' | thingTranslate: item | titlecase }} - + {{ 'type' | thingTranslate: _item | titlecase }} + {{ distance | metersLocalized }}
-

{{ 'description' | thingTranslate: item }}

+

{{ 'description' | thingTranslate: _item }}

- - + + {{ 'name' | thingTranslate: item.inPlace }} + >{{ 'name' | thingTranslate: _item.inPlace }}