BugFix: IP Adresse & Subject instead of BehaviourSubject

This commit is contained in:
2024-09-20 15:59:45 +02:00
parent 3e84b82c92
commit 16b880384b
16 changed files with 36 additions and 330 deletions

View File

@@ -1,6 +1,6 @@
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { BehaviorSubject, lastValueFrom, Observable } from 'rxjs';
import { lastValueFrom, Observable } from 'rxjs';
import { CityAndStateResult, CountyResult, GeoResult, IpInfo } from '../../../../bizmatch-server/src/models/main.model';
import { Place } from '../../../../bizmatch-server/src/models/server.model';
import { environment } from '../../environments/environment';
@@ -11,7 +11,6 @@ import { environment } from '../../environments/environment';
export class GeoService {
private apiBaseUrl = environment.apiBaseUrl;
private baseUrl: string = 'https://nominatim.openstreetmap.org/search';
private ipInfo$ = new BehaviorSubject<IpInfo | null>(null);
private fetchingData: Observable<IpInfo> | null = null;
private readonly storageKey = 'ipInfo';
constructor(private http: HttpClient) {}
@@ -34,27 +33,6 @@ export class GeoService {
return this.http.get<IpInfo>(`${this.apiBaseUrl}/bizmatch/geo/ipinfo/georesult/wysiwyg`);
}
// getIpInfo(): Observable<IpInfo | null> {
// if (this.ipInfo$.getValue() !== null) {
// // Wenn wir bereits Daten haben, geben wir sie sofort zurück
// return this.ipInfo$.asObservable();
// } else if (this.fetchingData) {
// // Wenn wir gerade Daten abrufen, geben wir diesen Observable zurück
// return this.fetchingData;
// } else {
// // Ansonsten initiieren wir den Abruf
// this.fetchingData = this.fetchIpAndGeoLocation().pipe(
// tap(data => this.ipInfo$.next(data)),
// catchError(error => {
// console.error('Error fetching IP info:', error);
// this.ipInfo$.next(null);
// return of(null);
// }),
// shareReplay(1),
// );
// return this.fetchingData;
// }
// }
async getIpInfo(): Promise<IpInfo | null> {
// Versuche zuerst, die Daten aus dem sessionStorage zu holen
const storedData = sessionStorage.getItem(this.storageKey);