mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 17:12:43 +00:00
fix: canteen view removes item select listener on view exit
This commit is contained in:
committed by
Rainer Killinger
parent
947cab458c
commit
05e996ae90
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2022 StApps
|
* Copyright (C) 2023 StApps
|
||||||
* This program is free software: you can redistribute it and/or modify it
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* under the terms of the GNU General Public License as published by the Free
|
* under the terms of the GNU General Public License as published by the Free
|
||||||
* Software Foundation, version 3.
|
* Software Foundation, version 3.
|
||||||
@@ -12,10 +12,11 @@
|
|||||||
* You should have received a copy of the GNU General Public License along with
|
* You should have received a copy of the GNU General Public License along with
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import {Component} from '@angular/core';
|
import {Component, OnDestroy, OnInit} from '@angular/core';
|
||||||
import {MapPosition} from '../../map/position.service';
|
import {MapPosition} from '../../map/position.service';
|
||||||
import {SearchPageComponent} from './search-page.component';
|
import {SearchPageComponent} from './search-page.component';
|
||||||
import {Geolocation} from '@capacitor/geolocation';
|
import {Geolocation} from '@capacitor/geolocation';
|
||||||
|
import {Subscription} from 'rxjs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Presents a list of places for eating/drinking
|
* Presents a list of places for eating/drinking
|
||||||
@@ -24,15 +25,19 @@ import {Geolocation} from '@capacitor/geolocation';
|
|||||||
templateUrl: 'search-page.html',
|
templateUrl: 'search-page.html',
|
||||||
styleUrls: ['../../data/list/search-page.scss'],
|
styleUrls: ['../../data/list/search-page.scss'],
|
||||||
})
|
})
|
||||||
export class FoodDataListComponent extends SearchPageComponent {
|
export class FoodDataListComponent extends SearchPageComponent implements OnInit, OnDestroy {
|
||||||
title = 'canteens.title';
|
title = 'canteens.title';
|
||||||
|
|
||||||
showNavigation = false;
|
showNavigation = false;
|
||||||
|
|
||||||
|
locationWatch?: Subscription;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the forced filter to present only places for eating/drinking
|
* Sets the forced filter to present only places for eating/drinking
|
||||||
*/
|
*/
|
||||||
initialize() {
|
ngOnInit() {
|
||||||
|
this.locationWatch?.unsubscribe();
|
||||||
|
this.locationWatch = this.createLocationWatch();
|
||||||
this.showDefaultData = true;
|
this.showDefaultData = true;
|
||||||
|
|
||||||
this.sortQuery = [
|
this.sortQuery = [
|
||||||
@@ -92,29 +97,36 @@ export class FoodDataListComponent extends SearchPageComponent {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
super.ngOnInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
private createLocationWatch(): Subscription {
|
||||||
|
return this.positionService
|
||||||
|
.watchCurrentLocation(this.constructor.name, {enableHighAccuracy: false, maximumAge: 1000})
|
||||||
|
.subscribe({
|
||||||
|
next: (position: MapPosition) => {
|
||||||
|
this.positionService.position = position;
|
||||||
|
},
|
||||||
|
error: async _error => {
|
||||||
|
this.positionService.position = undefined;
|
||||||
|
await Geolocation.checkPermissions();
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async ionViewWillEnter() {
|
async ionViewWillEnter() {
|
||||||
await super.ionViewWillEnter();
|
await super.ionViewWillEnter();
|
||||||
this.subscriptions.push(
|
this.locationWatch?.unsubscribe();
|
||||||
this.positionService
|
this.locationWatch = this.createLocationWatch();
|
||||||
.watchCurrentLocation(this.constructor.name, {enableHighAccuracy: false, maximumAge: 1000})
|
|
||||||
.subscribe({
|
|
||||||
next: (position: MapPosition) => {
|
|
||||||
this.positionService.position = position;
|
|
||||||
},
|
|
||||||
error: async _error => {
|
|
||||||
this.positionService.position = undefined;
|
|
||||||
await Geolocation.checkPermissions();
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ionViewWillLeave() {
|
ionViewWillLeave() {
|
||||||
void this.positionService.clearWatcher(this.constructor.name);
|
this.locationWatch?.unsubscribe();
|
||||||
for (const sub of this.subscriptions) {
|
}
|
||||||
sub.unsubscribe();
|
|
||||||
}
|
ngOnDestroy() {
|
||||||
|
super.ngOnDestroy();
|
||||||
|
this.locationWatch?.unsubscribe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user