Ajout d'un reset de cache après un ajout

This commit is contained in:
Sébastien André
2021-04-28 14:21:02 +02:00
parent 05ed51db66
commit 790cc33a39
3 changed files with 19 additions and 9 deletions

View File

@@ -30,26 +30,26 @@ export class DropzoneService extends BaseService {
return this.serviceRefData.get<Array<DropZoneResp>>(RefData.Dropzone, callToApi); return this.serviceRefData.get<Array<DropZoneResp>>(RefData.Dropzone, callToApi);
} }
public SetFavoriteDropZone(selectedDz: DropZoneResp): boolean { public SetFavoriteDropZone(selectedDz: DropZoneResp) {
selectedDz.isFavorite = true; selectedDz.isFavorite = true;
this.http.put(`${this.apiUrl}/DropZone/AddToFavorite/${selectedDz.id}`, this.http.put(`${this.apiUrl}/DropZone/AddToFavorite/${selectedDz.id}`,
selectedDz, selectedDz,
{ headers: this.headers }) { headers: this.headers })
.subscribe(); .subscribe(() => {
this.serviceRefData.delete(RefData.Dropzone);
return true; });
} }
public RemoveFavoriteDropZone(selectedDz: DropZoneResp): boolean { public RemoveFavoriteDropZone(selectedDz: DropZoneResp) {
selectedDz.isFavorite = false; selectedDz.isFavorite = false;
this.http.put(`${this.apiUrl}/DropZone/RemoveToFavorite${selectedDz.id}`, this.http.put(`${this.apiUrl}/DropZone/RemoveToFavorite${selectedDz.id}`,
selectedDz, selectedDz,
{ headers: this.headers }) { headers: this.headers })
.subscribe(); .subscribe(() => {
this.serviceRefData.delete(RefData.Dropzone);
return true; });
} }
public AddDropZone(latitude: string, public AddDropZone(latitude: string,
@@ -72,6 +72,7 @@ export class DropzoneService extends BaseService {
isFavorite: isFavorite isFavorite: isFavorite
}; };
this.serviceRefData.delete(RefData.Dropzone);
return this.http.post(`${this.apiUrl}/DropZone`, return this.http.post(`${this.apiUrl}/DropZone`,
bodyNewDropZone, bodyNewDropZone,
{ headers: this.headers }); { headers: this.headers });

View File

@@ -37,6 +37,7 @@ export class GearService extends BaseService {
reserveCanopy: reserveCanopy reserveCanopy: reserveCanopy
}; };
this.serviceRefData.delete(RefData.Gear);
return this.http.post(`${this.apiUrl}/Gear`, bodyNewGear, { headers: this.headers}); return this.http.post(`${this.apiUrl}/Gear`, bodyNewGear, { headers: this.headers});
} }
} }

View File

@@ -15,7 +15,11 @@ export class ServiceRefData {
this.cache = new Map<RefData, Observable<any>>(); this.cache = new Map<RefData, Observable<any>>();
} }
public get<T>(key: RefData, callToApi: Observable<T>) : Observable<T> { public get<T>(key: RefData, callToApi: Observable<T>, withResetCache: boolean = false) : Observable<T> {
if (withResetCache === true) {
this.cache.delete(key);
}
const cached = this.cache.get(key); const cached = this.cache.get(key);
if (cached) { if (cached) {
@@ -27,4 +31,8 @@ export class ServiceRefData {
})); }));
} }
} }
public delete(key: RefData) {
this.cache.delete(key);
}
} }